framework: auto cleanup uploaded files (#818)

This commit is contained in:
undefined committed 2025-01-03 01:01:37 +08:00
1 parent 8eed68e78f
commit 566ebd9bb2
10 files changed
+40 -24

No files matched your search

+1 -2
View File
@@ -476,8 +476,7 @@ export class ContestManagementHandler extends ContestManagementBaseHandler {
}
const file = this.request.files?.file;
if (!file) throw new ValidationError('file');
const f = statSync(file.filepath);
const size = Math.sum((this.tdoc.files || []).map((i) => i.size)) + f.size;
const size = Math.sum((this.tdoc.files || []).map((i) => i.size)) + file.size;
if (size >= system.get('limit.contest_files_size')) {
throw new FileLimitExceededError('size');
}
+1 -2
View File
@@ -273,8 +273,7 @@ export class HomeworkFilesHandler extends Handler {
}
const file = this.request.files?.file;
if (!file) throw new ValidationError('file');
const f = statSync(file.filepath);
const size = Math.sum((this.tdoc.files || []).map((i) => i.size)) + f.size;
const size = Math.sum((this.tdoc.files || []).map((i) => i.size)) + file.size;
if (size >= system.get('limit.contest_files_size')) {
throw new FileLimitExceededError('size');
}
+1 -2
View File
@@ -53,8 +53,7 @@ export class FilesHandler extends Handler {
}
const file = this.request.files?.file;
if (!file) throw new ValidationError('file');
const f = statSync(file.filepath);
const size = Math.sum((this.user._files || []).map((i) => i.size)) + f.size;
const size = Math.sum((this.user._files || []).map((i) => i.size)) + file.size;
if (size >= system.get('limit.user_files_size')) {
if (!this.user.hasPriv(PRIV.PRIV_UNLIMITED_QUOTA)) throw new FileLimitExceededError('size');
}
+4 -3
View File
@@ -705,13 +705,14 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
@post('filename', Types.Filename, true)
@post('type', Types.Range(['testdata', 'additional_file']), true)
async postUploadFile(domainId: string, filename: string, type = 'testdata') {
if (!this.request.files.file) throw new ValidationError('file');
filename ||= this.request.files.file.originalFilename || String.random(16);
const file = this.request.files.file;
if (!file) throw new ValidationError('file');
filename ||= file.originalFilename || String.random(16);
const files = [];
if (filename.endsWith('.zip') && type === 'testdata') {
let zip: AdmZip;
try {
zip = new AdmZip(this.request.files.file.filepath);
zip = new AdmZip(file.filepath);
} catch (e) {
throw new ValidationError('zip', null, e.message);
}
+1 -2
View File
@@ -261,8 +261,7 @@ export class TrainingFilesHandler extends Handler {
}
const file = this.request.files?.file;
if (!file) throw new ValidationError('file');
const f = statSync(file.filepath);
const size = Math.sum((this.tdoc.files || []).map((i) => i.size)) + f.size;
const size = Math.sum((this.tdoc.files || []).map((i) => i.size)) + file.size;
if (size >= system.get('limit.contest_files_size')) {
throw new FileLimitExceededError('size');
}