diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 6b906d476..b3505f8e0 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.24.16", + "version": "2.24.17", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 778d5ac79..af855eb03 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -382,8 +382,8 @@ export class ProblemFilesHandler extends ProblemDetailHandler { @param('additional_file', Types.Boolean) async get(domainId: string, getTestdata = true, getAdditionalFile = true) { const canReadData = !this.user.own(this.pdoc) || this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA); - this.response.body.testdata = (getTestdata && canReadData) ? sortFiles(this.pdoc.data) : []; - this.response.body.additional_file = getAdditionalFile ? sortFiles(this.pdoc.additional_file) : []; + this.response.body.testdata = (getTestdata && canReadData) ? sortFiles(this.pdoc.data || []) : []; + this.response.body.additional_file = getAdditionalFile ? sortFiles(this.pdoc.additional_file || []) : []; this.response.template = 'problem_files.html'; } diff --git a/packages/utils/lib/utils.ts b/packages/utils/lib/utils.ts index 6adffb641..5bf1cf821 100644 --- a/packages/utils/lib/utils.ts +++ b/packages/utils/lib/utils.ts @@ -393,6 +393,7 @@ CallableInstance.prototype = Object.create(Function.prototype); const fSortR = /[^\d]+|\d+/g; export function sortFiles(files: { _id: string }[] | string[]) { + if (!files?.length) return []; const isString = typeof files[0] === 'string'; const result = files .map((i) => (isString ? { name: i, weights: i.match(fSortR) } : { ...i, weights: i._id.match(fSortR) })) diff --git a/packages/utils/package.json b/packages/utils/package.json index d69772ddb..edfb34436 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/utils", - "version": "1.0.12", + "version": "1.0.13", "description": "hydrooj utils", "main": "package.json", "repository": "https://github.com/hydro-dev/Hydro.git",