awaiting submissions from storage acc

This commit is contained in:
2022-09-05 16:46:30 +01:00
parent b0dde836b0
commit c66883b4c5
25 changed files with 653 additions and 69 deletions
+134 -4
View File
@@ -120,7 +120,7 @@ export const getBlobs = async (containerName, casefolderID) => {
),
});
}
console.log("blobObj:", blobObj);
//console.log("blobObj:", blobObj);
return blobObj;
};
@@ -230,13 +230,46 @@ export const downloadProgressFile = async (
);
const blobClient = containerClient.getBlobClient(blobName);
console.log("herher:", containerName, blobName, casefolderID);
const downloadedBlob = await blobClient.download(0);
const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody);
return downloaded;
};
export const downloadAllProgressFiles = async (
containerName,
progressBlobObj
) => {
//console.log(progressBlobObj);
const creds = new DefaultAzureCredential();
const containerClient = new ContainerClient(
`${STORAGE_PATH}/${containerName}`,
creds
);
let blobClient = {};
let downloadedBlob = {};
let downloaded = "";
let blobCount = 0;
for (const prop in progressBlobObj) {
//console.log(`${prop}: ${progressBlobObj[prop].path}`);
blobClient = containerClient.getBlobClient(progressBlobObj[prop].path);
downloadedBlob = await blobClient.download(0);
downloaded =
downloaded +
(await streamToBuffer(downloadedBlob.readableStreamBody)) +
",";
blobCount++;
}
downloaded = downloaded.substring(0, downloaded.length - 1);
//console.log(downloaded);
return '{ "@odata.count": ' + blobCount + ',"value": [' + downloaded + "]}";
};
const streamToBuffer = async (readableStream) => {
return new Promise((resolve, reject) => {
const chunks = [];
@@ -250,6 +283,42 @@ const streamToBuffer = async (readableStream) => {
});
};
export const getCaseBlob = async (
containerName,
caseReference,
formContent
) => {
const creds = new DefaultAzureCredential();
const containerClient = new ContainerClient(
`${STORAGE_PATH}/${containerName}`,
creds
);
console.log("have got to create case");
containerClient.createIfNotExists();
let blobCount = 0;
for await (const blob of containerClient.listBlobsFlat({
prefix: caseReference,
})) {
blobCount++;
}
const content = JSON.stringify(formContent);
const blobName = caseReference + "/case/" + caseReference + ".json";
console.log("blobName:", blobName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const uploadBlobResponse = await blockBlobClient.upload(
content,
Buffer.byteLength(content)
);
return blobName;
};
export const getProgressBlobs = async (containerName, caseReference) => {
const creds = new DefaultAzureCredential();
@@ -260,7 +329,15 @@ export const getProgressBlobs = async (containerName, caseReference) => {
containerClient.createIfNotExists();
console.log("thisi s the caasefolder:", caseReference);
let blobCount = 0;
for await (const blob of containerClient.listBlobsFlat({
prefix: caseReference,
})) {
blobCount++;
}
//console.log("this is the caasefolder:", caseReference, blobCount);
let blobObj = [];
for await (const blob of containerClient.listBlobsFlat({
prefix: caseReference + "/" + caseReference + ".json",
@@ -304,7 +381,60 @@ export const getProgressBlobs = async (containerName, caseReference) => {
},
]).reverse()[0];
console.log("blobObj:", blobObj);
//console.log("blobObjwwwww:", blobObj);
return blobObj;
};
export const getAllProgressBlobs = async (containerName) => {
const creds = new DefaultAzureCredential();
const containerClient = new ContainerClient(
`${STORAGE_PATH}/${containerName}`,
creds
);
containerClient.createIfNotExists();
let blobCount = 0;
for await (const blob of containerClient.listBlobsFlat({
// prefix: caseReference,
})) {
blobCount++;
}
//console.log("this is the caasefolder:", caseReference, blobCount);
let blobObj = [];
for await (const blob of containerClient.listBlobsFlat({
//prefix: caseReference + "/" + caseReference + ".json",
})) {
blob.name.split("/")[1].indexOf(".json") > 0 &&
blob.name.split("/")[1].indexOf("undefined") < 0 &&
blobObj.push({
"name": blob.name.split("/")[1],
"path": blob.name,
"versionId": blob.versionId,
"isCurrentVersion": blob.isCurrentVersion,
"contentLength": blob.properties.contentLength,
"contentType": blob.contentType,
"lastModified": blob.properties.lastModified,
// "hashedfilepath": hashAPIPath(
// "/api/file/downloadblob?container=" +
// containerName +
// ),
// "hasheddeletepath": hashAPIPath(
// "/api/file/deleteblob?container=" +
// containerName +
// ),
// "hashgetblobs": hashAPIPath(
// "/api/file/getbloblist?container=" +
// containerName +
// ),
});
}
//console.log("blobObj:", blobObj);
return blobObj;
};
+93 -6
View File
@@ -3,7 +3,8 @@ import https from "https";
import CryptoJS from "crypto-js";
import HmacSHA256 from "crypto-js/hmac-sha256";
import { getFormCollection } from "../components/utils";
import { downloadFile } from "./azurestorage";
import { downloadFile, getCaseBlob } from "./azurestorage";
let BASE_URL;
const port = parseInt(process.env.PORT, 10) || 3000;
@@ -132,7 +133,6 @@ export const azureHeadersPagedCustom = (access_token, showNumberOfRecords) => {
};
export const hashAPIPath = (queryPath) => {
console.log(queryPath);
var hashlink = CryptoJS.HmacSHA256(
queryPath,
CryptoJS.enc.Hex.parse(WORDKEY)
@@ -744,6 +744,11 @@ export const getAwaitingSubmissionProxy = (loggedInUserId) => {
};
export const getAwaitingSubmission = (loggedInUserId) => {
console.log(
BASE_URL +
"/api/endpoint/getawaitingsubmission_api?loggedInUserId=" +
loggedInUserId
);
return axios
.get(
BASE_URL +
@@ -758,6 +763,25 @@ export const getAwaitingSubmission = (loggedInUserId) => {
});
};
export const getAwaitingSubmissionFromBlob = (containerName) => {
return axios
.get(
BASE_URL +
"/api/file/getawaitingsubmissionfromblob?container=" +
containerName +
hashAPIPath(
"/api/file/getawaitingsubmissionfromblob?container=" +
containerName
)
)
.then((res) => {
return res.data;
})
.catch((error) => {
//console.log("API call error", error);
});
};
export const getPortalModuleDetails = (appealType, caseReference) => {
//console.log(
// BASE_URL +
@@ -864,7 +888,13 @@ export const createWatchedCases = (formValues) => {
});
};
export const createNewCase = (appealTypeId, lpaID, contactid, createBody) => {
export const createNewCase = (
appealTypeId,
lpaID,
contactid,
createBody,
containerName
) => {
appealTypeId = parseInt(appealTypeId);
var data = createBody;
@@ -875,7 +905,9 @@ export const createNewCase = (appealTypeId, lpaID, contactid, createBody) => {
"&lpaID=" +
lpaID +
"&contactid=" +
contactid;
contactid +
"&containername=" +
containerName;
var config = {
method: "post",
@@ -1004,6 +1036,31 @@ export const deleteAwaitingSubmissions = (incidentID) => {
});
};
export const deleteAwaitingSubmissionsFromBlob = (
containerID,
casefolderID
) => {
var queryUrl =
"/api/file/deleteawaitingsubmissionsfromblob?container=" +
containerID +
"&casefolderID=" +
casefolderID;
var config = {
method: "get",
url: queryUrl,
};
//console.log(config);
return axios(config)
.then((res) => {
//console.log("deleted ", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};
export const deleteWatchedCases = (watchedCaseID) => {
var queryUrl =
"/api/endpoint/deletewatchedcases_api?watchedCaseID=" + watchedCaseID;
@@ -1165,7 +1222,7 @@ export const downloadBlob = (containerName, blobName) => {
{ responseType: "blob" }
)
.then((response) => {
console.log("Downloaded blob content:www");
console.log("Downloaded blob content:");
res.setHeader(
"content-disposition",
@@ -1181,7 +1238,6 @@ export const downloadBlob = (containerName, blobName) => {
};
export const getProgressFromBlob = async (containerName, casereference) => {
console.log("cont:", containerName);
try {
const res = await axios.get(
BASE_URL +
@@ -1201,3 +1257,34 @@ export const getProgressFromBlob = async (containerName, casereference) => {
console.log("this serror", error);
}
};
export const sendEmail = async (
emailToAddress,
emailSubject,
emailContentTitle,
emailContent
) => {
var mailData = {
"email": emailToAddress,
"subject": emailSubject,
"emailcontenttitle": emailContentTitle,
"emailcontent": emailContent,
};
var queryUrl = "/api/email";
var config = {
method: "post",
url: queryUrl,
data: mailData,
};
return axios(config)
.then((res) => {
//console.log("posted ", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};