diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 7fef4bfb9..2608d8ce1 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "3.4.8", + "version": "3.4.9", "bin": "bin/hydrooj.js", "main": "src/loader", "module": "src/loader", diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 0bbde23c7..0e6307cfd 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -291,11 +291,14 @@ export class ProblemDetailHandler extends ProblemHandler { this.tdoc = await contest.get(domainId, tid); if (!this.tdoc) throw new ContestNotFoundError(domainId, tid); this.tsdoc = await contest.getStatus(domainId, tid, this.user._id); - this.pdoc.tag.length = 0; - const showAccept = contest.canShowScoreboard.call(this, this.tdoc, true); - if (!showAccept) this.pdoc.nAccept = 0; if (contest.isNotStarted(this.tdoc)) throw new ContestNotLiveError(tid); if (!contest.isDone(this.tdoc) && !this.tsdoc?.attend) throw new ContestNotAttendedError(tid); + this.pdoc.tag.length = 0; + if (!contest.canShowScoreboard(this.tdoc) || !contest.isLocked(this.tdoc)) { + delete this.pdoc.nAccept; + delete this.pdoc.nSubmit; + delete this.pdoc.stats; + } } else if (!problem.canViewBy(this.pdoc, this.user)) { throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN); } diff --git a/packages/ui-default/components/editor/index.ts b/packages/ui-default/components/editor/index.ts index edd58d57b..69689b933 100644 --- a/packages/ui-default/components/editor/index.ts +++ b/packages/ui-default/components/editor/index.ts @@ -75,7 +75,7 @@ export default class Editor extends DOMAttachedObject { // eslint-disable-next-line no-nested-ternary this.model = typeof model === 'string' ? monaco.editor.getModel(monaco.Uri.parse(model)) - || monaco.editor.createModel(value, language, monaco.Uri.parse(model)) + || monaco.editor.createModel(value, language === 'auto' ? undefined : language, monaco.Uri.parse(model)) : model; this.model.setValue(value); const cfg: import('../monaco').default.editor.IStandaloneEditorConstructionOptions = { @@ -195,11 +195,7 @@ export default class Editor extends DOMAttachedObject { if (!this.isValid) throw new Error('Editor is not loaded'); } - /** - * @param {string?} val - * @returns {string} - */ - value(val) { + value(val?: string) { this.ensureValid(); if (typeof val === 'string') return (this.editor || this.vditor).setValue(val); return (this.editor || this.vditor).getValue(); diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index 7a38b0f66..60f4baecd 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.31.4", + "version": "4.31.5", "author": "undefined ", "license": "AGPL-3.0", "main": "hydro.js", diff --git a/packages/ui-default/pages/problem_files.page.js b/packages/ui-default/pages/problem_files.page.js index abc2c4d6b..b12f2a868 100644 --- a/packages/ui-default/pages/problem_files.page.js +++ b/packages/ui-default/pages/problem_files.page.js @@ -115,10 +115,7 @@ const page = new NamedPage('problem_files', () => { const selectedFiles = ensureAndGetSelectedFiles(type); if (selectedFiles === null) return; const action = await new ConfirmDialog({ - $body: tpl` -
-

${i18n('Confirm to delete the selected files?')}

-
`, + $body: tpl.typoMsg(i18n('Confirm to delete the selected files?')), }).open(); if (action !== 'yes') return; try { @@ -181,12 +178,13 @@ const page = new NamedPage('problem_files', () => { height: `${window.innerHeight - 100}px`, cancelByEsc: false, }).open(); - const language = { - yaml: 'yaml', - yml: 'yaml', - cc: 'cpp', - json: 'json', - }[filename.split('.').pop()] || 'plain'; + const languages = [ + ['yaml', ['yaml', 'yml']], + ['cpp', ['c', 'cc', 'cpp', 'h', 'hpp']], + ['json', ['json']], + ['plain', ['in', 'out', 'ans']], + ]; + const language = languages.filter((i) => i[1].includes(filename.split('.').pop()))[0]?.[0] || 'auto'; const editor = new Editor($('[name="fileContent"]'), { value, autoResize: false, @@ -224,8 +222,13 @@ const page = new NamedPage('problem_files', () => { return; } Notification.info(i18n('Loading file...')); - const res = await request.get(link); - content = await request.get(res.url, undefined, { dataType: 'text' }); + try { + const res = await request.get(link); + content = await request.get(res.url, undefined, { dataType: 'text' }); + } catch (e) { + Notification.error(i18n('Failed to load file: {0}', e.message)); + throw e; + } } else Notification.info(i18n('Loading editor...')); const val = await startEdit(filename, content); if (typeof val !== 'string') return;