diff --git a/server/media/imgproxy-media.js b/server/media/imgproxy-media.js index 55d88f938..46a8dd840 100644 --- a/server/media/imgproxy-media.js +++ b/server/media/imgproxy-media.js @@ -103,13 +103,7 @@ const getThumbnailUrls = async (req, res) => { /////< base 64 URL encoded to image path> //When working with documents from Cloudinary, the URL does not include the extension. - let key; - - if (/\.[^/.]+$/.test(document.key)) { - key = document.key; - } else { - key = `${document.key}.${document.extension.toLowerCase()}`; - } + let key = keyStandardize(document) // Build the S3 path to the object. const fullS3Path = `s3://${imgproxyDestinationBucket}/${key}`; const base64UrlEncodedKeyString = base64UrlEncode(fullS3Path); @@ -205,7 +199,7 @@ const downloadFiles = async (req, res) => { try { for (const doc of data.documents) { - const key = doc.key; + let key = keyStandardize(doc) let response; try { response = await s3client.send( @@ -388,6 +382,15 @@ const moveFiles = async (req, res) => { } }; +const keyStandardize = (doc) => { + if (/\.[^/.]+$/.test(doc.key)) { + return doc.key; + } else { + return `${doc.key}.${doc.extension.toLowerCase()}`; + } +}; + + module.exports = { generateSignedUploadUrls, getThumbnailUrls,