mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: 支持自定义导出文件名
This commit is contained in:
1 parent
cdbbee8180
commit
0273bfe198
13 files changed
+50
-32
No files matched your search
@@ -11,7 +11,7 @@ import solution from 'hydrooj/dist/model/solution';
|
|||||||
import problem from 'hydrooj/dist/model/problem';
|
import problem from 'hydrooj/dist/model/problem';
|
||||||
import { PERM } from 'hydrooj/dist/model/builtin';
|
import { PERM } from 'hydrooj/dist/model/builtin';
|
||||||
import { FileTooLargeError, ValidationError } from 'hydrooj/dist/error';
|
import { FileTooLargeError, ValidationError } from 'hydrooj/dist/error';
|
||||||
import type { ProblemConfig } from 'hydrooj';
|
import type { ProblemConfigFile } from 'hydrooj';
|
||||||
|
|
||||||
class FpsProblemImportHandler extends Handler {
|
class FpsProblemImportHandler extends Handler {
|
||||||
async get() {
|
async get() {
|
||||||
@@ -29,7 +29,7 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
: [],
|
: [],
|
||||||
hint: p.hint,
|
hint: p.hint,
|
||||||
}, 'html', this.translate.bind(this));
|
}, 'html', this.translate.bind(this));
|
||||||
const config: ProblemConfig = {
|
const config: ProblemConfigFile = {
|
||||||
time: p.time_limit[0]._ + p.time_limit[0].$.unit,
|
time: p.time_limit[0]._ + p.time_limit[0].$.unit,
|
||||||
memory: p.memory_limit[0]._ + p.memory_limit[0].$.unit,
|
memory: p.memory_limit[0]._ + p.memory_limit[0].$.unit,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/fps-importer",
|
"name": "@hydrooj/fps-importer",
|
||||||
"version": "1.1.13",
|
"version": "1.2.0",
|
||||||
"description": "Import FPS problems",
|
"description": "Import FPS problems",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.27.6",
|
"version": "2.27.7",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ export interface SubtaskConfig {
|
|||||||
cases?: TestCaseConfig[],
|
cases?: TestCaseConfig[],
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProblemConfig {
|
export interface ProblemConfigFile {
|
||||||
type?: ProblemType;
|
type?: ProblemType;
|
||||||
score?: number;
|
score?: number;
|
||||||
time?: string;
|
time?: string;
|
||||||
@@ -159,6 +159,16 @@ export interface ProblemConfig {
|
|||||||
langs?: string[];
|
langs?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ProblemConfig {
|
||||||
|
count: number;
|
||||||
|
memoryMax: number;
|
||||||
|
memoryMin: number;
|
||||||
|
timeMax: number;
|
||||||
|
timeMin: number;
|
||||||
|
langs?: string[];
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface PlainContentNode {
|
export interface PlainContentNode {
|
||||||
type: 'Plain',
|
type: 'Plain',
|
||||||
subType: 'html' | 'markdown',
|
subType: 'html' | 'markdown',
|
||||||
|
|||||||
@@ -1,24 +1,14 @@
|
|||||||
import readYamlCases from '@hydrooj/utils/lib/cases';
|
import readYamlCases from '@hydrooj/utils/lib/cases';
|
||||||
import { load } from 'js-yaml';
|
import { load } from 'js-yaml';
|
||||||
import type { ProblemConfig } from '../interface';
|
import type { ProblemConfig, ProblemConfigFile } from '../interface';
|
||||||
|
|
||||||
interface ParseResult {
|
export async function parseConfig(config: string | ProblemConfigFile = {}) {
|
||||||
count: number;
|
let cfg: ProblemConfigFile = {};
|
||||||
memoryMax: number;
|
|
||||||
memoryMin: number;
|
|
||||||
timeMax: number;
|
|
||||||
timeMin: number;
|
|
||||||
langs?: string[];
|
|
||||||
type: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function parseConfig(config: string | ProblemConfig = {}) {
|
|
||||||
let cfg: ProblemConfig = {};
|
|
||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
// TODO should validate here?
|
// TODO should validate here?
|
||||||
cfg = await readYamlCases(load(config) as Record<string, any>);
|
cfg = await readYamlCases(load(config) as Record<string, any>);
|
||||||
} else if (typeof config === 'object') cfg = await readYamlCases(config);
|
} else if (typeof config === 'object') cfg = await readYamlCases(config);
|
||||||
const result: ParseResult = {
|
const result: ProblemConfig = {
|
||||||
count: 0,
|
count: 0,
|
||||||
memoryMin: Number.MAX_SAFE_INTEGER,
|
memoryMin: Number.MAX_SAFE_INTEGER,
|
||||||
memoryMax: 0,
|
memoryMax: 0,
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ export class ProblemModel {
|
|||||||
for (const pdoc of pdocs) {
|
for (const pdoc of pdocs) {
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
pdoc.config = await parseConfig(pdoc.config);
|
pdoc.config = await parseConfig(pdoc.config as string);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
pdoc.config = `Cannot parse: ${e.message}`;
|
pdoc.config = `Cannot parse: ${e.message}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import moment from 'moment';
|
|||||||
import { STATUS } from './builtin';
|
import { STATUS } from './builtin';
|
||||||
import task from './task';
|
import task from './task';
|
||||||
import problem from './problem';
|
import problem from './problem';
|
||||||
import { RecordDoc, ContestInfo, ProblemConfig } from '../interface';
|
import { RecordDoc, ContestInfo, ProblemConfigFile } from '../interface';
|
||||||
import { ArgMethod, buildProjection, Time } from '../utils';
|
import { ArgMethod, buildProjection, Time } from '../utils';
|
||||||
import { MaybeArray } from '../typeutils';
|
import { MaybeArray } from '../typeutils';
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
@@ -51,7 +51,7 @@ class RecordModel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static async judge(domainId: string, rid: ObjectID, priority = 0, config: ProblemConfig = {}) {
|
static async judge(domainId: string, rid: ObjectID, priority = 0, config: ProblemConfigFile = {}) {
|
||||||
const rdoc = await RecordModel.get(domainId, rid);
|
const rdoc = await RecordModel.get(domainId, rid);
|
||||||
let data = [];
|
let data = [];
|
||||||
if (rdoc.pid) {
|
if (rdoc.pid) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
|||||||
import problem from 'hydrooj/dist/model/problem';
|
import problem from 'hydrooj/dist/model/problem';
|
||||||
import { PERM } from 'hydrooj/dist/model/builtin';
|
import { PERM } from 'hydrooj/dist/model/builtin';
|
||||||
import { buildContent } from 'hydrooj/dist/lib/content';
|
import { buildContent } from 'hydrooj/dist/lib/content';
|
||||||
import type { ContentNode, ProblemConfig } from 'hydrooj';
|
import type { ContentNode, ProblemConfigFile } from 'hydrooj';
|
||||||
|
|
||||||
fs.ensureDirSync('/tmp/hydro/import-qduoj');
|
fs.ensureDirSync('/tmp/hydro/import-qduoj');
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ class ImportQduojHandler extends Handler {
|
|||||||
const n = await problem.get(domainId, pdoc.display_id);
|
const n = await problem.get(domainId, pdoc.display_id);
|
||||||
if (n) pdoc.display_id = null;
|
if (n) pdoc.display_id = null;
|
||||||
const pid = await problem.add(domainId, pdoc.display_id, pdoc.title, buildContent(content, 'html'), this.user._id, pdoc.tags);
|
const pid = await problem.add(domainId, pdoc.display_id, pdoc.title, buildContent(content, 'html'), this.user._id, pdoc.tags);
|
||||||
const config: ProblemConfig = {
|
const config: ProblemConfigFile = {
|
||||||
time: `${pdoc.time_limit}ms`,
|
time: `${pdoc.time_limit}ms`,
|
||||||
memory: `${pdoc.memory_limit}m`,
|
memory: `${pdoc.memory_limit}m`,
|
||||||
subtasks: [],
|
subtasks: [],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/import-qduoj",
|
"name": "@hydrooj/import-qduoj",
|
||||||
"version": "1.1.9",
|
"version": "1.2.0",
|
||||||
"description": "Import QDUOJ problem export",
|
"description": "Import QDUOJ problem export",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import pipeStream from 'vj/utils/pipeStream';
|
|||||||
import i18n from 'vj/utils/i18n';
|
import i18n from 'vj/utils/i18n';
|
||||||
import request from 'vj/utils/request';
|
import request from 'vj/utils/request';
|
||||||
import Notification from 'vj/components/notification';
|
import Notification from 'vj/components/notification';
|
||||||
|
import { pick } from 'lodash';
|
||||||
|
|
||||||
let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext;
|
let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext;
|
||||||
function onBeforeUnload(e) {
|
function onBeforeUnload(e) {
|
||||||
@@ -62,11 +63,25 @@ export default async function download(name, targets) {
|
|||||||
window.removeEventListener('beforeunload', onBeforeUnload);
|
window.removeEventListener('beforeunload', onBeforeUnload);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadProblemSet(pids) {
|
export async function downloadProblemSet(pids, name = 'Export') {
|
||||||
|
Notification.info('Downloading...');
|
||||||
const targets = [];
|
const targets = [];
|
||||||
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({ 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(
|
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' }
|
||||||
@@ -81,5 +96,5 @@ export async function downloadProblemSet(pids) {
|
|||||||
targets.push({ filename: `${pid}/additional_file/${filename}`, url: links[filename] });
|
targets.push({ filename: `${pid}/additional_file/${filename}`, url: links[filename] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await download('Export.zip', targets);
|
await download(`${name}.zip`, targets);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.10.7",
|
"version": "4.10.8",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
|
|||||||
const extender = new ProblemPageExtender();
|
const extender = new ProblemPageExtender();
|
||||||
|
|
||||||
async function handleClickDownloadProblem() {
|
async function handleClickDownloadProblem() {
|
||||||
await downloadProblemSet([UiContext.problemNumId]);
|
await downloadProblemSet([UiContext.problemNumId], UiContext.pdoc.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function scratchpadFadeIn() {
|
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();
|
const pids = ensureAndGetSelectedPids();
|
||||||
await downloadProblemSet(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