Skip to content

Commit

Permalink
Fix scripts.v2: migrate & capture (#2465)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Kolesnikov <rokolesnikov@microsoft.com>
  • Loading branch information
rkolesnikovDX and Roman Kolesnikov authored Apr 15, 2024
1 parent cd983ec commit 63975bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
29 changes: 15 additions & 14 deletions scripts.v2/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,24 @@ async function downloadBlobsRecursive(containerClient, outputFolder, prefix = un
let blobs = containerClient.listBlobsByHierarchy("/", prefix ? { prefix: prefix } : undefined);
for await (const blob of blobs) {
if (blob.kind === "prefix") {
await this.downloadBlobsRecursive(containerClient, outputFolder, blob.name);
} else {
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);
const extension = mime.getExtension(blob.properties.contentType);
let pathToFile;
await downloadBlobsRecursive(containerClient, outputFolder, blob.name);
continue;
}

if (extension != null) {
pathToFile = `${snapshotMediaFolder}/${blob.name}.${extension}`;
}
else {
pathToFile = `${snapshotMediaFolder}/${blob.name}`;
}
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);
const extension = mime.getExtension(blob.properties.contentType);
let pathToFile;

const folderPath = pathToFile.substring(0, pathToFile.lastIndexOf("/"));
await fs.promises.mkdir(path.resolve(folderPath), { recursive: true });
await blockBlobClient.downloadToFile(pathToFile);
if (extension != null) {
pathToFile = `${outputFolder}/${blob.name}.${extension}`;
}
else {
pathToFile = `${outputFolder}/${blob.name}`;
}

const folderPath = pathToFile.substring(0, pathToFile.lastIndexOf("/"));
await fs.promises.mkdir(path.resolve(folderPath), { recursive: true });
await blockBlobClient.downloadToFile(pathToFile);
}
}

Expand Down
21 changes: 11 additions & 10 deletions scripts.v3/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,19 @@ class ImporterExporter {
for await (const blob of blobs) {
if (blob.kind === "prefix") {
await this.downloadBlobsRecursive(containerClient, outputFolder, blob.name);
} else {
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);
const pathToFile = `${outputFolder}/${blob.name}`;
const folderPath = pathToFile.substring(0, pathToFile.lastIndexOf("/"));
continue;
}

await fs.promises.mkdir(path.resolve(folderPath), { recursive: true });
await blockBlobClient.downloadToFile(pathToFile);
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);
const pathToFile = `${outputFolder}/${blob.name}`;
const folderPath = pathToFile.substring(0, pathToFile.lastIndexOf("/"));

const metadata = { contentType: blob.properties.contentType };
const metadataFile = JSON.stringify(metadata);
await fs.promises.writeFile(pathToFile + metadataFileExt, metadataFile);
}
await fs.promises.mkdir(path.resolve(folderPath), { recursive: true });
await blockBlobClient.downloadToFile(pathToFile);

const metadata = { contentType: blob.properties.contentType };
const metadataFile = JSON.stringify(metadata);
await fs.promises.writeFile(pathToFile + metadataFileExt, metadataFile);
}
}

Expand Down

0 comments on commit 63975bc

Please sign in to comment.