ui: 支持自定义导出文件名

This commit is contained in:
undefined committed 2021-05-27 23:16:18 +08:00
1 parent cdbbee8180
commit 0273bfe198
13 files changed
+50 -32

No files matched your search

@@ -5,6 +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 { pick } from 'lodash';
let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext;
function onBeforeUnload(e) {
@@ -62,11 +63,25 @@ export default async function download(name, targets) {
window.removeEventListener('beforeunload', onBeforeUnload);
}
export async function downloadProblemSet(pids) {
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(pdoc) });
targets.push({
filename: `${pid}/problem.yaml`,
content: dump({
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', 'lastModified', 'etag', 'size', '_id'])),
additional_file: pdoc.additional_file.map((i) => pick(i, ['name', 'lastModified', 'etag', 'size', '_id'])),
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' }
@@ -81,5 +96,5 @@ export async function downloadProblemSet(pids) {
targets.push({ filename: `${pid}/additional_file/${filename}`, url: links[filename] });
}
}
await download('Export.zip', targets);
await download(`${name}.zip`, targets);
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.10.7",
"version": "4.10.8",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",
@@ -104,7 +104,7 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
const extender = new ProblemPageExtender();
async function handleClickDownloadProblem() {
await downloadProblemSet([UiContext.problemNumId]);
await downloadProblemSet([UiContext.problemNumId], UiContext.pdoc.title);
}
async function scratchpadFadeIn() {
@@ -202,9 +202,12 @@ async function handleOperation(operation) {
}
}
async function handleDownload() {
async function handleDownload(ev) {
let name = 'Export';
// eslint-disable-next-line no-alert
if (ev.shiftKey) name = prompt('Filename:', name);
const pids = ensureAndGetSelectedPids();
await downloadProblemSet(pids);
await downloadProblemSet(pids, name);
}
const page = new NamedPage(['problem_main', 'problem_category'], () => {