feat: delete dms trash file
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-07-19 12:40:52 +02:00
parent f1c3a3f721
commit 1be0e9b7a9
1 changed files with 16 additions and 5 deletions

View File

@ -15,7 +15,7 @@ module.exports = Self => {
}
});
Self.deleteTrashFiles = async(options) => {
Self.deleteTrashFiles = async options => {
const tx = await Self.beginTransaction({});
const myOptions = {};
@ -33,9 +33,15 @@ module.exports = Self => {
where: {code: 'trash'}
}, myOptions);
const date = new Date();
date.setMonth(date.getMonth() - 4);
const dmsToDelete = await models.Dms.find({
where: {
dmsTypeFk: trashDmsType.id
and: [
{dmsTypeFk: trashDmsType.id},
{created: {lt: date}}
]
}
}, myOptions);
@ -43,14 +49,19 @@ module.exports = Self => {
const pathHash = DmsContainer.getHash(dms.id);
const dmsContainer = await DmsContainer.container(pathHash);
const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file);
const dstFolder = path.join(dmsContainer.client.root, pathHash);
await fs.unlink(dstFile);
await dms.destroy(myOptions);
try {
await fs.rmdir(dstFolder);
await dms.destroy(myOptions);
} catch (err) {
await dms.destroy(myOptions);
}
}
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};