core: update contentType for import

This commit is contained in:
undefined committed 2021-04-06 12:01:26 +08:00
1 parent 4904b16fa5
commit e701807cbc
7 files changed
+23 -19

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.21.7",
"version": "2.21.8",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+3 -3
View File
@@ -74,14 +74,14 @@ export async function load(call: Entry) {
const expected = scripts.length;
while (dbVer < expected) {
logger.info('Upgrading database: from %d to %d', dbVer, expected);
const func = scripts[dbVer];
if (isFresh) {
const func = scripts[dbVer].toString();
if (func.includes('_FRESH_INSTALL_IGNORE')) {
if (typeof func !== 'function' || func.toString().includes('_FRESH_INSTALL_IGNORE')) {
dbVer++;
continue;
}
}
const result = await scripts[dbVer]();
const result = await func();
if (!result) break;
dbVer++;
await modelSystem.set('db.ver', dbVer);
+2 -2
View File
@@ -96,7 +96,7 @@ class ProblemImportSYZOJHandler extends Handler {
});
}
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 file = path.resolve(os.tmpdir(), 'hydro', `import_${domainId}_${docId}.zip`);
@@ -172,7 +172,7 @@ class ProblemImportSYZOJHandler extends Handler {
...result.body.localizedContentsOfAllLocales,
][0].title;
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 judge = result.body.judgeInfo;
+10 -3
View File
@@ -6,7 +6,6 @@ import * as document from './document';
import domain from './domain';
import { buildProjection } from '../utils';
import type { ProblemStatusDoc, Pdict, Document } from '../interface';
import { Content } from '../loader';
import { ArrayKeys, NumberKeys, Projection } from '../typeutils';
import { ProblemNotFoundError, ValidationError } from '../error';
import storage from '../service/storage';
@@ -45,16 +44,24 @@ export class ProblemModel {
}
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,
) {
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> = {
title, tag, hidden, nSubmit: 0, nAccept: 0,
};
if (pid) args.pid = pid;
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);
return result;
}
+5 -8
View File
@@ -18,7 +18,7 @@ import * as system from './model/system';
import difficultyAlgorithm from './lib/difficulty';
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>) {
const ddocs = await domain.getMulti().project({ _id: 1, owner: 1 }).toArray();
@@ -58,9 +58,7 @@ export async function iterateAllProblem(
const scripts: UpgradeScript[] = [
// Mark as used
async function _0_1() {
return true;
},
null,
// Init
async function _1_2() {
const ddoc = await domain.get('system');
@@ -253,10 +251,9 @@ const scripts: UpgradeScript[] = [
});
return true;
},
async function _16_17() {
return true;
},
async function _17_18() {
null,
null,
async function _18_19() {
const _FRESH_INSTALL_IGNORE = 1;
await iterateAllProblem(['content'], async (pdoc) => {
if (typeof pdoc.content !== 'string') {
+1 -1
View File
@@ -76,7 +76,7 @@ class ImportQduojHandler extends Handler {
if (+pdoc.display_id) pdoc.display_id = `P${pdoc.display_id}`;
const n = await problem.get(domainId, pdoc.display_id);
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 = {
time: `${pdoc.time_limit}ms`,
memory: `${pdoc.memory_limit}m`,
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/import-qduoj",
"version": "1.1.5",
"version": "1.1.6",
"description": "Import QDUOJ problem export",
"main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git",