create pdf reps for lpa

This commit is contained in:
2023-09-26 09:12:57 +01:00
parent 34c3e06ee3
commit 41847b3433
55 changed files with 8798 additions and 168 deletions
+156 -28
View File
@@ -55,7 +55,7 @@ export const createContainerSas = async (containerName) => {
);
// Need only list permission to list blobs
const containerPermissions = "rcwltdf";
const containerPermissions = "rcwdltf";
// Best practice: SAS options are time-limited
const sasOptions = {
@@ -260,6 +260,7 @@ export const createBlob = async (formContent, containerName, caseref) => {
const tags = {
containerid: containerName,
caseID: caseID,
blobType: "Appeal",
};
console.log("the tags:", tags);
@@ -283,7 +284,7 @@ export const createRepBlob = async (formContent, containerName, caseref) => {
const content = JSON.stringify(formContent);
console.log(content);
//console.log(content);
const blobName = caseref + "/" + caseID + "_rep.json";
console.log("blobName:", blobName);
@@ -395,6 +396,90 @@ export const uploadFile = async (formContent, containerName, foldername) => {
}
};
export const uploadRepFiles = async (
formContent,
containerName,
foldername
) => {
const containerToken = await createContainerSas(containerName);
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
const containerClient = new ContainerClient(sasUrl);
const files = formContent;
console.log(...formContent);
console.log("rep files...", files, Object.keys(files).length, foldername);
// console.log(`files[${prop}] = ${files[prop][0].size}`);
const blobName = foldername + formContent.split("tmp/")[1];
console.log(blobName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const uploadBlobResponse = await blockBlobClient.uploadFile(formContent);
const tags = {
containerid: containerName,
caseID: foldername,
documentType: "rep content",
};
console.log(tags);
// const withTags = await blockBlobClient.setTags(tags);
// const withMeta = await blockBlobClient.setMetadata(tags);
console.log(
`Uploaded block blob ${files} successfully`,
uploadBlobResponse.requestId
);
};
export const uploadPDFRepFiles = async (
formContent,
containerName,
foldername,
repType
) => {
const containerToken = await createContainerSas(containerName);
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
const containerClient = new ContainerClient(sasUrl);
const files = formContent;
console.log(formContent, containerName, foldername);
console.log(
"rep pdf files...",
files,
Object.keys(files).length,
foldername
);
// console.log(`files[${prop}] = ${files[prop][0].size}`);
console.log(foldername + "/files/" + formContent.split("tmp/")[1]);
const blobName = foldername + "/files/" + formContent.split("tmp/")[1];
console.log(blobName);
console.log(blobName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const uploadBlobResponse = await blockBlobClient.uploadFile(formContent);
const tags = {
containerid: containerName,
caseID: foldername,
documentType: repType,
blobType: "RepresentationPDF",
};
console.log("the tags:", tags);
const withTags = await blockBlobClient.setTags(tags);
const withMeta = await blockBlobClient.setMetadata(tags);
console.log(
`Uploaded block blob ${files} successfully`,
uploadBlobResponse.requestId
);
};
export const downloadFile = async (containerName, blobName) => {
//console.log.apply(containerName, blobName);
const containerToken = await createContainerSas(containerName);
@@ -486,12 +571,32 @@ export const downloadAllProgressFiles = async (
);
};
export const downloadRepFile = async (
containerName,
blobName,
casefolderID
) => {
console.log(containerName, blobName);
const containerToken = await createContainerSas(containerName);
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
const containerClient = new ContainerClient(sasUrl);
const blobClient = containerClient.getBlobClient(blobName);
const downloadedBlob = await blobClient.download();
const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody);
console.log("Downloaded blob content:", downloaded.toString());
return JSON.parse(downloaded.toString());
};
export const downloadAllRepsFiles = async (containerName, repsBlobObj) => {
// console.log(
// "/////////////////////////\n downloading files: " +
// JSON.stringify(repsBlobObj) +
// "\n/////////////////////////\n"
// );
console.log(
"/////////////////////////\n downloading files: " +
JSON.stringify(repsBlobObj) +
"\n/////////////////////////\n"
);
const containerToken = await createContainerSas(containerName);
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
@@ -500,14 +605,18 @@ export const downloadAllRepsFiles = async (containerName, repsBlobObj) => {
let blobClient = {};
let downloadedBlob = {};
let repArr = [];
let downloaded = "";
let downloaded = [];
let caseBlob = {};
let caseDownloaded = "";
let blobCount = 0;
Array.isArray(repsBlobObj) &&
!repsBlobObj.length &&
console.log("is empt and an array");
for (const prop in repsBlobObj) {
//console.log(`Progress - ${prop}: ${repsBlobObj[prop].name}`);
blobClient = containerClient.getBlobClient(repsBlobObj[prop].name);
console.log(`Progress - ${prop}: ${repsBlobObj[prop].path}`);
blobClient = containerClient.getBlobClient(repsBlobObj[prop].path);
downloadedBlob = await blobClient.download(0);
let repBlobObj = await streamToBuffer(
downloadedBlob.readableStreamBody
@@ -517,17 +626,29 @@ export const downloadAllRepsFiles = async (containerName, repsBlobObj) => {
repBlobObj["casereference"] = repsBlobObj[prop].name.split("/")[0];
repBlobObj = JSON.stringify(repBlobObj);
// repBlobObj = JSON.stringify(repBlobObj);
downloaded = downloaded + repBlobObj + ",";
downloaded.push(repBlobObj);
blobCount++;
}
downloaded = downloaded.substring(0, downloaded.length - 1);
//downloaded = downloaded.substring(0, downloaded.length - 1);
// console.log(
// "/////////////////////////\n downloaded : " +
// JSON.stringify(
// '{ "@odata.count": ' +
// blobCount +
// ',"value": ' +
// downloaded +
// "}"
// ) +
// "\n/////////////////////////\n"
// );
return JSON.parse(
'{ "@odata.count": ' + blobCount + ',"value": [' + downloaded + "]}"
);
return {
"@odata.count": blobCount,
"value": downloaded,
};
};
const streamToBuffer = async (readableStream) => {
@@ -642,7 +763,9 @@ export const getAllProgressBlobs = async (containerName) => {
let blobCount = 0;
let blobObj = [];
for await (const blob of containerClient.listBlobsFlat()) {
for await (const blob of containerClient.findBlobsByTags(
"blobType='Appeal'"
)) {
blob.name.split("/")[1].indexOf("_appeal.json") > 0 &&
blob.name.split("/")[1].indexOf("undefined") < 0 &&
blobObj.push({
@@ -661,12 +784,12 @@ export const getAllProgressBlobs = async (containerName) => {
});
}
//console.log("blobObj:", blobObj);
console.log("blobObj:", blobObj);
return blobObj;
};
export const getRepslobs = async (containerName, caseReference) => {
export const getRepsBlobs = async (containerName) => {
const containerToken = await createContainerSas(containerName);
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
@@ -677,25 +800,30 @@ export const getRepslobs = async (containerName, caseReference) => {
for await (const blob of containerClient.findBlobsByTags(
"blobType='Representation'"
)) {
console.log(`-----Blob ${blobCount++}: ${blob.name}`);
blobCount++;
}
// console.log(
// "this is the casefolder and blobcount:",
// caseReference,
// blobCount
// );
console.log(
"this is the casefolder and blobcount:",
//caseReference,
blobCount
);
let blobObj = [];
for await (const blob of containerClient.findBlobsByTags(
"blobType='Representation'"
)) {
// console.log("getRepslobs in here");
// console.log(blob);
blobObj.push(blob);
console.log(blob);
blob.name.split("/")[1].indexOf("_rep.json") > 0 &&
blob.name.split("/")[1].indexOf("undefined") < 0 &&
blobObj.push({
"name": blob.name.split("/")[1],
"path": blob.name,
});
}
//console.log("blobObjwwwww:", blobObj);
console.log("blobObjwwwww:", blobObj);
return blobObj;
};