mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
bug fixes
This commit is contained in:
6 files changed
+19
-19
No files matched your search
@@ -437,7 +437,7 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
...this.handlerLayers,
|
...this.handlerLayers,
|
||||||
{
|
{
|
||||||
name: '404',
|
name: '404',
|
||||||
func: (t) => this.handleHttp(t, NotFoundHandler, () => true),
|
func: (t) => this.handleHttp(t, NotFoundHandler, () => true, this.ctx),
|
||||||
},
|
},
|
||||||
]));
|
]));
|
||||||
this.addLayer('base', base(logger, this.config.xff, this.config.xhost));
|
this.addLayer('base', base(logger, this.config.xff, this.config.xhost));
|
||||||
@@ -471,10 +471,10 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleHttp(ctx: KoaContext, HandlerClass, checker) {
|
private async handleHttp(ctx: KoaContext, HandlerClass, checker, savedContext) {
|
||||||
const { args } = ctx.HydroContext;
|
const { args } = ctx.HydroContext;
|
||||||
Object.assign(args, ctx.params);
|
Object.assign(args, ctx.params);
|
||||||
const h = new HandlerClass(ctx, this.ctx);
|
const h = new HandlerClass(ctx, savedContext);
|
||||||
ctx.handler = h;
|
ctx.handler = h;
|
||||||
const method = ctx.method.toLowerCase();
|
const method = ctx.method.toLowerCase();
|
||||||
const name = ((Object.hasOwn(HandlerClass, kHandler) && typeof HandlerClass[kHandler] === 'string')
|
const name = ((Object.hasOwn(HandlerClass, kHandler) && typeof HandlerClass[kHandler] === 'string')
|
||||||
@@ -550,9 +550,9 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleWS(ctx: KoaContext, HandlerClass, checker, conn?, layer?) {
|
private async handleWS(ctx: KoaContext, HandlerClass, checker, conn?, layer?, savedContext?) {
|
||||||
const { args } = ctx.HydroContext;
|
const { args } = ctx.HydroContext;
|
||||||
const h = new HandlerClass(ctx, this.ctx);
|
const h = new HandlerClass(ctx, savedContext);
|
||||||
// FIXME: should pass type check
|
// FIXME: should pass type check
|
||||||
await (this.ctx.parallel as any)('connection/create', h);
|
await (this.ctx.parallel as any)('connection/create', h);
|
||||||
const stream = new PassThrough();
|
const stream = new PassThrough();
|
||||||
@@ -695,18 +695,19 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// if (name === 'ContestScoreboard') {
|
// We hope to use parent context for handler (the context that calls register)
|
||||||
// console.log('-------------', this.ctx, this.ctx.scoreboard);
|
// So that handler can use services injected before calling register
|
||||||
// }
|
const savedContext = Object.hasOwn(this.ctx, Symbol.for('cordis.shadow'))
|
||||||
|
? Object.getPrototypeOf(this.ctx)
|
||||||
|
: this.ctx;
|
||||||
if (type === 'route') {
|
if (type === 'route') {
|
||||||
router.all(routeName, path, (ctx) => this.handleHttp(ctx as any, HandlerClass, Checker(permPrivChecker)));
|
router.all(routeName, path, (ctx) => this.handleHttp(ctx as any, HandlerClass, Checker(permPrivChecker), savedContext));
|
||||||
} else {
|
} else {
|
||||||
const checker = Checker(permPrivChecker);
|
const checker = Checker(permPrivChecker);
|
||||||
const layer = router.ws(path, async (conn, _req, ctx) => {
|
const layer = router.ws(path, async (conn, _req, ctx) => {
|
||||||
await this.handleWS(ctx as any, HandlerClass, checker, conn, layer);
|
await this.handleWS(ctx as any, HandlerClass, checker, conn, layer, savedContext);
|
||||||
});
|
});
|
||||||
router.get(path, (ctx) => this.handleWS(ctx as any, HandlerClass, checker, null, null));
|
router.get(path, (ctx) => this.handleWS(ctx as any, HandlerClass, checker, null, null, savedContext));
|
||||||
}
|
}
|
||||||
const dispose = router.disposeLastOp;
|
const dispose = router.disposeLastOp;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -119,8 +119,8 @@ export default class ElasticSearchService extends Service {
|
|||||||
Schema.object({
|
Schema.object({
|
||||||
domainId: Schema.string(),
|
domainId: Schema.string(),
|
||||||
}),
|
}),
|
||||||
this.run,
|
this.run.bind(this),
|
||||||
);
|
);
|
||||||
this.ctx.provideModule('problemSearch', 'elastic', this.problemSearch);
|
this.ctx.provideModule('problemSearch', 'elastic', this.problemSearch.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ import { load as loadOptions } from '../options';
|
|||||||
import { MongoService } from '../service/db';
|
import { MongoService } from '../service/db';
|
||||||
import { ConfigService } from '../settings';
|
import { ConfigService } from '../settings';
|
||||||
import {
|
import {
|
||||||
addon, builtinModel, lib, model, script, service, setting,
|
addon, builtinModel, model, service, setting,
|
||||||
} from './common';
|
} from './common';
|
||||||
|
|
||||||
const argv = cac().parse();
|
const argv = cac().parse();
|
||||||
@@ -122,7 +122,6 @@ export async function load(ctx: Context) {
|
|||||||
await ctx.loader.reloadPlugin(require.resolve('../service/storage'), 'file');
|
await ctx.loader.reloadPlugin(require.resolve('../service/storage'), 'file');
|
||||||
require('../lib/index');
|
require('../lib/index');
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
lib(pending, fail, ctx),
|
|
||||||
service(pending, fail, ctx),
|
service(pending, fail, ctx),
|
||||||
]);
|
]);
|
||||||
ctx.plugin(require('../service/worker'));
|
ctx.plugin(require('../service/worker'));
|
||||||
@@ -140,6 +139,5 @@ export async function load(ctx: Context) {
|
|||||||
for (const h of await fs.readdir(scriptDir)) {
|
for (const h of await fs.readdir(scriptDir)) {
|
||||||
ctx.loader.reloadPlugin(path.resolve(scriptDir, h), '');
|
ctx.loader.reloadPlugin(path.resolve(scriptDir, h), '');
|
||||||
}
|
}
|
||||||
await script(pending, fail, ctx);
|
|
||||||
await cli();
|
await cli();
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ import { load } from '../options';
|
|||||||
import { MongoService } from '../service/db';
|
import { MongoService } from '../service/db';
|
||||||
import { ConfigService } from '../settings';
|
import { ConfigService } from '../settings';
|
||||||
import {
|
import {
|
||||||
addon, builtinModel, locale, model, service,
|
addon, builtinModel, locale, model, service, setting,
|
||||||
} from './common';
|
} from './common';
|
||||||
|
|
||||||
const argv = cac().parse();
|
const argv = cac().parse();
|
||||||
@@ -58,6 +58,7 @@ export async function apply(ctx: Context) {
|
|||||||
await service(pending, fail, ctx);
|
await service(pending, fail, ctx);
|
||||||
await builtinModel(ctx);
|
await builtinModel(ctx);
|
||||||
await model(pending, fail, ctx);
|
await model(pending, fail, ctx);
|
||||||
|
await setting(pending, fail, require('../model/setting'));
|
||||||
|
|
||||||
const handlerDir = path.resolve(__dirname, '..', 'handler');
|
const handlerDir = path.resolve(__dirname, '..', 'handler');
|
||||||
const handlers = await fs.readdir(handlerDir);
|
const handlers = await fs.readdir(handlerDir);
|
||||||
|
|||||||
@@ -676,7 +676,6 @@ class ScoreboardService extends Service {
|
|||||||
views: Record<string, ScoreboardView<any>> = {};
|
views: Record<string, ScoreboardView<any>> = {};
|
||||||
constructor(ctx: Context) {
|
constructor(ctx: Context) {
|
||||||
super(ctx, 'scoreboard');
|
super(ctx, 'scoreboard');
|
||||||
ctx.set('scoreboard', this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addView<T extends { [key: string]: keyof BuiltinInput | AnyFunction | Type<any> }>(
|
addView<T extends { [key: string]: keyof BuiltinInput | AnyFunction | Type<any> }>(
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ factory.addExporter(new Exporter.Console({
|
|||||||
},
|
},
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
}));
|
}));
|
||||||
|
factory.exporters.get(1).levels = { default: process.env.DEV ? 3 : 2 };
|
||||||
|
|
||||||
function createLogger(name: string) {
|
function createLogger(name: string) {
|
||||||
return factory.createLogger(name);
|
return factory.createLogger(name);
|
||||||
|
|||||||
Reference in new issue
Block a user