delete file from s3 if data environment variable is undefined

This commit is contained in:
Cassie Tarakajian 2017-03-30 17:28:28 -04:00
parent 8392acdf3f
commit 23560c7879
2 changed files with 13 additions and 4 deletions

View file

@ -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();

View file

@ -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())
);
}