core: support auto delete submission files

This commit is contained in:
undefined committed 2022-04-13 14:28:11 +08:00
1 parent 10950ce8b9
commit 93fd7f97c5
3 files changed
+15 -5

No files matched your search

+11 -1
View File
@@ -102,6 +102,16 @@ export class StorageModel {
}
async function cleanFiles() {
const submissionKeepDate = system.get('submission.saveDays');
if (submissionKeepDate) {
const shouldDelete = moment().subtract(submissionKeepDate, 'day').toDate();
const res = await StorageModel.coll.find({
path: /^submission\//g,
lastModified: { $lt: shouldDelete },
}).toArray();
const paths = res.map((i) => i.path);
await StorageModel.del(paths);
}
if (system.get('server.keepFiles')) return;
let res = await StorageModel.coll.findOneAndDelete({ autoDelete: { $lte: new Date() } });
while (res.value) {
@@ -122,7 +132,7 @@ bus.once('app/started', async () => {
await TaskModel.add({
type: 'schedule',
subType: 'storage.prune',
executeAfter: moment().minute(0).second(0).millisecond(0).toDate(),
executeAfter: moment().startOf('hour').toDate(),
interval: [1, 'hour'],
});
}
+1 -1
View File
@@ -519,7 +519,7 @@ export class Handler extends HandlerCommon {
async init({ domainId }) {
let error;
if (!argv.options.benchmark && !this.notUsage) await this.limitRate('global', 10, 88);
if (!argv.options.benchmark && !this.notUsage) await this.limitRate('global', 5, 88);
const [absoluteDomain, inferDomain, bdoc] = await Promise.all([
domain.get(domainId),
domain.getByHost(this.request.host),