diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 2873ea252..2dca96d5c 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.11.8", + "version": "2.11.9", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 4dc9c7885..103457235 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.39.20", + "version": "2.39.21", "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 508ae52e2..bf50d77c5 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -45,6 +45,7 @@ registerValue('Problem', [ ['domainId', 'String!'], ['docId', 'Int!'], ['docType', 'Int!'], + ['pid', 'String'], ['title', 'String!'], ['content', 'String!'], ['config', 'String!'], diff --git a/packages/ui-default/components/zipDownloader/index.js b/packages/ui-default/components/zipDownloader/index.js index fa289e42d..e6b4de908 100644 --- a/packages/ui-default/components/zipDownloader/index.js +++ b/packages/ui-default/components/zipDownloader/index.js @@ -5,7 +5,7 @@ import pipeStream from 'vj/utils/pipeStream'; import i18n from 'vj/utils/i18n'; import request from 'vj/utils/request'; import Notification from 'vj/components/notification'; -import api from 'vj/utils/api'; +import api, { gql } from 'vj/utils/api'; let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext; function onBeforeUnload(e) { @@ -21,11 +21,15 @@ if (window.location.protocol === 'https:' streamsaver.mitm = '/streamsaver/mitm.html'; } -export default async function download(name, targets) { - if (!window.WritableStream) { - window.WritableStream = (await import('web-streams-polyfill/dist/ponyfill.es6')).WritableStream; +const waitForWritableStream = window.WritableStream + ? Promise.resolve() + : import('web-streams-polyfill/dist/ponyfill.es6').then(({ WritableStream }) => { + window.WritableStream = WritableStream; streamsaver.WritableStream = window.WritableStream; - } + }); + +export default async function download(name, targets) { + await waitForWritableStream; const fileStream = streamsaver.createWriteStream(name); let i = 0; const zipStream = createZipStream({ @@ -68,9 +72,8 @@ export async function downloadProblemSet(pids, name = 'Export') { const targets = []; try { for (const pid of pids) { - const { pdoc } = await request.get(`/d/${UiContext.domainId}/api`); - await api(gql` - problem(id: ${pid}) { + const pdoc = await api(gql` + problem(id: ${+pid}) { pid owner title @@ -85,7 +88,7 @@ export async function downloadProblemSet(pids, name = 'Export') { name } } - `); + `, ['data', 'problem']); targets.push({ filename: `${pid}/problem.yaml`, content: dump({ @@ -117,7 +120,7 @@ export async function downloadProblemSet(pids, name = 'Export') { } await download(`${name}.zip`, targets); } catch (e) { - Notification.warn(`${e.error.message} ${e.error.params[0]}`); + Notification.warn(`${e.error?.message} ${e.error?.params?.[0]}`); } } diff --git a/packages/ui-default/utils/api.ts b/packages/ui-default/utils/api.ts index 2a70ae302..cebf72b03 100644 --- a/packages/ui-default/utils/api.ts +++ b/packages/ui-default/utils/api.ts @@ -3,7 +3,7 @@ import request from './request'; export default async (q: string, path: string[] = []) => { let query = q.trim(); if (!query.startsWith('query')) query = `query{${query}}`; - const res = await request.post('/api', { query }); + const res = await request.post(`/d/${UiContext.domainId}/api`, { query }); if (res.errors) throw new Error(res.errors[0].message); let cursor = res; for (const p of path) {