mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
ui: fix problem download
This commit is contained in:
1 parent
a5b5ae49d4
commit
1d48df3e80
5 files changed
+17
-13
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@hydrooj/hydrojudge",
|
||||
"bin": "bin/hydrojudge.js",
|
||||
"version": "2.11.8",
|
||||
"version": "2.11.9",
|
||||
"main": "package.json",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.39.20",
|
||||
"version": "2.39.21",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -45,6 +45,7 @@ registerValue('Problem', [
|
||||
['domainId', 'String!'],
|
||||
['docId', 'Int!'],
|
||||
['docType', 'Int!'],
|
||||
['pid', 'String'],
|
||||
['title', 'String!'],
|
||||
['content', 'String!'],
|
||||
['config', 'String!'],
|
||||
|
||||
@@ -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]}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user