|
|
@ -318,13 +318,13 @@ class Problem extends Model { |
|
|
|
return syzoj.utils.resolvePath(syzoj.config.upload_dir, 'testdata', this.id.toString()); |
|
|
|
return syzoj.utils.resolvePath(syzoj.config.upload_dir, 'testdata', this.id.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async updateTestdata(path) { |
|
|
|
async updateTestdata(path, noLimit) { |
|
|
|
let AdmZip = require('adm-zip'); |
|
|
|
let AdmZip = require('adm-zip'); |
|
|
|
let zip = new AdmZip(path); |
|
|
|
let zip = new AdmZip(path); |
|
|
|
|
|
|
|
|
|
|
|
let unzipSize = 0; |
|
|
|
let unzipSize = 0; |
|
|
|
for (let x of zip.getEntries()) unzipSize += x.header.size; |
|
|
|
for (let x of zip.getEntries()) unzipSize += x.header.size; |
|
|
|
if (unzipSize > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。'); |
|
|
|
if (!noLimit && unzipSize > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。'); |
|
|
|
|
|
|
|
|
|
|
|
let dir = this.getTestdataPath(); |
|
|
|
let dir = this.getTestdataPath(); |
|
|
|
let fs = Promise.promisifyAll(require('fs-extra')); |
|
|
|
let fs = Promise.promisifyAll(require('fs-extra')); |
|
|
@ -346,7 +346,7 @@ class Problem extends Model { |
|
|
|
for (let file of list.files) if (file.filename !== filename) oldSize += file.size; |
|
|
|
for (let file of list.files) if (file.filename !== filename) oldSize += file.size; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (oldSize + size > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。'); |
|
|
|
if (!noLimit && oldSize + size > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。'); |
|
|
|
|
|
|
|
|
|
|
|
await fs.moveAsync(filepath, path.join(dir, filename), { overwrite: true }); |
|
|
|
await fs.moveAsync(filepath, path.join(dir, filename), { overwrite: true }); |
|
|
|
await fs.removeAsync(dir + '.zip'); |
|
|
|
await fs.removeAsync(dir + '.zip'); |
|
|
@ -424,8 +424,8 @@ class Problem extends Model { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async updateFile(path, type) { |
|
|
|
async updateFile(path, type, noLimit) { |
|
|
|
let file = await File.upload(path, type); |
|
|
|
let file = await File.upload(path, type, noLimit); |
|
|
|
|
|
|
|
|
|
|
|
if (type === 'additional_file') { |
|
|
|
if (type === 'additional_file') { |
|
|
|
this.additional_file_id = file.id; |
|
|
|
this.additional_file_id = file.id; |
|
|
|