mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: remove pdoc.config (use config.yaml instead)
This commit is contained in:
1 parent
6fbb7588e1
commit
d1e119fe7f
7 files changed
+53
-29
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.15.32",
|
"version": "2.16.0",
|
||||||
"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",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import superagent from 'superagent';
|
|||||||
import { filter } from 'lodash';
|
import { filter } from 'lodash';
|
||||||
import { PassThrough } from 'stream';
|
import { PassThrough } from 'stream';
|
||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
import { ValidationError, RemoteOnlineJudgeError } from '../error';
|
import { ValidationError, RemoteOnlineJudgeError } from '../error';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import type { ContentNode } from '../interface';
|
import type { ContentNode } from '../interface';
|
||||||
@@ -115,14 +116,13 @@ class ProblemImportSYZOJHandler extends Handler {
|
|||||||
await problem.addTestdata(domainId, docId, entry.entryName, entry.getData());
|
await problem.addTestdata(domainId, docId, entry.entryName, entry.getData());
|
||||||
}
|
}
|
||||||
const filename = p.file_io_input_name ? p.file_io_input_name?.split('.')[0] : null;
|
const filename = p.file_io_input_name ? p.file_io_input_name?.split('.')[0] : null;
|
||||||
await problem.edit(domainId, docId, {
|
const config = {
|
||||||
config: {
|
time: `${p.time_limit}ms`,
|
||||||
time: `${p.time_limit}ms`,
|
memory: `${p.memory_limit}m`,
|
||||||
memory: `${p.memory_limit}m`,
|
filename,
|
||||||
filename,
|
type: p.type === 'traditional' ? 'default' : p.type,
|
||||||
type: p.type === 'traditional' ? 'default' : p.type,
|
};
|
||||||
},
|
await problem.addTestdata(domainId, docId, 'config.yaml', Buffer.from(yaml.dump(config)));
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
fs.unlinkSync(file);
|
fs.unlinkSync(file);
|
||||||
}
|
}
|
||||||
@@ -188,13 +188,12 @@ class ProblemImportSYZOJHandler extends Handler {
|
|||||||
await problem.addTestdata(domainId, docId, f.filename, p);
|
await problem.addTestdata(domainId, docId, f.filename, p);
|
||||||
}
|
}
|
||||||
if (judge) {
|
if (judge) {
|
||||||
await problem.edit(domainId, docId, {
|
const config = {
|
||||||
config: {
|
time: `${judge.timeLimit}ms`,
|
||||||
time: `${judge.timeLimit}ms`,
|
memory: `${judge.memoryLimit}m`,
|
||||||
memory: `${judge.memoryLimit}m`,
|
// TODO other config
|
||||||
// TODO other config
|
};
|
||||||
},
|
await problem.addTestdata(domainId, docId, 'config.yaml', Buffer.from(yaml.dump(config)));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
const a = await superagent.post(`${protocol}://${host === 'loj.ac' ? 'api.loj.ac.cn' : host}/api/problem/downloadProblemFiles`)
|
const a = await superagent.post(`${protocol}://${host === 'loj.ac' ? 'api.loj.ac.cn' : host}/api/problem/downloadProblemFiles`)
|
||||||
.send({
|
.send({
|
||||||
|
|||||||
@@ -358,9 +358,6 @@ export class ProblemSettingsHandler extends ProblemManageHandler {
|
|||||||
[this.pdoc.title, 'problem_detail', { pid }, true],
|
[this.pdoc.title, 'problem_detail', { pid }, true],
|
||||||
['problem_settings', null],
|
['problem_settings', null],
|
||||||
];
|
];
|
||||||
if (this.response.body.pdoc.config) {
|
|
||||||
this.response.body.pdoc.config = yaml.dump(this.response.body.pdoc.config);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@param('pid', Types.String, null, parsePid)
|
@param('pid', Types.String, null, parsePid)
|
||||||
|
|||||||
@@ -174,7 +174,6 @@ declare module './model/problem' {
|
|||||||
category: string[],
|
category: string[],
|
||||||
data: ProblemData[],
|
data: ProblemData[],
|
||||||
hidden: boolean,
|
hidden: boolean,
|
||||||
config: ProblemConfig,
|
|
||||||
acMsg?: string,
|
acMsg?: string,
|
||||||
html?: boolean,
|
html?: boolean,
|
||||||
|
|
||||||
@@ -182,6 +181,11 @@ declare module './model/problem' {
|
|||||||
difficultyAlgo?: number,
|
difficultyAlgo?: number,
|
||||||
difficultyAdmin?: number,
|
difficultyAdmin?: number,
|
||||||
difficultySetting?: any,
|
difficultySetting?: any,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
config: any,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export type { Pdoc } from './model/problem';
|
export type { Pdoc } from './model/problem';
|
||||||
|
|||||||
@@ -73,12 +73,10 @@ export async function stat(domainId?: string) {
|
|||||||
|
|
||||||
export async function judge(domainId: string, rid: ObjectID, priority = 1) {
|
export async function judge(domainId: string, rid: ObjectID, priority = 1) {
|
||||||
const rdoc = await get(domainId, rid);
|
const rdoc = await get(domainId, rid);
|
||||||
let config: RunConfig | ProblemConfig = rdoc.config;
|
const config: RunConfig | ProblemConfig = rdoc.config || {};
|
||||||
let data = [];
|
let data = [];
|
||||||
if (rdoc.pid) {
|
if (rdoc.pid) {
|
||||||
const pdoc = await problem.get(domainId, rdoc.pid);
|
|
||||||
data = await storage.list(`problem/${domainId}/${rdoc.pid}/testdata/`, true);
|
data = await storage.list(`problem/${domainId}/${rdoc.pid}/testdata/`, true);
|
||||||
if (!config) config = pdoc?.config || {};
|
|
||||||
}
|
}
|
||||||
delete rdoc._id;
|
delete rdoc._id;
|
||||||
await task.add({
|
await task.add({
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ global.Hydro.model.token = {
|
|||||||
TYPE_OAUTH,
|
TYPE_OAUTH,
|
||||||
TYPE_REGISTRATION,
|
TYPE_REGISTRATION,
|
||||||
TYPE_LOSTPASS,
|
TYPE_LOSTPASS,
|
||||||
|
TYPE_EXPORT,
|
||||||
|
|
||||||
add,
|
add,
|
||||||
createOrUpdate,
|
createOrUpdate,
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
import { ObjectID, Collection } from 'mongodb';
|
import { ObjectID, Collection } from 'mongodb';
|
||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
import Queue from 'p-queue';
|
import Queue from 'p-queue';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
import { Progress } from './ui';
|
import { Progress } from './ui';
|
||||||
import { Ufdoc } from './interface';
|
import { Ufdoc } from './interface';
|
||||||
import { Logger } from './logger';
|
import { Logger } from './logger';
|
||||||
|
import { DomainDoc } from './loader';
|
||||||
import { streamToBuffer } from './utils';
|
import { streamToBuffer } from './utils';
|
||||||
import gridfs from './service/gridfs';
|
import gridfs from './service/gridfs';
|
||||||
import storage from './service/storage';
|
import storage from './service/storage';
|
||||||
@@ -19,6 +21,17 @@ import * as system from './model/system';
|
|||||||
const logger = new Logger('upgrade');
|
const logger = new Logger('upgrade');
|
||||||
type UpgradeScript = () => Promise<boolean | void>;
|
type UpgradeScript = () => Promise<boolean | void>;
|
||||||
|
|
||||||
|
async function iterateAllDomain(cb: (ddoc: DomainDoc) => Promise<any>) {
|
||||||
|
const domains = await domain.getMulti().project({ _id: 1 }).toArray();
|
||||||
|
for (const d of domains) await cb(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function iterateAllProblem(cb: (pdoc: problem.Pdoc) => Promise<any>) {
|
||||||
|
await iterateAllDomain(async (d) => {
|
||||||
|
await problem.getMulti(d._id, {}).forEach(cb);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const scripts: UpgradeScript[] = [
|
const scripts: UpgradeScript[] = [
|
||||||
// Init
|
// Init
|
||||||
async function _0_1() {
|
async function _0_1() {
|
||||||
@@ -30,8 +43,7 @@ const scripts: UpgradeScript[] = [
|
|||||||
// Add history column to ddoc,drdoc,psdoc
|
// Add history column to ddoc,drdoc,psdoc
|
||||||
async function _1_2() {
|
async function _1_2() {
|
||||||
const _FRESH_INSTALL_IGNORE = 1;
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
const domains = await domain.getMulti().project({ _id: 1 }).toArray();
|
await iterateAllDomain(async (d) => {
|
||||||
for (const d of domains) {
|
|
||||||
const bulk = document.coll.initializeUnorderedBulkOp();
|
const bulk = document.coll.initializeUnorderedBulkOp();
|
||||||
await document.getMulti(d._id, document.TYPE_DISCUSSION).forEach((ddoc) => {
|
await document.getMulti(d._id, document.TYPE_DISCUSSION).forEach((ddoc) => {
|
||||||
bulk.find({ _id: ddoc._id }).updateOne({ $set: { history: [] } });
|
bulk.find({ _id: ddoc._id }).updateOne({ $set: { history: [] } });
|
||||||
@@ -44,7 +56,7 @@ const scripts: UpgradeScript[] = [
|
|||||||
bulk.find({ _id: psdoc._id }).updateOne({ $set: { history: [] } });
|
bulk.find({ _id: psdoc._id }).updateOne({ $set: { history: [] } });
|
||||||
});
|
});
|
||||||
if (bulk.length) await bulk.execute();
|
if (bulk.length) await bulk.execute();
|
||||||
}
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
async function _2_3() {
|
async function _2_3() {
|
||||||
@@ -138,8 +150,7 @@ const scripts: UpgradeScript[] = [
|
|||||||
},
|
},
|
||||||
async function _4_5() {
|
async function _4_5() {
|
||||||
const _FRESH_INSTALL_IGNORE = 1;
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
const domains = await domain.getMulti().project({ _id: 1 }).toArray();
|
await iterateAllDomain(async (d) => {
|
||||||
for (const d of domains) {
|
|
||||||
const bulk = document.coll.initializeUnorderedBulkOp();
|
const bulk = document.coll.initializeUnorderedBulkOp();
|
||||||
const pdocs = await document.getMulti(d._id, document.TYPE_PROBLEM).project({ domainId: 1, docId: 1 }).toArray();
|
const pdocs = await document.getMulti(d._id, document.TYPE_PROBLEM).project({ domainId: 1, docId: 1 }).toArray();
|
||||||
for (const pdoc of pdocs) {
|
for (const pdoc of pdocs) {
|
||||||
@@ -147,13 +158,27 @@ const scripts: UpgradeScript[] = [
|
|||||||
bulk.find({ _id: pdoc._id }).updateOne({ $set: { data } });
|
bulk.find({ _id: pdoc._id }).updateOne({ $set: { data } });
|
||||||
}
|
}
|
||||||
if (bulk.length) await bulk.execute();
|
if (bulk.length) await bulk.execute();
|
||||||
}
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
async function _5_6() {
|
async function _5_6() {
|
||||||
// Issue #58
|
// Issue #58
|
||||||
const _FRESH_INSTALL_IGNORE = 1;
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
await domain.edit('system', { owner: 1 });
|
await domain.edit('system', { owner: 1 });
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
async function _6_7() {
|
||||||
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
|
await iterateAllProblem(async (pdoc) => {
|
||||||
|
if (!pdoc.config) return;
|
||||||
|
const dst = `problem/${pdoc.domainId}/${pdoc.pid}/testdata/config.yaml`;
|
||||||
|
await storage.get(dst)
|
||||||
|
.catch(() => {
|
||||||
|
const cfg = yaml.dump(pdoc.config);
|
||||||
|
return storage.put(dst, Buffer.from(cfg));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user