updated storage account stuff to take auth id

This commit is contained in:
2022-08-26 15:19:34 +01:00
parent 671d49c394
commit 862a953aae
18 changed files with 346 additions and 133 deletions
+70 -31
View File
@@ -14,7 +14,7 @@ const STORAGE_CONTAINER = process.env.AZURE_PEDW_CONTAINER;
export const createContainer = async (containerName) => {
const creds = new DefaultAzureCredential();
containerName = containerName.toLowerCase();
//containerName = containerName.toLowerCase();
// console.log(
// "container name:",
@@ -40,6 +40,8 @@ export const createContainer = async (containerName) => {
// console.log(`- ${container.name}`);
// }
console.log("\n//////////////////\n container name :", containerName);
return containerName;
};
@@ -53,7 +55,7 @@ export const getContainers = async () => {
}
};
export const getBlobs = async (containerName) => {
export const getBlobs = async (containerName, casefolderID) => {
const creds = new DefaultAzureCredential();
const containerClient = new ContainerClient(
@@ -65,14 +67,14 @@ export const getBlobs = async (containerName) => {
const blobObj = [];
for await (const blob of containerClient.listBlobsFlat({
prefix: "files/",
prefix: casefolderID + "/files/",
})) {
let blobDocumentType = blob.name
.split("/")[1]
.slice(0, blob.name.split("/")[1].indexOf("_"));
.split("/")[2]
.slice(0, blob.name.split("/")[2].indexOf("_"));
blobObj.push({
"name": blob.name.split("/")[1],
"name": blob.name.split("/")[2],
"path": blob.name,
"documentType": blobDocumentType,
"versionId": blob.versionId,
@@ -80,28 +82,50 @@ export const getBlobs = async (containerName) => {
"contentLength": blob.properties.contentLength,
"contentType": blob.contentType,
"lastModified": blob.properties.lastModified,
"filepath":
"/api/file/downloadblob?container=" +
containerName +
"&casefolderID=" +
casefolderID +
"&blobname=" +
blob.name.split("/")[2],
"hashedfilepath": hashAPIPath(
"/api/file/downloadblob?container=" +
containerName.toLowerCase() +
containerName +
"&casefolderID=" +
casefolderID +
"&blobname=" +
blob.name.split("/")[1]
blob.name.split("/")[2]
),
"deletepath":
"/api/file/deleteblob?container=" +
containerName +
"&casefolderID=" +
casefolderID +
"&blobname=" +
blob.name.split("/")[2],
"hasheddeletepath": hashAPIPath(
"/api/file/deleteblob?container=" +
containerName.toLowerCase() +
containerName +
"&casefolderID=" +
casefolderID +
"&blobname=" +
blob.name.split("/")[1]
blob.name.split("/")[2]
),
"hashgetblobs": hashAPIPath(
"/api/file/getbloblist?container=" + containerName.toLowerCase()
"/api/file/getbloblist?container=" +
containerName +
"&casefolderID=" +
casefolderID
),
});
}
console.log("blobObj:", blobObj);
return blobObj;
};
export const createBlob = async (formContent, containerName) => {
export const createBlob = async (formContent, containerName, caseref) => {
const creds = new DefaultAzureCredential();
const containerClient = new ContainerClient(
@@ -109,21 +133,19 @@ export const createBlob = async (formContent, containerName) => {
creds
);
formContent = JSON.parse(formContent);
let caseID = formContent.pinswg_name;
const content = JSON.stringify(formContent);
const blobName =
formContent.pinswg_name + "_" + new Date().getTime() + ".json";
const blobName = caseID + "/" + caseID + ".json";
console.log("blobName:", blobName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const uploadBlobResponse = await blockBlobClient.upload(
content,
Buffer.byteLength(content)
);
// console.log("Blobs:");
// for await (const blob of containerClient.listBlobsByHierarchy("/")) {
// console.log(`- ${blob.name}`);
// }
return formContent.pinswg_name;
};
@@ -159,11 +181,13 @@ export const uploadFile = async (formContent, containerName, foldername) => {
const files = formContent;
//console.log(...formContent);
//console.log("files...", files, files.length);
console.log("files...", files, Object.keys(files).length, foldername);
for (const prop in files) {
//console.log(`files[${prop}] = ${files[prop][0].size}`);
const blobName = "files/" + files[prop][0].fieldName;
console.log(`files[${prop}] = ${files[prop][0].size}`);
const blobName = foldername + "/files/" + files[prop][0].fieldName;
console.log(blobName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const uploadBlobResponse = await blockBlobClient.uploadFile(
files[prop][0].path,
@@ -185,14 +209,18 @@ export const downloadFile = async (containerName, blobName) => {
creds
);
const blobClient = containerClient.getBlobClient("files/" + blobName);
const blobClient = containerClient.getBlobClient(blobName);
const downloadedBlob = await blobClient.download(0);
const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody);
return downloaded;
};
export const downloadProgressFile = async (containerName, blobName) => {
export const downloadProgressFile = async (
containerName,
blobName,
casefolderID
) => {
//console.log.apply(containerName, blobName);
const creds = new DefaultAzureCredential();
@@ -202,6 +230,7 @@ export const downloadProgressFile = async (containerName, blobName) => {
);
const blobClient = containerClient.getBlobClient(blobName);
console.log("herher:", containerName, blobName, casefolderID);
const downloadedBlob = await blobClient.download(0);
const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody);
@@ -221,7 +250,7 @@ const streamToBuffer = async (readableStream) => {
});
};
export const getProgressBlobs = async (containerName) => {
export const getProgressBlobs = async (containerName, caseReference) => {
const creds = new DefaultAzureCredential();
const containerClient = new ContainerClient(
@@ -231,8 +260,11 @@ export const getProgressBlobs = async (containerName) => {
containerClient.createIfNotExists();
console.log("thisi s the caasefolder:", caseReference);
let blobObj = [];
for await (const blob of containerClient.listBlobsFlat()) {
for await (const blob of containerClient.listBlobsFlat({
prefix: caseReference + "/" + caseReference + ".json",
})) {
blobObj.push({
"name": blob.name.split("/")[1],
"path": blob.name,
@@ -243,18 +275,25 @@ export const getProgressBlobs = async (containerName) => {
"lastModified": blob.properties.lastModified,
"hashedfilepath": hashAPIPath(
"/api/file/downloadblob?container=" +
containerName.toLowerCase() +
containerName +
"&casefolderID=" +
caseReference +
"&blobname=" +
blob.name.split("/")[1]
),
"hasheddeletepath": hashAPIPath(
"/api/file/deleteblob?container=" +
containerName.toLowerCase() +
containerName +
"&casefolderID=" +
caseReference +
"&blobname=" +
blob.name.split("/")[1]
),
"hashgetblobs": hashAPIPath(
"/api/file/getbloblist?container=" + containerName.toLowerCase()
"/api/file/getbloblist?container=" +
containerName +
"&casefolderID=" +
caseReference
),
});
}
@@ -265,7 +304,7 @@ export const getProgressBlobs = async (containerName) => {
},
]).reverse()[0];
console.log(blobObj.path);
console.log("blobObj:", blobObj);
return blobObj;
};
+40 -11
View File
@@ -132,6 +132,7 @@ export const azureHeadersPagedCustom = (access_token, showNumberOfRecords) => {
};
export const hashAPIPath = (queryPath) => {
console.log(queryPath);
var hashlink = CryptoJS.HmacSHA256(
queryPath,
CryptoJS.enc.Hex.parse(WORDKEY)
@@ -1040,12 +1041,19 @@ export const createAccount = (formValues) => {
});
};
export const uploadFiles = async (formValues, filesObj, uploadhash) => {
export const uploadFiles = async (
formValues,
filesObj,
containerID,
casefolderID
) => {
let files = filesObj;
//console.log(formValues);
var formData = new FormData();
formData.append("appealData", JSON.stringify(formValues));
formData.append("containerID", containerID);
formData.append("casefolderID", casefolderID);
// files.forEach((file) => formData.append("files", file));
@@ -1076,15 +1084,19 @@ export const uploadFiles = async (formValues, filesObj, uploadhash) => {
}
};
export const getFilesFromBlob = (containerName) => {
export const getFilesFromBlob = (containerName, casefolderID) => {
return axios
.get(
BASE_URL +
"/api/file/getbloblist?container=" +
containerName.toLowerCase() +
containerName +
"&casefolderID=" +
casefolderID +
hashAPIPath(
"/api/file/getbloblist?container=" +
containerName.toLowerCase()
containerName +
"&casefolderID=" +
casefolderID
)
)
.then((res) => {
@@ -1096,12 +1108,18 @@ export const getFilesFromBlob = (containerName) => {
});
};
export const getFilesFromBlobHashed = (containerName, getblobshash) => {
export const getFilesFromBlobHashed = (
containerName,
getblobshash,
casefolderID
) => {
return axios
.get(
BASE_URL +
"/api/file/getbloblist?container=" +
containerName.toLowerCase() +
containerName +
"&casefolderID=" +
casefolderID +
getblobshash
)
.then((res) => {
@@ -1113,12 +1131,19 @@ export const getFilesFromBlobHashed = (containerName, getblobshash) => {
});
};
export const deleteBlob = async (containerName, blobName, deleteblobhash) => {
export const deleteBlob = async (
containerName,
blobName,
deleteblobhash,
casefolderID
) => {
try {
const res = await axios.get(
BASE_URL +
"/api/file/deleteblob?container=" +
containerName.toLowerCase() +
containerName +
"&casefolderID=" +
casefolderID +
"&blobname=" +
blobName +
deleteblobhash
@@ -1155,16 +1180,20 @@ export const downloadBlob = (containerName, blobName) => {
});
};
export const getProgressFromBlob = async (containerName) => {
export const getProgressFromBlob = async (containerName, casereference) => {
console.log("cont:", containerName);
try {
const res = await axios.get(
BASE_URL +
"/api/file/getprogressobjblob?container=" +
containerName.toLowerCase() +
containerName +
"&casefolderID=" +
casereference +
hashAPIPath(
"/api/file/getprogressobjblob?container=" +
containerName.toLowerCase()
containerName +
"&casefolderID=" +
casereference
)
);
return res.data;