core: 支持修改tags & workspace: upgrade to js-yaml@4

This commit is contained in:
undefined committed 2021-01-09 23:58:06 +08:00
1 parent 87a4bc8bfa
commit 3d9acf2c1a
18 files changed
+38 -36

No files matched your search

+4 -4
View File
@@ -20,17 +20,17 @@
"devDependencies": { "devDependencies": {
"@shelf/jest-mongodb": "^1.2.3", "@shelf/jest-mongodb": "^1.2.3",
"@types/cross-spawn": "^6.0.2", "@types/cross-spawn": "^6.0.2",
"@types/jest": "^26.0.19", "@types/jest": "^26.0.20",
"@types/node": "^14.14.16", "@types/node": "^14.14.20",
"@types/semver": "^7.3.4", "@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^3.9.1", "@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.9.1", "@typescript-eslint/parser": "^3.9.1",
"cross-spawn": "^7.0.3", "cross-spawn": "^7.0.3",
"eslint": "^7.16.0", "eslint": "^7.17.0",
"eslint-config-airbnb-base": "^14.2.1", "eslint-config-airbnb-base": "^14.2.1",
"eslint-import-resolver-typescript": "^2.3.0", "eslint-import-resolver-typescript": "^2.3.0",
"eslint-plugin-import": "^2.22.1", "eslint-plugin-import": "^2.22.1",
"globby": "^11.0.1", "globby": "^11.0.2",
"jest": "^26.6.3", "jest": "^26.6.3",
"latest-version": "^5.1.0", "latest-version": "^5.1.0",
"ora": "^5.2.0", "ora": "^5.2.0",
+3 -3
View File
@@ -10,11 +10,11 @@
"axios": "^0.21.1", "axios": "^0.21.1",
"bson": "^4.2.2", "bson": "^4.2.2",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"js-yaml": "^3.14.1", "js-yaml": "^4.0.0",
"lodash": "^4.17.20", "lodash": "^4.17.20",
"p-queue": "^6.6.1", "p-queue": "^6.6.1",
"shell-quote": "^1.7.2", "shell-quote": "^1.7.2",
"systeminformation": "^4.33.4", "systeminformation": "^4.34.5",
"yargs": "^16.2.0" "yargs": "^16.2.0"
}, },
"peerDependencies": { "peerDependencies": {
@@ -24,7 +24,7 @@
"devDependencies": { "devDependencies": {
"@types/bson": "^4.0.2", "@types/bson": "^4.0.2",
"@types/fs-extra": "^9.0.6", "@types/fs-extra": "^9.0.6",
"@types/js-yaml": "^3.12.5", "@types/js-yaml": "^4.0.0",
"@types/shell-quote": "^1.7.0" "@types/shell-quote": "^1.7.0"
}, },
"scripts": { "scripts": {
+1 -1
View File
@@ -299,7 +299,7 @@ export default async function readCases(folder: string, cfg: Record<string, any>
const yamlConfig = path.resolve(folder, 'config.yaml'); const yamlConfig = path.resolve(folder, 'config.yaml');
let config; let config;
if (fs.existsSync(yamlConfig)) { if (fs.existsSync(yamlConfig)) {
config = { ...yaml.safeLoad(fs.readFileSync(yamlConfig).toString()) as object, ...cfg }; config = { ...yaml.load(fs.readFileSync(yamlConfig).toString()) as object, ...cfg };
} else if (fs.existsSync(iniConfig)) { } else if (fs.existsSync(iniConfig)) {
config = { ...convertIniConfig(fs.readFileSync(iniConfig).toString()), ...cfg }; config = { ...convertIniConfig(fs.readFileSync(iniConfig).toString()), ...cfg };
} else config = cfg; } else config = cfg;
+1 -1
View File
@@ -9,7 +9,7 @@ export = async function compile(
lang: string, code: string, target: string, copyIn: any, next?: Function, lang: string, code: string, target: string, copyIn: any, next?: Function,
): Promise<Execute> { ): Promise<Execute> {
const LANGS = global.Hydro const LANGS = global.Hydro
? yaml.safeLoad(await global.Hydro.model.system.get('hydrojudge.langs')) ? yaml.load(global.Hydro.model.system.get('hydrojudge.langs'))
: require('./config').LANGS; : require('./config').LANGS;
if (!LANGS[lang]) throw new SystemError('Unsupported language {0}.', [lang]); if (!LANGS[lang]) throw new SystemError('Unsupported language {0}.', [lang]);
const info = LANGS[lang]; const info = LANGS[lang];
+3 -3
View File
@@ -47,12 +47,12 @@ if (process.env.EXECUTION_HOST || argv.execute) {
EXECUTION_HOST = path.resolve(process.env.EXECUTION_HOST || argv.execute as string); EXECUTION_HOST = path.resolve(process.env.EXECUTION_HOST || argv.execute as string);
} }
if (!global.Hydro) { if (!global.Hydro) {
if (fs.existsSync(LANGS_FILE)) LANGS = yaml.safeLoad(fs.readFileSync(LANGS_FILE).toString()); if (fs.existsSync(LANGS_FILE)) LANGS = yaml.load(fs.readFileSync(LANGS_FILE).toString());
else { else {
log.error('Language file not found, using default.'); log.error('Language file not found, using default.');
const file = path.join(path.dirname(require.resolve('@hydrooj/hydrojudge')), 'setting.yaml'); const file = path.join(path.dirname(require.resolve('@hydrooj/hydrojudge')), 'setting.yaml');
const content = yaml.safeLoad(fs.readFileSync(file).toString()) as any; const content = yaml.load(fs.readFileSync(file).toString()) as any;
LANGS = yaml.safeLoad(content.langs.default) as any; LANGS = yaml.load(content.langs.default) as any;
} }
if (!(fs.existsSync(LANGS_FILE) || global.Hydro)) { if (!(fs.existsSync(LANGS_FILE) || global.Hydro)) {
fs.ensureDirSync(path.dirname(LANGS_FILE)); fs.ensureDirSync(path.dirname(LANGS_FILE));
+2 -2
View File
@@ -57,7 +57,7 @@ async function daemon() {
if (CONFIG) config = CONFIG; if (CONFIG) config = CONFIG;
else { else {
config = (await fs.readFile(CONFIG_FILE)).toString(); config = (await fs.readFile(CONFIG_FILE)).toString();
config = yaml.safeLoad(config); config = yaml.load(config);
} }
} catch (e) { } catch (e) {
log.error('配置文件无效或未找到。'); log.error('配置文件无效或未找到。');
@@ -85,7 +85,7 @@ async function daemon() {
if (hosts[i].config.cookie) cfg.hosts[i].cookie = hosts[i].config.cookie; if (hosts[i].config.cookie) cfg.hosts[i].cookie = hosts[i].config.cookie;
if (hosts[i].config.detail) cfg.hosts[i].detail = hosts[i].config.detail; if (hosts[i].config.detail) cfg.hosts[i].detail = hosts[i].config.detail;
} }
await fs.writeFile(CONFIG_FILE, yaml.safeDump(cfg)); await fs.writeFile(CONFIG_FILE, yaml.dump(cfg));
}); });
} }
while ('Orz twd2') { while ('Orz twd2') {
+6 -6
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.15.15", "version": "2.15.16",
"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",
@@ -16,8 +16,8 @@
"cookies": "^0.8.0", "cookies": "^0.8.0",
"detect-browser": "^5.1.1", "detect-browser": "^5.1.1",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"js-yaml": "^3.14.1", "js-yaml": "^4.0.0",
"koa": "^2.13.0", "koa": "^2.13.1",
"koa-body": "^4.2.0", "koa-body": "^4.2.0",
"koa-proxies": "^0.11.0", "koa-proxies": "^0.11.0",
"koa-router": "^10.0.0", "koa-router": "^10.0.0",
@@ -32,18 +32,18 @@
"serialize-javascript": "^5.0.1", "serialize-javascript": "^5.0.1",
"sockjs": "^0.3.20", "sockjs": "^0.3.20",
"superagent": "^6.1.0", "superagent": "^6.1.0",
"systeminformation": "^4.33.4", "systeminformation": "^4.34.5",
"terminal-kit": "^1.44.3", "terminal-kit": "^1.44.3",
"yargs": "^16.2.0" "yargs": "^16.2.0"
}, },
"devDependencies": { "devDependencies": {
"@types/adm-zip": "^0.4.33", "@types/adm-zip": "^0.4.33",
"@types/fs-extra": "^9.0.6", "@types/fs-extra": "^9.0.6",
"@types/js-yaml": "^3.12.5", "@types/js-yaml": "^4.0.0",
"@types/koa": "^2.11.4", "@types/koa": "^2.11.4",
"@types/koa-router": "^7.4.1", "@types/koa-router": "^7.4.1",
"@types/koa-static-cache": "^5.1.0", "@types/koa-static-cache": "^5.1.0",
"@types/lodash": "^4.14.166", "@types/lodash": "^4.14.167",
"@types/lru-cache": "^5.1.0", "@types/lru-cache": "^5.1.0",
"@types/minio": "^7.0.6", "@types/minio": "^7.0.6",
"@types/mongodb": "^3.5.33", "@types/mongodb": "^3.5.33",
+2 -2
View File
@@ -70,7 +70,7 @@ export async function locale(pending: string[], fail: string[]) {
const locales = {}; const locales = {};
for (const file of files) { for (const file of files) {
const content = fs.readFileSync(path.resolve(p, file)).toString(); const content = fs.readFileSync(path.resolve(p, file)).toString();
locales[file.split('.')[0]] = yaml.safeLoad(content); locales[file.split('.')[0]] = yaml.load(content);
} }
global.Hydro.lib.i18n(locales); global.Hydro.lib.i18n(locales);
logger.info('Locale init: %s', i); logger.info('Locale init: %s', i);
@@ -97,7 +97,7 @@ export async function setting(pending: string[], fail: string[], modelSetting: t
if (!fs.existsSync(p)) p = path.resolve(i, 'settings.yaml'); if (!fs.existsSync(p)) p = path.resolve(i, 'settings.yaml');
if (fs.existsSync(p) && !fail.includes(i)) { if (fs.existsSync(p) && !fail.includes(i)) {
try { try {
const cfg: any = yaml.safeLoad(fs.readFileSync(p).toString()); const cfg: any = yaml.load(fs.readFileSync(p).toString());
for (const key in cfg) { for (const key in cfg) {
map[cfg[key].category || 'system']( map[cfg[key].category || 'system'](
modelSetting.Setting( modelSetting.Setting(
+2 -2
View File
@@ -24,7 +24,7 @@ import paginate from '../lib/paginate';
import { isTitle, isContent } from '../lib/validator'; import { isTitle, isContent } from '../lib/validator';
const validatePenaltyRules = (input: string) => { const validatePenaltyRules = (input: string) => {
const s = yaml.safeLoad(input); const s = yaml.load(input);
return s; return s;
}; };
const convertPenaltyRules = validatePenaltyRules; const convertPenaltyRules = validatePenaltyRules;
@@ -281,7 +281,7 @@ class HomeworkEditHandler extends HomeworkHandler {
datePenaltyText: penaltySince.format('YYYY-M-D'), datePenaltyText: penaltySince.format('YYYY-M-D'),
timePenaltyText: penaltySince.format('hh:mm'), timePenaltyText: penaltySince.format('hh:mm'),
extensionDays, extensionDays,
penaltyRules: yaml.safeDump(tdoc.penaltyRules), penaltyRules: yaml.dump(tdoc.penaltyRules),
pids: tdoc.pids.join(','), pids: tdoc.pids.join(','),
path, path,
}; };
+2 -2
View File
@@ -363,7 +363,7 @@ export class ProblemSettingsHandler extends ProblemManageHandler {
['problem_settings', null], ['problem_settings', null],
]; ];
if (this.response.body.pdoc.config) { if (this.response.body.pdoc.config) {
this.response.body.pdoc.config = yaml.safeDump(this.response.body.pdoc.config); this.response.body.pdoc.config = yaml.dump(this.response.body.pdoc.config);
} }
} }
@@ -372,7 +372,7 @@ export class ProblemSettingsHandler extends ProblemManageHandler {
async postConfig(domainId: string, pid: string | number, cfg: string) { async postConfig(domainId: string, pid: string | number, cfg: string) {
const pdoc = await problem.get(domainId, pid); const pdoc = await problem.get(domainId, pid);
// TODO validate // TODO validate
const config = yaml.safeLoad(cfg) as any; const config = yaml.load(cfg) as any;
await problem.edit(domainId, pdoc.docId, { config }); await problem.edit(domainId, pdoc.docId, { config });
this.back(); this.back();
} }
@@ -15,7 +15,7 @@ function convert(ini: string) {
if (!Number.isNaN(parseInt(memory, 10))) cur.memory = `${Math.floor(parseInt(memory, 10) / 1024)}m`; if (!Number.isNaN(parseInt(memory, 10))) cur.memory = `${Math.floor(parseInt(memory, 10) / 1024)}m`;
res.subtasks.push(cur); res.subtasks.push(cur);
} }
return yaml.safeDump(res); return yaml.dump(res);
} }
global.Hydro.lib['testdata.convert.ini'] = convert; global.Hydro.lib['testdata.convert.ini'] = convert;
+2 -2
View File
@@ -1,5 +1,5 @@
import Zip from 'adm-zip'; import Zip from 'adm-zip';
import { safeLoad } from 'js-yaml'; import { load } from 'js-yaml';
import { LocalProblemConfig } from '../interface'; import { LocalProblemConfig } from '../interface';
export async function readConfig(file: string | Buffer) { export async function readConfig(file: string | Buffer) {
@@ -37,7 +37,7 @@ export async function parseConfig(config: string | LocalProblemConfig) {
let cfg: LocalProblemConfig = {}; let cfg: LocalProblemConfig = {};
if (typeof config === 'string') { if (typeof config === 'string') {
// TODO should validate here? // TODO should validate here?
cfg = safeLoad(config) as LocalProblemConfig; cfg = load(config) as LocalProblemConfig;
} else cfg = config; } else cfg = config;
if (cfg.cases) { if (cfg.cases) {
for (const c of cfg.cases) { for (const c of cfg.cases) {
+2
View File
@@ -1,6 +1,7 @@
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
import moment from 'moment-timezone'; import moment from 'moment-timezone';
import { Dictionary } from 'lodash'; import { Dictionary } from 'lodash';
import yaml from 'js-yaml';
import * as builtin from './builtin'; import * as builtin from './builtin';
import { Setting as _Setting } from '../interface'; import { Setting as _Setting } from '../interface';
import { Logger } from '../logger'; import { Logger } from '../logger';
@@ -142,6 +143,7 @@ SystemSetting(
Setting('setting_server', 'server.port', null, 8888, 'number', 'Server Port'), Setting('setting_server', 'server.port', null, 8888, 'number', 'Server Port'),
Setting('setting_server', 'server.xff', null, null, 'text', 'IP Header', 'e.g. x-forwarded-for (lowercase)'), Setting('setting_server', 'server.xff', null, null, 'text', 'IP Header', 'e.g. x-forwarded-for (lowercase)'),
Setting('setting_server', 'server.language', langRange, 'zh_CN', 'select', 'Default display language'), Setting('setting_server', 'server.language', langRange, 'zh_CN', 'select', 'Default display language'),
Setting('setting_basic', 'problem.categories', null, yaml.dump(builtin.CATEGORIES), 'textarea', 'Problem Categories'),
Setting('setting_session', 'session.keys', null, [String.random(32)], 'text', 'session.keys', null, FLAG_HIDDEN), Setting('setting_session', 'session.keys', null, [String.random(32)], 'text', 'session.keys', null, FLAG_HIDDEN),
Setting('setting_session', 'session.secure', null, false, 'boolean', 'session.secure'), Setting('setting_session', 'session.secure', null, false, 'boolean', 'session.secure'),
Setting('setting_session', 'session.saved_expire_seconds', null, 3600 * 24 * 30, 'number', 'Saved session expire seconds'), Setting('setting_session', 'session.saved_expire_seconds', null, 3600 * 24 * 30, 'number', 'Saved session expire seconds'),
+2 -2
View File
@@ -1,7 +1,7 @@
import cluster from 'cluster'; import cluster from 'cluster';
import crypto from 'crypto'; import crypto from 'crypto';
import axios from 'axios'; import axios from 'axios';
import { safeDump } from 'js-yaml'; import { dump } from 'js-yaml';
import db from './db'; import db from './db';
import * as bus from './bus'; import * as bus from './bus';
import * as sysinfo from '../lib/sysinfo'; import * as sysinfo from '../lib/sysinfo';
@@ -33,7 +33,7 @@ export async function feedback() {
document.coll.find({ docType: document.TYPE_DISCUSSION }).count(), document.coll.find({ docType: document.TYPE_DISCUSSION }).count(),
record.coll.find().count(), record.coll.find().count(),
]); ]);
const payload = crypt(safeDump({ const payload = crypt(dump({
_id: installid + mid.toString(), _id: installid + mid.toString(),
version, version,
name, name,
+1 -1
View File
@@ -98,7 +98,7 @@ class ImportQduojHandler extends Handler {
} }
await storage.put( await storage.put(
`problem/${domainId}/${pid}/testdata/config.yaml`, `problem/${domainId}/${pid}/testdata/config.yaml`,
Buffer.from(yaml.safeDump(config)), Buffer.from(yaml.dump(config)),
); );
const data = await storage.list(`problem/${domainId}/${pid}/testdata/`, true); const data = await storage.list(`problem/${domainId}/${pid}/testdata/`, true);
await problem.edit(domainId, pid, { html: true, data }); await problem.edit(domainId, pid, { html: true, data });
+1 -1
View File
@@ -13,7 +13,7 @@
"hydrooj": "^2.15.0" "hydrooj": "^2.15.0"
}, },
"dependencies": { "dependencies": {
"ws": "^7.4.1" "ws": "^7.4.2"
}, },
"devDependencies": { "devDependencies": {
"@types/ws": "^7.4.0" "@types/ws": "^7.4.0"
+2 -2
View File
@@ -10,14 +10,14 @@
"build": "tsc" "build": "tsc"
}, },
"devDependencies": { "devDependencies": {
"@types/js-yaml": "^3.12.5", "@types/js-yaml": "^4.0.0",
"@types/mongodb": "^3.5.33" "@types/mongodb": "^3.5.33"
}, },
"peerDependencies": { "peerDependencies": {
"hydrooj": "2.14.x" "hydrooj": "2.14.x"
}, },
"dependencies": { "dependencies": {
"js-yaml": "^3.14.1", "js-yaml": "^4.0.0",
"mongodb": "^3.6.3" "mongodb": "^3.6.3"
} }
} }
+1 -1
View File
@@ -346,7 +346,7 @@ async function fix(doc) {
w.on('error', reject); w.on('error', reject);
r.pipe(w); r.pipe(w);
}); });
const config = yaml.safeLoad(await testdataConfig.readConfig(p)); const config = yaml.load(await testdataConfig.readConfig(p));
await dst.collection('document').updateOne( await dst.collection('document').updateOne(
{ _id: doc._id }, { _id: doc._id },
{ $set: { config } }, { $set: { config } },