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;
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
getMandatoryFields,
|
||||
getPickLists,
|
||||
getPartSavedAppeal,
|
||||
getFilesFromBlob,
|
||||
} from "../../actions";
|
||||
import { getProviderConfig } from "../../actions/govgateway";
|
||||
import Breadcrumbs from "../../components/breadcrumbs";
|
||||
@@ -29,6 +30,7 @@ import {
|
||||
setAppealTypeID,
|
||||
setAppealTypeTitle,
|
||||
setCaseReference,
|
||||
setFilesForAppeal,
|
||||
} from "../../store/appealType/action";
|
||||
import { setForm } from "../../store/formData/action";
|
||||
import { getGovGatewayConfig } from "../../store/govgateway/action";
|
||||
@@ -213,11 +215,12 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
console.log("the query", query.appealtypes);
|
||||
let loggedInUser = cookies.pinsUser;
|
||||
|
||||
const [appealTypeData, mandatoryFieldsData, pickListData] =
|
||||
const [appealTypeData, mandatoryFieldsData, pickListData, blobList] =
|
||||
await Promise.all([
|
||||
await getAppealsTypes(),
|
||||
await getMandatoryFields(query.appealtypes),
|
||||
await getPickLists(query.appealtypes),
|
||||
await getFilesFromBlob(query.casereference),
|
||||
]);
|
||||
|
||||
let searchResultsObj = await getPartSavedAppeal(query.casereference);
|
||||
@@ -232,7 +235,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
}
|
||||
});
|
||||
|
||||
console.log("appeal:", searchDetailsObj);
|
||||
//console.log("appeal:", searchDetailsObj);
|
||||
|
||||
searchDetailsObj = JSON.stringify(searchDetailsObj);
|
||||
searchDetailsObj = searchDetailsObj.replace(/:true/gm, `:"Yes"`);
|
||||
@@ -265,6 +268,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
store.dispatch(setCaseReference(caseReference));
|
||||
store.dispatch(setForm(xmlStr, mandatoryFieldsData, pickListData));
|
||||
store.dispatch(setAppealType(appealTypeData));
|
||||
store.dispatch(setFilesForAppeal(blobList));
|
||||
}
|
||||
);
|
||||
|
||||
@@ -290,6 +294,9 @@ const mapDispatchToProps = (dispatch) => {
|
||||
setCaseReference: (refno) => {
|
||||
dispatch(setCaseReference(refno));
|
||||
},
|
||||
setFilesForAppeal: (blobList) => {
|
||||
dispatch(setFilesForAppeal(blobList));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
);
|
||||
|
||||
const getDetails = (resultsObj, detailsType) => {
|
||||
console.log(detailsType);
|
||||
//console.log(detailsType);
|
||||
let detailsArr = [];
|
||||
resultsObj = resultsObj.value;
|
||||
const detailsObj = resultsObj.map((searchDetail, index) => {
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
getAppealsTypes,
|
||||
getMandatoryFields,
|
||||
getPickLists,
|
||||
getFilesFromBlobs,
|
||||
} from "../../actions";
|
||||
import { getProviderConfig } from "../../actions/govgateway";
|
||||
import Breadcrumbs from "../../components/breadcrumbs";
|
||||
@@ -30,6 +31,7 @@ import {
|
||||
setAppealTypeID,
|
||||
setAppealTypeTitle,
|
||||
setCaseReference,
|
||||
setFilesForAppeal,
|
||||
} from "../../store/appealType/action";
|
||||
import { setForm } from "../../store/formData/action";
|
||||
import { getGovGatewayConfig } from "../../store/govgateway/action";
|
||||
@@ -220,11 +222,13 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
appealTypeData,
|
||||
mandatoryFieldsData,
|
||||
pickListData,
|
||||
blobList,
|
||||
] = await Promise.all([
|
||||
await getCase(query.id),
|
||||
await getAppealsTypes(),
|
||||
await getMandatoryFields(query.appealtypes),
|
||||
await getPickLists(query.appealtypes),
|
||||
await getFilesFromBlob(query.casereference),
|
||||
]);
|
||||
|
||||
console.log("anything here", loggedInUser, query.id, caseReferenceData);
|
||||
@@ -251,6 +255,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
store.dispatch(setCaseReference(caseReference));
|
||||
store.dispatch(setForm(xmlStr, mandatoryFieldsData, pickListData));
|
||||
store.dispatch(setAppealType(appealTypeData));
|
||||
store.dispatch(setFilesForAppeal(blobList));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { BlobServiceClient, ContainerClient } from "@azure/storage-blob";
|
||||
import {
|
||||
DefaultAzureCredential,
|
||||
InteractiveBrowserCredential,
|
||||
EnvironmentCredential,
|
||||
ClientSecretCredential,
|
||||
} from "@azure/identity";
|
||||
import { wrapper } from "../store/store";
|
||||
|
||||
import Head from "next/head";
|
||||
|
||||
const ShowStorage = (props) => {
|
||||
const { container } = props;
|
||||
// console.log("Containers:");
|
||||
// // for await (const container of blobServiceClient.listContainers()) {
|
||||
// // console.log(`- ${container.name}`);
|
||||
// // }
|
||||
|
||||
console.log(container);
|
||||
|
||||
return <div>hello</div>;
|
||||
};
|
||||
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
|
||||
console.log(
|
||||
"have therese?:",
|
||||
process.env.AZURE_TENANT_ID,
|
||||
process.env.AZURE_CLIENT_ID,
|
||||
process.env.AZURE_CLIENT_SECRET
|
||||
);
|
||||
|
||||
const creds = new DefaultAzureCredential();
|
||||
|
||||
const blobServiceClient = new BlobServiceClient(
|
||||
`https://pedwdev.blob.core.windows.net`,
|
||||
creds
|
||||
);
|
||||
|
||||
const containerName = `CAS-999999-22222`;
|
||||
|
||||
const containerClient = new ContainerClient(
|
||||
`https://pedwdev.blob.core.windows.net/${containerName}`,
|
||||
creds
|
||||
);
|
||||
|
||||
// const createContainerResponse = await containerClient.create();
|
||||
// console.log(
|
||||
// `Created container ${containerName} successfully`,
|
||||
// createContainerResponse.requestId
|
||||
// );
|
||||
|
||||
console.log("Containers:");
|
||||
for await (const container of blobServiceClient.listContainers()) {
|
||||
console.log(`- ${container.name}`);
|
||||
}
|
||||
|
||||
const appealID = uuidv4();
|
||||
const uploadOptions = {
|
||||
metadata: { reviewer: "john", reviewDate: "2022-04-01" },
|
||||
tags: { owner: appealID },
|
||||
};
|
||||
// for (let index = 0; index < 7; index++) {
|
||||
// // Create a blob
|
||||
// const content = "hello";
|
||||
// const blobName = appealID + "/BOBnewblob" + new Date().getTime();
|
||||
// const blockBlobClient =
|
||||
// containerClient.getBlockBlobClient(blobName);
|
||||
|
||||
// // const uploadBlobResponse = await blockBlobClient.upload(
|
||||
// // content,
|
||||
// // Buffer.byteLength(content),
|
||||
// // uploadOptions
|
||||
// // );
|
||||
|
||||
// const uploadBlobResponse = await blockBlobClient.uploadFile(
|
||||
// "public/assets/images/HM-Govt-Supplier-to-Govt.jpg"
|
||||
// // uploadOptions
|
||||
// );
|
||||
|
||||
// const tags = {
|
||||
// owner: appealID,
|
||||
// };
|
||||
|
||||
// //console.log(tags);
|
||||
// //await blockBlobClient.setTags(tags);
|
||||
|
||||
// // console.log(
|
||||
// // `Uploaded block blob ${blobName} successfully`,
|
||||
// // uploadBlobResponse.requestId
|
||||
// // );
|
||||
// }
|
||||
|
||||
console.log("Blobs:");
|
||||
for await (const blob of containerClient.listBlobsFlat()) {
|
||||
console.log(`- ${blob.name}`);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export default ShowStorage;
|
||||
Reference in New Issue
Block a user