Browse Source

Limit testdata files for normal users

pull/6/head
Menci 7 years ago
parent
commit
6ef64d1c03
  1. 14
      models/problem.js

14
models/problem.js

@ -322,10 +322,12 @@ class Problem extends Model {
await syzoj.utils.lock(['Problem::Testdata', this.id], async () => {
let p7zip = new (require('node-7z'));
let unzipSize = 0;
let unzipSize = 0, unzipCount;
await p7zip.list(path).progress(files => {
unzipCount = files.length;
for (let file of files) unzipSize += file.size;
});
if (!noLimit && unzipCount > syzoj.config.limit.testdata_filecount) throw new ErrorMessage('数据包中的文件太多。');
if (!noLimit && unzipSize > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。');
let dir = this.getTestdataPath();
@ -344,13 +346,17 @@ class Problem extends Model {
let fs = Promise.promisifyAll(require('fs-extra')), path = require('path');
await fs.ensureDirAsync(dir);
let oldSize = 0;
let list = await this.listTestdata();
let oldSize = 0, list = await this.listTestdata(), replace = false, oldCount = 0;
if (list) {
for (let file of list.files) if (file.filename !== filename) oldSize += file.size;
oldCount = list.files.length;
for (let file of list.files) {
if (file.filename !== filename) oldSize += file.size;
else replace = true;
}
}
if (!noLimit && oldSize + size > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。');
if (!noLimit && oldCount + !replace > syzoj.config.limit.testdata_filecount) throw new ErrorMessage('数据包中的文件太多。');
await fs.moveAsync(filepath, path.join(dir, filename), { overwrite: true });
await fs.removeAsync(dir + '.zip');

Loading…
Cancel
Save