core: remove pdoc.config (use config.yaml instead)

This commit is contained in:
undefined committed 2021-01-24 11:57:51 +08:00
1 parent 6fbb7588e1
commit d1e119fe7f
7 files changed
+53 -29

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.15.32",
"version": "2.16.0",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+14 -15
View File
@@ -6,6 +6,7 @@ import superagent from 'superagent';
import { filter } from 'lodash';
import { PassThrough } from 'stream';
import AdmZip from 'adm-zip';
import yaml from 'js-yaml';
import { ValidationError, RemoteOnlineJudgeError } from '../error';
import { Logger } from '../logger';
import type { ContentNode } from '../interface';
@@ -115,14 +116,13 @@ class ProblemImportSYZOJHandler extends Handler {
await problem.addTestdata(domainId, docId, entry.entryName, entry.getData());
}
const filename = p.file_io_input_name ? p.file_io_input_name?.split('.')[0] : null;
await problem.edit(domainId, docId, {
config: {
time: `${p.time_limit}ms`,
memory: `${p.memory_limit}m`,
filename,
type: p.type === 'traditional' ? 'default' : p.type,
},
});
const config = {
time: `${p.time_limit}ms`,
memory: `${p.memory_limit}m`,
filename,
type: p.type === 'traditional' ? 'default' : p.type,
};
await problem.addTestdata(domainId, docId, 'config.yaml', Buffer.from(yaml.dump(config)));
} finally {
fs.unlinkSync(file);
}
@@ -188,13 +188,12 @@ class ProblemImportSYZOJHandler extends Handler {
await problem.addTestdata(domainId, docId, f.filename, p);
}
if (judge) {
await problem.edit(domainId, docId, {
config: {
time: `${judge.timeLimit}ms`,
memory: `${judge.memoryLimit}m`,
// TODO other config
},
});
const config = {
time: `${judge.timeLimit}ms`,
memory: `${judge.memoryLimit}m`,
// 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`)
.send({
-3
View File
@@ -358,9 +358,6 @@ export class ProblemSettingsHandler extends ProblemManageHandler {
[this.pdoc.title, 'problem_detail', { pid }, true],
['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)
+5 -1
View File
@@ -174,7 +174,6 @@ declare module './model/problem' {
category: string[],
data: ProblemData[],
hidden: boolean,
config: ProblemConfig,
acMsg?: string,
html?: boolean,
@@ -182,6 +181,11 @@ declare module './model/problem' {
difficultyAlgo?: number,
difficultyAdmin?: number,
difficultySetting?: any,
/**
* @deprecated
*/
config: any,
}
}
export type { Pdoc } from './model/problem';
+1 -3
View File
@@ -73,12 +73,10 @@ export async function stat(domainId?: string) {
export async function judge(domainId: string, rid: ObjectID, priority = 1) {
const rdoc = await get(domainId, rid);
let config: RunConfig | ProblemConfig = rdoc.config;
const config: RunConfig | ProblemConfig = rdoc.config || {};
let data = [];
if (rdoc.pid) {
const pdoc = await problem.get(domainId, rdoc.pid);
data = await storage.list(`problem/${domainId}/${rdoc.pid}/testdata/`, true);
if (!config) config = pdoc?.config || {};
}
delete rdoc._id;
await task.add({
+1
View File
@@ -97,6 +97,7 @@ global.Hydro.model.token = {
TYPE_OAUTH,
TYPE_REGISTRATION,
TYPE_LOSTPASS,
TYPE_EXPORT,
add,
createOrUpdate,
+31 -6
View File
@@ -3,9 +3,11 @@
import { ObjectID, Collection } from 'mongodb';
import AdmZip from 'adm-zip';
import Queue from 'p-queue';
import yaml from 'js-yaml';
import { Progress } from './ui';
import { Ufdoc } from './interface';
import { Logger } from './logger';
import { DomainDoc } from './loader';
import { streamToBuffer } from './utils';
import gridfs from './service/gridfs';
import storage from './service/storage';
@@ -19,6 +21,17 @@ import * as system from './model/system';
const logger = new Logger('upgrade');
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[] = [
// Init
async function _0_1() {
@@ -30,8 +43,7 @@ const scripts: UpgradeScript[] = [
// Add history column to ddoc,drdoc,psdoc
async function _1_2() {
const _FRESH_INSTALL_IGNORE = 1;
const domains = await domain.getMulti().project({ _id: 1 }).toArray();
for (const d of domains) {
await iterateAllDomain(async (d) => {
const bulk = document.coll.initializeUnorderedBulkOp();
await document.getMulti(d._id, document.TYPE_DISCUSSION).forEach((ddoc) => {
bulk.find({ _id: ddoc._id }).updateOne({ $set: { history: [] } });
@@ -44,7 +56,7 @@ const scripts: UpgradeScript[] = [
bulk.find({ _id: psdoc._id }).updateOne({ $set: { history: [] } });
});
if (bulk.length) await bulk.execute();
}
});
return true;
},
async function _2_3() {
@@ -138,8 +150,7 @@ const scripts: UpgradeScript[] = [
},
async function _4_5() {
const _FRESH_INSTALL_IGNORE = 1;
const domains = await domain.getMulti().project({ _id: 1 }).toArray();
for (const d of domains) {
await iterateAllDomain(async (d) => {
const bulk = document.coll.initializeUnorderedBulkOp();
const pdocs = await document.getMulti(d._id, document.TYPE_PROBLEM).project({ domainId: 1, docId: 1 }).toArray();
for (const pdoc of pdocs) {
@@ -147,13 +158,27 @@ const scripts: UpgradeScript[] = [
bulk.find({ _id: pdoc._id }).updateOne({ $set: { data } });
}
if (bulk.length) await bulk.execute();
}
});
return true;
},
async function _5_6() {
// Issue #58
const _FRESH_INSTALL_IGNORE = 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;
},
];