diff --git a/server/controllers/file.controller.js b/server/controllers/file.controller.js index b827db01..a3e4b9a7 100644 --- a/server/controllers/file.controller.js +++ b/server/controllers/file.controller.js @@ -46,8 +46,10 @@ function deleteMany(files, ids) { const objectKeys = []; each(ids, (id, cb) => { - if (files.id(id).url && moment(process.env.S3_DATE) < moment(files.id(id).createdAt)) { - objectKeys.push(files.id(id).url.split("/").pop()); + if (files.id(id).url) { + if (!process.env.S3_DATE || (process.env.S3_DATE && moment(process.env.S3_DATE) < moment(files.id(id).createdAt))) { + objectKeys.push(files.id(id).url.split("/").pop()); + } } files.id(id).remove(); cb(); diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js index cfdfce42..591758e9 100644 --- a/server/controllers/project.controller.js +++ b/server/controllers/project.controller.js @@ -92,8 +92,15 @@ export function getProject(req, res) { function deleteFilesFromS3(files) { deleteObjectsFromS3( - files.filter((file) => file.url && moment(process.env.S3_DATE) < moment(file.createdAt)) - .map((file) => file.url.split('/').pop()) + files.filter((file) => { + if (file.url) { + if (!process.env.S3_DATE || (process.env.S3_DATE && moment(process.env.S3_DATE) < moment(file.createdAt))) { + return true; + } + } + return false; + }) + .map((file) => file.url.split('/').pop()) ); }