upload fies to storage account for appeal

This commit is contained in:
2022-07-07 17:06:56 +01:00
parent b96f3bb916
commit f23ad2a300
28 changed files with 956 additions and 179 deletions
+32
View File
@@ -0,0 +1,32 @@
import {
createContainer,
getContainers,
getBlobs,
createBlob,
uploadFile,
deleteBlob,
} from "../../../actions/azurestorage";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var blobName = req.query.blobname;
console.log(containerName, blobName);
await deleteBlob(containerName, "files/" + blobName).then((data) => {
return res.status(200).json({ data: data });
});
});
export const config = {
api: {
bodyParser: false,
},
};
export default ApiProxy;
+84
View File
@@ -0,0 +1,84 @@
import {
createContainer,
getContainers,
getBlobs,
createBlob,
uploadFile,
deleteBlob,
downloadFile,
} from "../../../actions/azurestorage";
import { BlobServiceClient, ContainerClient } from "@azure/storage-blob";
import {
DefaultAzureCredential,
InteractiveBrowserCredential,
EnvironmentCredential,
ClientSecretCredential,
} from "@azure/identity";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
import CryptoJS from "crypto-js";
import { hashAPIPath } from "../../../actions";
const WORDKEY = process.env.HASHKEY;
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var blobName = req.query.blobname;
var checkHash = req.query.hash;
var checkquerypath =
"/api/file/downloadblob?container=" +
containerName +
"&blobname=" +
blobName;
console.log(
"containerName " +
containerName +
`\n` +
blobName +
`\n` +
checkHash +
`\n` +
checkquerypath
);
console.log(hashAPIPath(checkquerypath), checkHash);
console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const downloaded = await downloadFile(containerName, blobName);
res.setHeader(
"content-disposition",
"attachment; filename=" + blobName
);
return res.status(200).send(downloaded);
} else {
return res.status(400).json();
}
});
async function streamToBuffer(readableStream) {
return new Promise((resolve, reject) => {
const chunks = [];
readableStream.on("data", (data) => {
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
});
readableStream.on("end", () => {
resolve(Buffer.concat(chunks));
});
readableStream.on("error", reject);
});
}
export const config = {
api: {
bodyParser: false,
},
};
export default ApiProxy;
+29
View File
@@ -0,0 +1,29 @@
import {
createContainer,
getContainers,
getBlobs,
createBlob,
uploadFile,
} from "../../../actions/azurestorage";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
console.log(containerName);
await getBlobs(containerName).then((data) => {
return res.status(200).json({ files: data });
});
});
export const config = {
api: {
bodyParser: false,
},
};
export default ApiProxy;
+36
View File
@@ -0,0 +1,36 @@
import {
createContainer,
getContainers,
getBlobs,
createBlob,
uploadFile,
} from "../../../actions/azurestorage";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.post(async (req, res) => {
console.log(JSON.parse(req.body.appealData));
console.log(req.files);
const appealData = JSON.parse(req.body.appealData);
createContainer(appealData.pinswg_name.trim()).then((containerName) => {
createBlob(appealData, containerName).then((data) => {
uploadFile(req.files, containerName, data);
});
});
return res.status(200).json({ data: "success" });
});
export const config = {
api: {
bodyParser: false,
},
};
export default ApiProxy;