IO-3281 Resolve key issue for downloads.
This commit is contained in:
@@ -103,13 +103,7 @@ const getThumbnailUrls = async (req, res) => {
|
|||||||
//<Cloudfront_to_lambda>/<hmac with SHA of entire request URI path (with base64 encoded URL if needed), beginning with un-encoded/un-hashed Salt>/<remainder of url - resize params >/< base 64 URL encoded to image path>
|
//<Cloudfront_to_lambda>/<hmac with SHA of entire request URI path (with base64 encoded URL if needed), beginning with un-encoded/un-hashed Salt>/<remainder of url - resize params >/< base 64 URL encoded to image path>
|
||||||
//When working with documents from Cloudinary, the URL does not include the extension.
|
//When working with documents from Cloudinary, the URL does not include the extension.
|
||||||
|
|
||||||
let key;
|
let key = keyStandardize(document)
|
||||||
|
|
||||||
if (/\.[^/.]+$/.test(document.key)) {
|
|
||||||
key = document.key;
|
|
||||||
} else {
|
|
||||||
key = `${document.key}.${document.extension.toLowerCase()}`;
|
|
||||||
}
|
|
||||||
// Build the S3 path to the object.
|
// Build the S3 path to the object.
|
||||||
const fullS3Path = `s3://${imgproxyDestinationBucket}/${key}`;
|
const fullS3Path = `s3://${imgproxyDestinationBucket}/${key}`;
|
||||||
const base64UrlEncodedKeyString = base64UrlEncode(fullS3Path);
|
const base64UrlEncodedKeyString = base64UrlEncode(fullS3Path);
|
||||||
@@ -205,7 +199,7 @@ const downloadFiles = async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
for (const doc of data.documents) {
|
for (const doc of data.documents) {
|
||||||
const key = doc.key;
|
let key = keyStandardize(doc)
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
response = await s3client.send(
|
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 = {
|
module.exports = {
|
||||||
generateSignedUploadUrls,
|
generateSignedUploadUrls,
|
||||||
getThumbnailUrls,
|
getThumbnailUrls,
|
||||||
|
|||||||
Reference in New Issue
Block a user