ui: ignore download if no problem selected

pull/156/head
undefined 3 years ago
parent f95e5452f7
commit fec85985ef

@ -66,40 +66,42 @@ export default async function download(name, targets) {
export async function downloadProblemSet(pids, name = 'Export') {
Notification.info('Downloading...');
const targets = [];
for (const pid of pids) {
const { pdoc } = await request.get(`/d/${UiContext.domainId}/p/${pid}`);
targets.push({
filename: `${pid}/problem.yaml`,
content: dump({
pid: pdoc.pid,
content: pdoc.content,
owner: pdoc.owner,
title: pdoc.title,
tag: pdoc.tag,
nSubmit: pdoc.nSubmit,
nAccept: pdoc.nAccept,
data: (pdoc.data || []).map((i) => pick(i, ['name'])),
additional_file: (pdoc.additional_file || []).map((i) => pick(i, ['name'])),
difficulty: pdoc.difficulty,
}),
});
let { links } = await request.post(
`/d/${UiContext.domainId}/p/${pid}/files`,
{ operation: 'get_links', files: (pdoc.data || []).map((i) => i.name), type: 'testdata' }
).catch((e) => {
Notification.warn(`${e.error.message} ${e.error.params[0]}`);
});
for (const filename of Object.keys(links)) {
targets.push({ filename: `${pid}/testdata/${filename}`, url: links[filename] });
}
({ links } = await request.post(`/d/${UiContext.domainId}/p/${pid}/files`, {
operation: 'get_links', files: (pdoc.additional_file || []).map((i) => i.name), type: 'additional_file',
}));
for (const filename of Object.keys(links)) {
targets.push({ filename: `${pid}/additional_file/${filename}`, url: links[filename] });
try {
for (const pid of pids) {
const { pdoc } = await request.get(`/d/${UiContext.domainId}/p/${pid}`);
targets.push({
filename: `${pid}/problem.yaml`,
content: dump({
pid: pdoc.pid,
content: pdoc.content,
owner: pdoc.owner,
title: pdoc.title,
tag: pdoc.tag,
nSubmit: pdoc.nSubmit,
nAccept: pdoc.nAccept,
data: (pdoc.data || []).map((i) => pick(i, ['name'])),
additional_file: (pdoc.additional_file || []).map((i) => pick(i, ['name'])),
difficulty: pdoc.difficulty,
}),
});
let { links } = await request.post(
`/d/${UiContext.domainId}/p/${pid}/files`,
{ operation: 'get_links', files: (pdoc.data || []).map((i) => i.name), type: 'testdata' }
);
for (const filename of Object.keys(links)) {
targets.push({ filename: `${pid}/testdata/${filename}`, url: links[filename] });
}
({ links } = await request.post(`/d/${UiContext.domainId}/p/${pid}/files`, {
operation: 'get_links', files: (pdoc.additional_file || []).map((i) => i.name), type: 'additional_file',
}));
for (const filename of Object.keys(links)) {
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;

@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.11.22",
"version": "4.11.23",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",

@ -196,7 +196,7 @@ async function handleDownload(ev) {
// eslint-disable-next-line no-alert
if (ev.shiftKey) name = prompt('Filename:', name);
const pids = ensureAndGetSelectedPids();
await downloadProblemSet(pids, name);
if (pids) await downloadProblemSet(pids, name);
}
const page = new NamedPage(['problem_main', 'problem_category'], () => {

Loading…
Cancel
Save