| 580 | @param('autoOrganizeInput', Types.Boolean, true) |
| 581 | @param('tid', Types.ObjectId, true) |
| 582 | async post(domainId: string, input = '', autoOrganizeInput = false, tid?: ObjectId) { |
| 583 | await this.limitRate('add_record', 60, system.get('limit.submission_user'), '{{user}}'); |
| 584 | await this.limitRate('add_record', 60, system.get('limit.submission')); |
| 585 | const id = `${this.user._id}/${nanoid()}`; |
| 586 | if (this.request.files?.file?.size > 0) { |
| 587 | const file = this.request.files.file; |
| 588 | if (!file || file.size > 2 * 1024 * 1024) throw new ValidationError('input'); |
| 589 | await storage.put(`submission/${id}`, file.filepath, this.user._id); |
| 590 | } else if (input) { |
| 591 | if (autoOrganizeInput) input = input.replace(/\s+\n/g, '\n').replace(/\s+ /g, ' '); |
| 592 | await storage.put(`submission/${id}`, Buffer.from(input), this.user._id); |
| 593 | } |
| 594 | const rid = await record.add( |
| 595 | domainId, this.pdoc.docId, this.user._id, |
| 596 | this.rdoc.lang, this.rdoc.code, true, |
| 597 | { |
| 598 | contest: tid, |
| 599 | type: 'hack', |
| 600 | hackTarget: this.rdoc._id, |
| 601 | files: { hack: `${id}#input.txt` }, |
| 602 | }, |
| 603 | ); |
| 604 | this.response.body = { rid }; |
| 605 | this.response.redirect = this.url('record_detail', { rid }); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | export class ProblemManageHandler extends ProblemDetailHandler { |