diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index b5b1a43a..4c733a0c 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "4.7.4", + "version": "4.7.5", "bin": "bin/hydrooj.js", "main": "src/plugin-api", "module": "src/plugin-api", diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 3b64f477..1c279b8c 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -666,22 +666,22 @@ export class ProblemConfigHandler extends ProblemManageHandler { export class ProblemFilesHandler extends ProblemDetailHandler { notUsage = true; + @param('d', Types.CommaSeperatedArray, true) @param('pjax', Types.Boolean) @param('sidebar', Types.Boolean) - async get(domainId: string, pjax = false, sidebar = false) { - this.response.body.testdata = sortFiles(this.pdoc.data || []); + async get(domainId: string, d = ['testdata', 'additional_file'], pjax = false, sidebar = false) { + this.response.body.testdata = d.includes('testdata') ? sortFiles(this.pdoc.data || []) : []; this.response.body.reference = this.pdoc.reference; - this.response.body.additional_file = sortFiles(this.pdoc.additional_file || []); + this.response.body.additional_file = d.includes('additional_file') ? sortFiles(this.pdoc.additional_file || []) : []; if (pjax) { const { testdata, additional_file } = this.response.body; const owner = await user.getById(domainId, this.pdoc.owner); const args = { testdata, additional_file, pdoc: this.pdoc, owner_udoc: owner, sidebar, }; - const tasks = [ - this.renderHTML('partials/problem_files.html', { ...args, filetype: 'testdata' }), - this.renderHTML('partials/problem_files.html', { ...args, filetype: 'additional_file' }), - ]; + const tasks = []; + if (d.includes('testdata')) tasks.push(this.renderHTML('partials/problem_files.html', { ...args, filetype: 'testdata' })); + if (d.includes('additional_file')) tasks.push(this.renderHTML('partials/problem_files.html', { ...args, filetype: 'additional_file' })); if (!sidebar) tasks.push(this.renderHTML('partials/problem-sidebar-information.html', args)); this.response.body = { fragments: (await Promise.all(tasks)).map((i) => ({ html: i })), diff --git a/packages/ui-default/api.ts b/packages/ui-default/api.ts index 4abe24b2..8b8c7add 100644 --- a/packages/ui-default/api.ts +++ b/packages/ui-default/api.ts @@ -6,6 +6,7 @@ export * from './components/dialog'; export * as bus from './bus'; export { default as AnsiUp } from 'ansi_up'; export { default as loadMonaco } from './components/monaco/loader'; +export { default as uploadFiles } from './components/upload'; export * as redux from 'react-redux'; export * from './components/zipDownloader'; export { default as $ } from 'jquery'; diff --git a/packages/ui-default/components/upload.ts b/packages/ui-default/components/upload.ts index 915022ee..f27d387c 100644 --- a/packages/ui-default/components/upload.ts +++ b/packages/ui-default/components/upload.ts @@ -68,7 +68,7 @@ export default async function uploadFiles(endpoint = '', files: File[] | FileLis Notification.success(i18n('File uploaded successfully.')); if (options.pjax) { let params = ''; - if (options.type) params += `?testdata=${options.type === 'testdata'}&additional_file=${options.type === 'additional_file'}`; + if (options.type) params += `?d=${options.type}`; if (options.sidebar) params += `${params ? '&' : '?'}sidebar=true`; await pjax.request({ push: false, url: `${endpoint}${params || ''}` }); } diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index a954bc35..9720c138 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.47.3", + "version": "4.47.4", "author": "undefined ", "license": "AGPL-3.0", "main": "index.ts", diff --git a/packages/ui-default/pages/problem_config.page.tsx b/packages/ui-default/pages/problem_config.page.tsx index 29c4f44d..284d2ac9 100644 --- a/packages/ui-default/pages/problem_config.page.tsx +++ b/packages/ui-default/pages/problem_config.page.tsx @@ -57,7 +57,7 @@ const page = new NamedPage('problem_config', () => { type: 'CONFIG_DELETE_TESTDATA', value: file, }); - await pjax.request({ url: './files?testdata=false&sidebar=true', push: false }); + await pjax.request({ url: './files?d=testdata&sidebar=true', push: false }); } catch (error) { Notification.error(error.message); } diff --git a/packages/ui-default/pages/problem_edit.page.js b/packages/ui-default/pages/problem_edit.page.js index ae78ab32..857b2b25 100644 --- a/packages/ui-default/pages/problem_edit.page.js +++ b/packages/ui-default/pages/problem_edit.page.js @@ -214,7 +214,7 @@ export default new NamedPage(['problem_create', 'problem_edit'], (pagename) => { type: 'additional_file', }); Notification.success(i18n('File have been deleted.')); - await pjax.request({ url: './files?testdata=false&sidebar=true', push: false }); + await pjax.request({ url: './files?d=additional_file&sidebar=true', push: false }); } catch (error) { Notification.error(error.message); }