mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: bug fixes
This commit is contained in:
1 parent
5d340608db
commit
2daa7e2034
11 files changed
+26
-24
No files matched your search
+4
-1
@@ -33,7 +33,7 @@
|
|||||||
"@types/autocannon": "^7.9.0",
|
"@types/autocannon": "^7.9.0",
|
||||||
"@types/cross-spawn": "^6.0.2",
|
"@types/cross-spawn": "^6.0.2",
|
||||||
"@types/mocha": "^9.1.1",
|
"@types/mocha": "^9.1.1",
|
||||||
"@types/node": "^18.8.1",
|
"@types/node": "^18.8.2",
|
||||||
"@types/semver": "^7.3.12",
|
"@types/semver": "^7.3.12",
|
||||||
"@types/supertest": "^2.0.12",
|
"@types/supertest": "^2.0.12",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.39.0",
|
"@typescript-eslint/eslint-plugin": "^5.39.0",
|
||||||
@@ -65,5 +65,8 @@
|
|||||||
"supertest": "^6.3.0",
|
"supertest": "^6.3.0",
|
||||||
"typescript": "4.8.4"
|
"typescript": "4.8.4"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"@blueprintjs/icons": "4.6.0"
|
||||||
|
},
|
||||||
"packageManager": "yarn@3.2.3"
|
"packageManager": "yarn@3.2.3"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "4.0.1",
|
"version": "4.0.2",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/plugin-api",
|
"main": "src/plugin-api",
|
||||||
"module": "src/plugin-api",
|
"module": "src/plugin-api",
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
"@hydrooj/utils": "workspace:*",
|
"@hydrooj/utils": "workspace:*",
|
||||||
"adm-zip": "0.5.5",
|
"adm-zip": "0.5.5",
|
||||||
"cac": "^6.7.14",
|
"cac": "^6.7.14",
|
||||||
"cordis": "^2.3.8",
|
"cordis": "^2.4.3",
|
||||||
"detect-browser": "^5.3.0",
|
"detect-browser": "^5.3.0",
|
||||||
"emoji-regex": "^10.2.1",
|
"emoji-regex": "^10.2.1",
|
||||||
"emojis-list": "2.1.0",
|
"emojis-list": "2.1.0",
|
||||||
@@ -64,7 +64,6 @@
|
|||||||
"@types/koa-static-cache": "^5.1.1",
|
"@types/koa-static-cache": "^5.1.1",
|
||||||
"@types/lodash": "^4.14.186",
|
"@types/lodash": "^4.14.186",
|
||||||
"@types/mime-types": "^2.1.1",
|
"@types/mime-types": "^2.1.1",
|
||||||
"@types/minio": "^7.0.13",
|
|
||||||
"@types/mongodb": "^3.6.20",
|
"@types/mongodb": "^3.6.20",
|
||||||
"@types/nodemailer": "^6.4.6",
|
"@types/nodemailer": "^6.4.6",
|
||||||
"@types/notp": "^2.0.2",
|
"@types/notp": "^2.0.2",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { Context } from '../context';
|
|||||||
import i18n from '../lib/i18n';
|
import i18n from '../lib/i18n';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
|
import { unwrapExports } from '../utils';
|
||||||
|
|
||||||
const logger = new Logger('common');
|
const logger = new Logger('common');
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ const getLoader = (type: LoadTask, filename: string) => async function loader(pe
|
|||||||
const p = locateFile(i, [`${filename}.ts`, `${filename}.js`]);
|
const p = locateFile(i, [`${filename}.ts`, `${filename}.js`]);
|
||||||
if (p && !fail.includes(i)) {
|
if (p && !fail.includes(i)) {
|
||||||
try {
|
try {
|
||||||
const m = require(p);
|
const m = unwrapExports(require(p));
|
||||||
if (m.apply) ctx.loader.reloadPlugin(ctx, p, {});
|
if (m.apply) ctx.loader.reloadPlugin(ctx, p, {});
|
||||||
else logger.info(`${type.replace(/^(.)/, (t) => t.toUpperCase())} init: %s`, i);
|
else logger.info(`${type.replace(/^(.)/, (t) => t.toUpperCase())} init: %s`, i);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ export async function apply(ctx: Context) {
|
|||||||
}
|
}
|
||||||
await handler(pending, fail, ctx);
|
await handler(pending, fail, ctx);
|
||||||
await addon(pending, fail, ctx);
|
await addon(pending, fail, ctx);
|
||||||
|
await ctx.lifecycle.flush();
|
||||||
for (const i in global.Hydro.handler) await global.Hydro.handler[i]();
|
for (const i in global.Hydro.handler) await global.Hydro.handler[i]();
|
||||||
const scriptDir = path.resolve(__dirname, '..', 'script');
|
const scriptDir = path.resolve(__dirname, '..', 'script');
|
||||||
for (const h of await fs.readdir(scriptDir)) {
|
for (const h of await fs.readdir(scriptDir)) {
|
||||||
@@ -68,7 +69,6 @@ export async function apply(ctx: Context) {
|
|||||||
await ctx.lifecycle.flush();
|
await ctx.lifecycle.flush();
|
||||||
await script(pending, fail, ctx);
|
await script(pending, fail, ctx);
|
||||||
await ctx.lifecycle.flush();
|
await ctx.lifecycle.flush();
|
||||||
await sleep(1000); // lifecycle.flush won't wait for async function
|
|
||||||
await ctx.parallel('app/started');
|
await ctx.parallel('app/started');
|
||||||
if (process.env.NODE_APP_INSTANCE === '0') {
|
if (process.env.NODE_APP_INSTANCE === '0') {
|
||||||
const scripts = require('../upgrade').default;
|
const scripts = require('../upgrade').default;
|
||||||
|
|||||||
@@ -556,7 +556,7 @@ export interface Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface FileNode {
|
export interface FileNode {
|
||||||
/** File Path In MinIO */
|
/** File Path In S3 */
|
||||||
_id: string;
|
_id: string;
|
||||||
/** Actual File Path */
|
/** Actual File Path */
|
||||||
path: string;
|
path: string;
|
||||||
|
|||||||
@@ -54,10 +54,10 @@ export class Loader {
|
|||||||
async reloadPlugin(parent: Context, key: string, config: any, asName = '') {
|
async reloadPlugin(parent: Context, key: string, config: any, asName = '') {
|
||||||
let fork = parent.state[Loader.Record]?.[key];
|
let fork = parent.state[Loader.Record]?.[key];
|
||||||
if (fork) {
|
if (fork) {
|
||||||
logger.info('reload plugin %c', key);
|
logger.info('reload plugin %c', key.split('node_modules').pop());
|
||||||
fork.update(config);
|
fork.update(config);
|
||||||
} else {
|
} else {
|
||||||
logger.info('apply plugin %c', key);
|
logger.info('apply plugin %c', key.split('node_modules').pop());
|
||||||
const plugin = await this.resolvePlugin(key);
|
const plugin = await this.resolvePlugin(key);
|
||||||
if (!plugin) return;
|
if (!plugin) return;
|
||||||
resolveConfig(plugin, config);
|
resolveConfig(plugin, config);
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ export async function apply(ctx: Context) {
|
|||||||
const stream = collEvent.watch();
|
const stream = collEvent.watch();
|
||||||
const handleEvent = async (doc: EventDoc) => {
|
const handleEvent = async (doc: EventDoc) => {
|
||||||
const payload = JSON.parse(doc.payload);
|
const payload = JSON.parse(doc.payload);
|
||||||
if (process.send) process.send({ type: 'hydro:broadcast', data: { event: doc.event, payload } });
|
process.send?.({ type: 'hydro:broadcast', data: { event: doc.event, payload } });
|
||||||
await (bus.parallel as any)(doc.event, ...payload);
|
await (bus.parallel as any)(doc.event, ...payload);
|
||||||
};
|
};
|
||||||
stream.on('change', async (change) => {
|
stream.on('change', async (change) => {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import type {
|
|||||||
Db, FilterQuery, ObjectID, OnlyFieldsOfType,
|
Db, FilterQuery, ObjectID, OnlyFieldsOfType,
|
||||||
} from 'mongodb';
|
} from 'mongodb';
|
||||||
import pm2 from '@hydrooj/utils/lib/locate-pm2';
|
import pm2 from '@hydrooj/utils/lib/locate-pm2';
|
||||||
import { Context } from '../context';
|
|
||||||
import type { ProblemSolutionHandler } from '../handler/problem';
|
import type { ProblemSolutionHandler } from '../handler/problem';
|
||||||
import type { UserRegisterHandler } from '../handler/user';
|
import type { UserRegisterHandler } from '../handler/user';
|
||||||
import type {
|
import type {
|
||||||
@@ -100,23 +99,21 @@ export interface EventMap extends LifecycleEvents, HandlerEvents {
|
|||||||
}
|
}
|
||||||
/* eslint-enable @typescript-eslint/naming-convention */
|
/* eslint-enable @typescript-eslint/naming-convention */
|
||||||
|
|
||||||
export function apply(ctx: Context) {
|
try {
|
||||||
try {
|
|
||||||
if (!process.send || !pm2 || process.env.exec_mode !== 'cluster_mode') throw new Error();
|
if (!process.send || !pm2 || process.env.exec_mode !== 'cluster_mode') throw new Error();
|
||||||
pm2.launchBus((err, bus) => {
|
pm2.launchBus((err, bus) => {
|
||||||
if (err) throw new Error();
|
if (err) throw new Error();
|
||||||
bus.on('hydro:broadcast', (packet) => {
|
bus.on('hydro:broadcast', (packet) => {
|
||||||
(ctx.parallel as any)(packet.data.event, ...packet.data.payload);
|
(app.parallel as any)(packet.data.event, ...packet.data.payload);
|
||||||
});
|
});
|
||||||
ctx.on('bus/broadcast', (event, payload) => {
|
app.on('bus/broadcast', (event, payload) => {
|
||||||
process.send({ type: 'hydro:broadcast', data: { event, payload } });
|
process.send({ type: 'hydro:broadcast', data: { event, payload } });
|
||||||
});
|
});
|
||||||
console.debug('Using pm2 event bus');
|
console.debug('Using pm2 event bus');
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ctx.on('bus/broadcast', (event, payload) => ctx.parallel(event, ...payload));
|
app.on('bus/broadcast', (event, payload) => app.parallel(event, ...payload));
|
||||||
console.debug('Using mongodb external event bus');
|
console.debug('Using mongodb external event bus');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@@ -209,8 +209,8 @@ export class Handler extends HandlerCommon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bail(name: string, ...args: any[]) {
|
async function serial(name: string, ...args: any[]) {
|
||||||
const r = await (bus.bail as any)(name, ...args);
|
const r = await (bus.serial as any)(name, ...args);
|
||||||
if (r instanceof Error) throw r;
|
if (r instanceof Error) throw r;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ async function handle(ctx: KoaContext, HandlerClass, checker) {
|
|||||||
let control;
|
let control;
|
||||||
if (step.startsWith('log/')) h.args[step.slice(4)] = Date.now();
|
if (step.startsWith('log/')) h.args[step.slice(4)] = Date.now();
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
else if (step.startsWith('handler/')) control = await bail(step, h);
|
else if (step.startsWith('handler/')) control = await serial(step, h);
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
else if (typeof h[step] === 'function') control = await h[step](args);
|
else if (typeof h[step] === 'function') control = await h[step](args);
|
||||||
if (control) {
|
if (control) {
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
"lint": "eslint"
|
"lint": "eslint"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@blueprintjs/core": "^4.10.2",
|
"@blueprintjs/core": "4.10.2",
|
||||||
"@blueprintjs/select": "^4.7.0",
|
"@blueprintjs/select": "4.7.0",
|
||||||
"@fontsource/dm-mono": "^4.5.10",
|
"@fontsource/dm-mono": "^4.5.10",
|
||||||
"@fontsource/fira-code": "^4.5.12",
|
"@fontsource/fira-code": "^4.5.12",
|
||||||
"@fontsource/inconsolata": "^4.5.8",
|
"@fontsource/inconsolata": "^4.5.8",
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
"@vscode/codicons": "^0.0.32",
|
"@vscode/codicons": "^0.0.32",
|
||||||
"autoprefixer": "^10.4.12",
|
"autoprefixer": "^10.4.12",
|
||||||
"browser-update": "^3.3.40",
|
"browser-update": "^3.3.40",
|
||||||
"chalk": "^5.0.1",
|
"chalk": "^5.1.0",
|
||||||
"chunk-progress-webpack-plugin": "^2.0.1",
|
"chunk-progress-webpack-plugin": "^2.0.1",
|
||||||
"classnames": "^2.3.2",
|
"classnames": "^2.3.2",
|
||||||
"clean-webpack-plugin": "^4.0.0",
|
"clean-webpack-plugin": "^4.0.0",
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ export interface LangConfig {
|
|||||||
key: string;
|
key: string;
|
||||||
hidden: boolean;
|
hidden: boolean;
|
||||||
analysis?: string;
|
analysis?: string;
|
||||||
|
remote?: string;
|
||||||
|
pretest?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseLang(config: string): Record<string, LangConfig> {
|
export function parseLang(config: string): Record<string, LangConfig> {
|
||||||
|
|||||||
Reference in new issue
Block a user