mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: ignore download if no problem selected
This commit is contained in:
1 parent
f95e5452f7
commit
fec85985ef
3 files changed
+7
-5
No files matched your search
@@ -66,6 +66,7 @@ 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 = [];
|
||||||
|
try {
|
||||||
for (const pid of pids) {
|
for (const pid of pids) {
|
||||||
const { pdoc } = await request.get(`/d/${UiContext.domainId}/p/${pid}`);
|
const { pdoc } = await request.get(`/d/${UiContext.domainId}/p/${pid}`);
|
||||||
targets.push({
|
targets.push({
|
||||||
@@ -86,9 +87,7 @@ export async function downloadProblemSet(pids, name = 'Export') {
|
|||||||
let { links } = await request.post(
|
let { links } = await request.post(
|
||||||
`/d/${UiContext.domainId}/p/${pid}/files`,
|
`/d/${UiContext.domainId}/p/${pid}/files`,
|
||||||
{ operation: 'get_links', files: (pdoc.data || []).map((i) => i.name), type: 'testdata' }
|
{ 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)) {
|
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] });
|
||||||
}
|
}
|
||||||
@@ -100,6 +99,9 @@ export async function downloadProblemSet(pids, name = 'Export') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
await download(`${name}.zip`, targets);
|
await download(`${name}.zip`, targets);
|
||||||
|
} catch (e) {
|
||||||
|
Notification.warn(`${e.error.message} ${e.error.params[0]}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.Hydro.components.downloadProblemSet = downloadProblemSet;
|
window.Hydro.components.downloadProblemSet = downloadProblemSet;
|
||||||
|
|||||||
@@ -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'], () => {
|
||||||
|
|||||||
Reference in new issue
Block a user