(domainId: string, pid: number, name: string, f: Readable | Buffer | string, operator = 1)
| 292 | } |
| 293 | |
| 294 | static async addTestdata(domainId: string, pid: number, name: string, f: Readable | Buffer | string, operator = 1) { |
| 295 | name = name.trim(); |
| 296 | if (!name) throw new ValidationError('name'); |
| 297 | const [[, fileinfo]] = await Promise.all([ |
| 298 | document.getSub(domainId, document.TYPE_PROBLEM, pid, 'data', name), |
| 299 | storage.put(`problem/${domainId}/${pid}/testdata/${name}`, f, operator), |
| 300 | ]); |
| 301 | const meta = await storage.getMeta(`problem/${domainId}/${pid}/testdata/${name}`); |
| 302 | if (!meta) throw new FileUploadError(); |
| 303 | const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) }; |
| 304 | payload.lastModified ||= new Date(); |
| 305 | if (!fileinfo) await ProblemModel.push(domainId, pid, 'data', { _id: name, ...payload }); |
| 306 | else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'data', name, payload); |
| 307 | await bus.emit('problem/addTestdata', domainId, pid, name, payload); |
| 308 | } |
| 309 | |
| 310 | static async renameTestdata(domainId: string, pid: number, file: string, newName: string, operator = 1) { |
| 311 | if (file === newName) return; |
no test coverage detected