fomr xml cleanup

This commit is contained in:
2022-07-25 16:18:28 +01:00
parent 3b27176868
commit e2970a06e6
34 changed files with 9169 additions and 13116 deletions
+68 -2
View File
@@ -6,8 +6,8 @@ import {
EnvironmentCredential,
ClientSecretCredential,
} from "@azure/identity";
import { hashAPIPath } from ".";
import { consoleLogger, hashAPIPath } from ".";
import _ from "lodash";
const STORAGE_PATH = process.env.AZURE_PEDW_STORAGE_ENDPOINT;
const STORAGE_CONTAINER = process.env.AZURE_PEDW_CONTAINER;
@@ -79,6 +79,7 @@ export const getBlobs = async (containerName) => {
"isCurrentVersion": blob.isCurrentVersion,
"contentLength": blob.properties.contentLength,
"contentType": blob.contentType,
"lastModified": blob.properties.lastModified,
"hashedfilepath": hashAPIPath(
"/api/file/downloadblob?container=" +
containerName.toLowerCase() +
@@ -191,6 +192,22 @@ export const downloadFile = async (containerName, blobName) => {
return downloaded;
};
export const downloadProgressFile = async (containerName, blobName) => {
//console.log.apply(containerName, blobName);
const creds = new DefaultAzureCredential();
const containerClient = new ContainerClient(
`${STORAGE_PATH}/${containerName}`,
creds
);
const blobClient = containerClient.getBlobClient(blobName);
const downloadedBlob = await blobClient.download(0);
const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody);
return downloaded;
};
const streamToBuffer = async (readableStream) => {
return new Promise((resolve, reject) => {
const chunks = [];
@@ -203,3 +220,52 @@ const streamToBuffer = async (readableStream) => {
readableStream.on("error", reject);
});
};
export const getProgressBlobs = async (containerName) => {
const creds = new DefaultAzureCredential();
const containerClient = new ContainerClient(
`${STORAGE_PATH}/${containerName}`,
creds
);
containerClient.createIfNotExists();
let blobObj = [];
for await (const blob of containerClient.listBlobsFlat()) {
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.toLowerCase() +
"&blobname=" +
blob.name.split("/")[1]
),
"hasheddeletepath": hashAPIPath(
"/api/file/deleteblob?container=" +
containerName.toLowerCase() +
"&blobname=" +
blob.name.split("/")[1]
),
"hashgetblobs": hashAPIPath(
"/api/file/getbloblist?container=" + containerName.toLowerCase()
),
});
}
blobObj = _.sortBy(blobObj, [
function (o) {
return o.lastModified;
},
]).reverse()[0];
console.log(blobObj.path);
return blobObj;
};