From cc6d868988e7bf84ac18266d86d120f0871eea99 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Thu, 16 Jul 2020 17:00:50 -0400 Subject: [PATCH] [#1500] Update sketch media file duplication code - Sketch duplication code now checks for AWS endpoint via environment variable, rather than hard-coded string - Fixes `aws.controller#getObjectKey`, which was incorrectly generating file keys --- client/modules/IDE/actions/project.js | 4 +++- server/controllers/aws.controller.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js index 9055d484..2909742f 100644 --- a/client/modules/IDE/actions/project.js +++ b/client/modules/IDE/actions/project.js @@ -16,6 +16,8 @@ import { import { clearState, saveState } from '../../../persistState'; const ROOT_URL = getConfig('API_URL'); +const S3_BUCKET_URL_BASE = getConfig('S3_BUCKET_URL_BASE'); +const S3_BUCKET = getConfig('S3_BUCKET'); export function setProject(project) { return { @@ -287,7 +289,7 @@ export function cloneProject(id) { // duplicate all files hosted on S3 each(newFiles, (file, callback) => { - if (file.url && file.url.includes('amazonaws')) { + if (file.url && (file.url.includes(S3_BUCKET_URL_BASE) || file.url.includes(S3_BUCKET))) { const formParams = { url: file.url }; diff --git a/server/controllers/aws.controller.js b/server/controllers/aws.controller.js index 0b7d5d85..27fef714 100644 --- a/server/controllers/aws.controller.js +++ b/server/controllers/aws.controller.js @@ -28,7 +28,7 @@ function getExtension(filename) { export function getObjectKey(url) { const urlArray = url.split('/'); let objectKey; - if (urlArray.length === 6) { + if (urlArray.length === 5) { const key = urlArray.pop(); const userId = urlArray.pop(); objectKey = `${userId}/${key}`;