ui: ignore download if no problem selected

This commit is contained in:
undefined committed 2021-06-15 00:52:35 +08:00
1 parent f95e5452f7
commit fec85985ef
3 files changed
+36 -34

No files matched your search

@@ -66,40 +66,42 @@ export default async function download(name, targets) {
export async function downloadProblemSet(pids, name = 'Export') { export async function downloadProblemSet(pids, name = 'Export') {
Notification.info('Downloading...'); Notification.info('Downloading...');
const targets = []; const targets = [];
for (const pid of pids) { try {
const { pdoc } = await request.get(`/d/${UiContext.domainId}/p/${pid}`); for (const pid of pids) {
targets.push({ const { pdoc } = await request.get(`/d/${UiContext.domainId}/p/${pid}`);
filename: `${pid}/problem.yaml`, targets.push({
content: dump({ filename: `${pid}/problem.yaml`,
pid: pdoc.pid, content: dump({
content: pdoc.content, pid: pdoc.pid,
owner: pdoc.owner, content: pdoc.content,
title: pdoc.title, owner: pdoc.owner,
tag: pdoc.tag, title: pdoc.title,
nSubmit: pdoc.nSubmit, tag: pdoc.tag,
nAccept: pdoc.nAccept, nSubmit: pdoc.nSubmit,
data: (pdoc.data || []).map((i) => pick(i, ['name'])), nAccept: pdoc.nAccept,
additional_file: (pdoc.additional_file || []).map((i) => pick(i, ['name'])), data: (pdoc.data || []).map((i) => pick(i, ['name'])),
difficulty: pdoc.difficulty, additional_file: (pdoc.additional_file || []).map((i) => pick(i, ['name'])),
}), difficulty: pdoc.difficulty,
}); }),
let { links } = await request.post( });
`/d/${UiContext.domainId}/p/${pid}/files`, let { links } = await request.post(
{ operation: 'get_links', files: (pdoc.data || []).map((i) => i.name), type: 'testdata' } `/d/${UiContext.domainId}/p/${pid}/files`,
).catch((e) => { { operation: 'get_links', files: (pdoc.data || []).map((i) => i.name), type: 'testdata' }
Notification.warn(`${e.error.message} ${e.error.params[0]}`); );
}); for (const filename of Object.keys(links)) {
for (const filename of Object.keys(links)) { targets.push({ filename: `${pid}/testdata/${filename}`, url: links[filename] });
targets.push({ filename: `${pid}/testdata/${filename}`, url: links[filename] }); }
} ({ links } = await request.post(`/d/${UiContext.domainId}/p/${pid}/files`, {
({ links } = await request.post(`/d/${UiContext.domainId}/p/${pid}/files`, { operation: 'get_links', files: (pdoc.additional_file || []).map((i) => i.name), type: 'additional_file',
operation: 'get_links', files: (pdoc.additional_file || []).map((i) => i.name), type: 'additional_file', }));
})); for (const filename of Object.keys(links)) {
for (const filename of Object.keys(links)) { targets.push({ filename: `${pid}/additional_file/${filename}`, url: links[filename] });
targets.push({ filename: `${pid}/additional_file/${filename}`, url: links[filename] }); }
} }
await download(`${name}.zip`, targets);
} catch (e) {
Notification.warn(`${e.error.message} ${e.error.params[0]}`);
} }
await download(`${name}.zip`, targets);
} }
window.Hydro.components.downloadProblemSet = downloadProblemSet; window.Hydro.components.downloadProblemSet = downloadProblemSet;
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.11.22", "version": "4.11.23",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",
@@ -196,7 +196,7 @@ async function handleDownload(ev) {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
if (ev.shiftKey) name = prompt('Filename:', name); if (ev.shiftKey) name = prompt('Filename:', name);
const pids = ensureAndGetSelectedPids(); const pids = ensureAndGetSelectedPids();
await downloadProblemSet(pids, name); if (pids) await downloadProblemSet(pids, name);
} }
const page = new NamedPage(['problem_main', 'problem_category'], () => { const page = new NamedPage(['problem_main', 'problem_category'], () => {