mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
judge: key check report
This commit is contained in:
1 parent
cf4ef57f68
commit
132ef0312c
14 files changed
+38
-25
No files matched your search
@@ -402,21 +402,25 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
||||
@post('filename', Types.Name, true)
|
||||
@post('type', Types.Range(['testdata', 'additional_file']), true)
|
||||
async postUploadFile(domainId: string, filename: string, type = 'testdata') {
|
||||
if ((this.pdoc.data?.length || 0) + (this.pdoc.additional_file?.length || 0) >= system.get('limit.problem_files_max')) {
|
||||
throw new ForbiddenError('File limit exceeded.');
|
||||
}
|
||||
if (!this.request.files.file) throw new ValidationError('file');
|
||||
const size = Math.sum((this.pdoc.data || []).map((i) => i.size), (this.pdoc.additional_file || []).map((i) => i.size));
|
||||
if (size >= system.get('limit.problem_files_max_size')) {
|
||||
throw new ForbiddenError('File size limit exceeded.');
|
||||
}
|
||||
if (!filename) filename = this.request.files.file.name || String.random(16);
|
||||
if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', null, 'Bad filename');
|
||||
if (!this.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM)) {
|
||||
if ((this.pdoc.data?.length || 0) + (this.pdoc.additional_file?.length || 0)
|
||||
>= system.get('limit.problem_files_max')) {
|
||||
throw new ForbiddenError('File limit exceeded.');
|
||||
}
|
||||
const size = Math.sum((this.pdoc.data || []).map((i) => i.size), (this.pdoc.additional_file || []).map((i) => i.size));
|
||||
if (size >= system.get('limit.problem_files_max_size')) {
|
||||
throw new ForbiddenError('File size limit exceeded.');
|
||||
}
|
||||
}
|
||||
if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
||||
if (filename.endsWith('.zip')) {
|
||||
const zip = new AdmZip(this.request.files.file.path);
|
||||
const entries = zip.getEntries();
|
||||
for (const entry of entries) {
|
||||
// TODO check file size
|
||||
if (!entry.name) continue;
|
||||
if (type === 'testdata') {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
|
||||
Reference in new issue
Block a user