diff --git a/package.json b/package.json index b48f14f63..07f7e8522 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "liquidjs": "^9.16.1", "lodash": "^4.17.20", "lunr": "^2.3.9", + "mime-types": "^2.1.27", "moment": "^2.29.1", "msal": "^1.4.1", "prismjs": "^1.22.0", diff --git a/scripts.v2/utils.js b/scripts.v2/utils.js index 4d63b99c2..7517605e8 100644 --- a/scripts.v2/utils.js +++ b/scripts.v2/utils.js @@ -3,6 +3,7 @@ const path = require("path"); const https = require("https"); const { BlobServiceClient } = require("@azure/storage-blob"); const blobStorageContainer = "content"; +const mime = require("mime-types"); process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; @@ -116,7 +117,14 @@ async function downloadBlobs(blobStorageUrl, localMediaFolder) { for await (const blob of blobs) { const blockBlobClient = containerClient.getBlockBlobClient(blob.name); - await blockBlobClient.downloadToFile(`${localMediaFolder}/${blob.name}`); + const extension = mime.extension(blob.properties.contentType); + + if (extension != null) { + await blockBlobClient.downloadToFile(`${localMediaFolder}/${blob.name}.${extension}`); + } + else { + await blockBlobClient.downloadToFile(`${localMediaFolder}/${blob.name}`); + } } } @@ -127,8 +135,15 @@ async function uploadBlobs(blobStorageUrl, localMediaFolder) { for (const fileName of fileNames) { const blobName = path.basename(fileName).split(".")[0]; + const contentType = mime.lookup(path.extname(fileName)); + const blockBlobClient = containerClient.getBlockBlobClient(blobName); - await blockBlobClient.uploadFile(fileName) + + await blockBlobClient.uploadFile(fileName, { + blobHTTPHeaders: { + blobContentType: contentType + } + }); } } @@ -150,4 +165,4 @@ module.exports = { uploadBlobs, deleteBlobs, getStorageSasTokenOrThrow -}; \ No newline at end of file +};