From b02750551236de826353cfbf6565f745c6467017 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 8 Jan 2024 16:45:23 +0800 Subject: [PATCH] core: bug fixes --- packages/hydrooj/src/handler/problem.ts | 4 ++-- packages/hydrooj/src/handler/record.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 74a75127a..7d19c3cd1 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -807,8 +807,8 @@ export class ProblemFilesHandler extends ProblemDetailHandler { @post('std', Types.Filename) @post('gen', Types.Filename) async postGenerateTestdata(domainId: string, std: string, gen: string) { - if (!this.pdoc.data.find((i) => i.name === std)) throw new BadRequestError(); - if (!this.pdoc.data.find((i) => i.name === gen)) throw new BadRequestError(); + if (!this.pdoc.data?.find((i) => i.name === std)) throw new BadRequestError(); + if (!this.pdoc.data?.find((i) => i.name === gen)) throw new BadRequestError(); const rid = await record.add(domainId, this.pdoc.docId, this.user._id, '_', `${gen}\n${std}`, true, { type: 'generate', }); diff --git a/packages/hydrooj/src/handler/record.ts b/packages/hydrooj/src/handler/record.ts index ab11e14c9..78bf82314 100644 --- a/packages/hydrooj/src/handler/record.ts +++ b/packages/hydrooj/src/handler/record.ts @@ -189,7 +189,7 @@ class RecordDetailHandler extends ContestDetailBaseHandler { if (this.tdoc.allowViewCode && contest.isDone(this.tdoc)) { canViewCode ||= tsdoc?.attend; } - if (!tsdoc?.attend && !problem.canViewBy(pdoc, this.user)) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN); + if (!tsdoc?.attend && pdoc && !problem.canViewBy(pdoc, this.user)) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN); } else if (pdoc && !problem.canViewBy(pdoc, this.user)) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN); if (!canViewCode) { rdoc.code = '';