upload fies to storage account for appeal
This commit is contained in:
@@ -26,7 +26,7 @@ export default async function ApiProxy(req, res) {
|
||||
loggedInUserId +
|
||||
" and servicestage eq 1 and pinswg_appealcasetype ne null&$orderby=createdon desc&$count=true";
|
||||
|
||||
console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
||||
//console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
||||
return axios
|
||||
.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
|
||||
@@ -32,7 +32,7 @@ export default async function ApiProxy(req, res) {
|
||||
searchString +
|
||||
"')) and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
|
||||
|
||||
console.log("basic search ", queryUrl);
|
||||
//console.log("basic search ", queryUrl);
|
||||
|
||||
var apiResponse = _.isEmpty(req.query)
|
||||
? res.status(400).json()
|
||||
|
||||
@@ -26,6 +26,7 @@ export default async function ApiProxy(req, res) {
|
||||
var queryUrl =
|
||||
"accounts?$count=true&$filter=pinswg_isalocalplanningauthorityaccount eq 846040000&$select=name&$orderby=name asc";
|
||||
|
||||
console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
||||
return axios
|
||||
.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
@@ -35,6 +36,7 @@ export default async function ApiProxy(req, res) {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch(({ err }) => {
|
||||
console.log(err);
|
||||
res.status(400).json(err);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,16 @@
|
||||
import nextConnect from "next-connect";
|
||||
import multiparty from "multiparty";
|
||||
|
||||
const middleware = nextConnect();
|
||||
|
||||
middleware.use(async (req, res, next) => {
|
||||
const form = new multiparty.Form();
|
||||
|
||||
await form.parse(req, function (err, fields, files) {
|
||||
req.body = fields;
|
||||
req.files = files;
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
export default middleware;
|
||||
Reference in New Issue
Block a user