delete file from s3 if data environment variable is undefined
This commit is contained in:
parent
8392acdf3f
commit
23560c7879
2 changed files with 13 additions and 4 deletions
|
@ -46,9 +46,11 @@ function deleteMany(files, ids) {
|
||||||
const objectKeys = [];
|
const objectKeys = [];
|
||||||
|
|
||||||
each(ids, (id, cb) => {
|
each(ids, (id, cb) => {
|
||||||
if (files.id(id).url && moment(process.env.S3_DATE) < moment(files.id(id).createdAt)) {
|
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());
|
objectKeys.push(files.id(id).url.split("/").pop());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
files.id(id).remove();
|
files.id(id).remove();
|
||||||
cb();
|
cb();
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
|
|
|
@ -92,7 +92,14 @@ export function getProject(req, res) {
|
||||||
|
|
||||||
function deleteFilesFromS3(files) {
|
function deleteFilesFromS3(files) {
|
||||||
deleteObjectsFromS3(
|
deleteObjectsFromS3(
|
||||||
files.filter((file) => file.url && moment(process.env.S3_DATE) < moment(file.createdAt))
|
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())
|
.map((file) => file.url.split('/').pop())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue