core: contest: fix export_code for submit_answer

This commit is contained in:
undefined committed 2022-12-16 15:48:33 +08:00
1 parent 4958655ac9
commit 58a5cc0f9e
2 files changed
+19 -8

No files matched your search

+4 -4
View File
@@ -527,13 +527,13 @@ export class ProblemSubmitHandler extends ProblemDetailHandler {
if (!file || file.size === 0) throw new ValidationError('code');
const sizeLimit = config.type === 'submit_answer' ? 128 * 1024 * 1024 : 65535;
if (file.size > sizeLimit) throw new ValidationError('file');
if (file.size > 65535 || await isBinaryFile(file.filepath, file.size)) {
if (config.type !== 'submit_answer' || (file.size < 65535 && !await isBinaryFile(file.filepath, file.size))) {
// TODO auto detect & convert encoding
code = await readFile(file.filepath, 'utf-8');
} else {
const id = nanoid();
await storage.put(`submission/${this.user._id}/${id}`, file.filepath, this.user._id);
files.code = `${this.user._id}/${id}#${file.originalFilename}`;
} else {
// TODO auto detect & convert encoding
code = await readFile(file.filepath, 'utf-8');
}
}
const rid = await record.add(