mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: update contentType for import
This commit is contained in:
1 parent
4904b16fa5
commit
e701807cbc
7 files changed
+23
-19
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.21.7",
|
"version": "2.21.8",
|
||||||
"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",
|
||||||
|
|||||||
@@ -74,14 +74,14 @@ export async function load(call: Entry) {
|
|||||||
const expected = scripts.length;
|
const expected = scripts.length;
|
||||||
while (dbVer < expected) {
|
while (dbVer < expected) {
|
||||||
logger.info('Upgrading database: from %d to %d', dbVer, expected);
|
logger.info('Upgrading database: from %d to %d', dbVer, expected);
|
||||||
|
const func = scripts[dbVer];
|
||||||
if (isFresh) {
|
if (isFresh) {
|
||||||
const func = scripts[dbVer].toString();
|
if (typeof func !== 'function' || func.toString().includes('_FRESH_INSTALL_IGNORE')) {
|
||||||
if (func.includes('_FRESH_INSTALL_IGNORE')) {
|
|
||||||
dbVer++;
|
dbVer++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const result = await scripts[dbVer]();
|
const result = await func();
|
||||||
if (!result) break;
|
if (!result) break;
|
||||||
dbVer++;
|
dbVer++;
|
||||||
await modelSystem.set('db.ver', dbVer);
|
await modelSystem.set('db.ver', dbVer);
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class ProblemImportSYZOJHandler extends Handler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const docId = await problem.add(
|
const docId = await problem.add(
|
||||||
domainId, target, p.title, content, this.user._id, p.tags || [], hidden,
|
domainId, target, p.title, JSON.stringify(content), this.user._id, p.tags || [], hidden,
|
||||||
);
|
);
|
||||||
const r = download(`${url}testdata/download`);
|
const r = download(`${url}testdata/download`);
|
||||||
const file = path.resolve(os.tmpdir(), 'hydro', `import_${domainId}_${docId}.zip`);
|
const file = path.resolve(os.tmpdir(), 'hydro', `import_${domainId}_${docId}.zip`);
|
||||||
@@ -172,7 +172,7 @@ class ProblemImportSYZOJHandler extends Handler {
|
|||||||
...result.body.localizedContentsOfAllLocales,
|
...result.body.localizedContentsOfAllLocales,
|
||||||
][0].title;
|
][0].title;
|
||||||
const docId = await problem.add(
|
const docId = await problem.add(
|
||||||
domainId, target, title, content, this.user._id, tags || [], hidden,
|
domainId, target, title, JSON.stringify(content), this.user._id, tags || [], hidden,
|
||||||
);
|
);
|
||||||
const syncFiles = async () => {
|
const syncFiles = async () => {
|
||||||
const judge = result.body.judgeInfo;
|
const judge = result.body.judgeInfo;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import * as document from './document';
|
|||||||
import domain from './domain';
|
import domain from './domain';
|
||||||
import { buildProjection } from '../utils';
|
import { buildProjection } from '../utils';
|
||||||
import type { ProblemStatusDoc, Pdict, Document } from '../interface';
|
import type { ProblemStatusDoc, Pdict, Document } from '../interface';
|
||||||
import { Content } from '../loader';
|
|
||||||
import { ArrayKeys, NumberKeys, Projection } from '../typeutils';
|
import { ArrayKeys, NumberKeys, Projection } from '../typeutils';
|
||||||
import { ProblemNotFoundError, ValidationError } from '../error';
|
import { ProblemNotFoundError, ValidationError } from '../error';
|
||||||
import storage from '../service/storage';
|
import storage from '../service/storage';
|
||||||
@@ -45,16 +44,24 @@ export class ProblemModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async add(
|
static async add(
|
||||||
domainId: string, pid: string = null, title: string, content: Content, owner: number,
|
domainId: string, pid: string = null, title: string, content: string, owner: number,
|
||||||
tag: string[] = [], hidden = false,
|
tag: string[] = [], hidden = false,
|
||||||
) {
|
) {
|
||||||
const pidCounter = await domain.inc(domainId, 'pidCounter', 1);
|
const pidCounter = await domain.inc(domainId, 'pidCounter', 1);
|
||||||
|
const result = await ProblemModel.addWithId(domainId, pidCounter, pid, title, content, owner, tag, hidden);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async addWithId(
|
||||||
|
domainId: string, docId: number, pid: string = null, title: string,
|
||||||
|
content: string, owner: number, tag: string[] = [], hidden = false,
|
||||||
|
) {
|
||||||
const args: Partial<Pdoc> = {
|
const args: Partial<Pdoc> = {
|
||||||
title, tag, hidden, nSubmit: 0, nAccept: 0,
|
title, tag, hidden, nSubmit: 0, nAccept: 0,
|
||||||
};
|
};
|
||||||
if (pid) args.pid = pid;
|
if (pid) args.pid = pid;
|
||||||
await bus.serial('problem/before-add', args);
|
await bus.serial('problem/before-add', args);
|
||||||
const result = await document.add(domainId, content, owner, document.TYPE_PROBLEM, pidCounter, null, null, args);
|
const result = await document.add(domainId, content, owner, document.TYPE_PROBLEM, docId, null, null, args);
|
||||||
await bus.emit('problem/add', args, result);
|
await bus.emit('problem/add', args, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import * as system from './model/system';
|
|||||||
import difficultyAlgorithm from './lib/difficulty';
|
import difficultyAlgorithm from './lib/difficulty';
|
||||||
|
|
||||||
const logger = new Logger('upgrade');
|
const logger = new Logger('upgrade');
|
||||||
type UpgradeScript = () => Promise<boolean | void>;
|
type UpgradeScript = void | (() => Promise<boolean | void>);
|
||||||
|
|
||||||
export async function iterateAllDomain(cb: (ddoc: DomainDoc, current?: number, total?: number) => Promise<any>) {
|
export async function iterateAllDomain(cb: (ddoc: DomainDoc, current?: number, total?: number) => Promise<any>) {
|
||||||
const ddocs = await domain.getMulti().project({ _id: 1, owner: 1 }).toArray();
|
const ddocs = await domain.getMulti().project({ _id: 1, owner: 1 }).toArray();
|
||||||
@@ -58,9 +58,7 @@ export async function iterateAllProblem(
|
|||||||
|
|
||||||
const scripts: UpgradeScript[] = [
|
const scripts: UpgradeScript[] = [
|
||||||
// Mark as used
|
// Mark as used
|
||||||
async function _0_1() {
|
null,
|
||||||
return true;
|
|
||||||
},
|
|
||||||
// Init
|
// Init
|
||||||
async function _1_2() {
|
async function _1_2() {
|
||||||
const ddoc = await domain.get('system');
|
const ddoc = await domain.get('system');
|
||||||
@@ -253,10 +251,9 @@ const scripts: UpgradeScript[] = [
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
async function _16_17() {
|
null,
|
||||||
return true;
|
null,
|
||||||
},
|
async function _18_19() {
|
||||||
async function _17_18() {
|
|
||||||
const _FRESH_INSTALL_IGNORE = 1;
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
await iterateAllProblem(['content'], async (pdoc) => {
|
await iterateAllProblem(['content'], async (pdoc) => {
|
||||||
if (typeof pdoc.content !== 'string') {
|
if (typeof pdoc.content !== 'string') {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class ImportQduojHandler extends Handler {
|
|||||||
if (+pdoc.display_id) pdoc.display_id = `P${pdoc.display_id}`;
|
if (+pdoc.display_id) pdoc.display_id = `P${pdoc.display_id}`;
|
||||||
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, content, this.user._id, pdoc.tags);
|
const pid = await problem.add(domainId, pdoc.display_id, pdoc.title, JSON.stringify(content), this.user._id, pdoc.tags);
|
||||||
const config: ProblemConfig = {
|
const config: ProblemConfig = {
|
||||||
time: `${pdoc.time_limit}ms`,
|
time: `${pdoc.time_limit}ms`,
|
||||||
memory: `${pdoc.memory_limit}m`,
|
memory: `${pdoc.memory_limit}m`,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/import-qduoj",
|
"name": "@hydrooj/import-qduoj",
|
||||||
"version": "1.1.5",
|
"version": "1.1.6",
|
||||||
"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",
|
||||||
|
|||||||
Reference in new issue
Block a user