mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
bug fixes
This commit is contained in:
3 files changed
+8
-7
No files matched your search
@@ -23,7 +23,7 @@ import serializer from './serializer';
|
|||||||
|
|
||||||
export { WebSocket, WebSocketServer } from 'ws';
|
export { WebSocket, WebSocketServer } from 'ws';
|
||||||
|
|
||||||
const kHandler = Symbol.for('hydro.handler');
|
export const kHandler = Symbol.for('hydro.handler');
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
|
||||||
export function encodeRFC5987ValueChars(str: string) {
|
export function encodeRFC5987ValueChars(str: string) {
|
||||||
@@ -111,7 +111,7 @@ export interface UserModel {
|
|||||||
|
|
||||||
export interface HandlerCommon { }
|
export interface HandlerCommon { }
|
||||||
export class HandlerCommon {
|
export class HandlerCommon {
|
||||||
static [kHandler] = true;
|
static [kHandler]: string | boolean = true;
|
||||||
session: Record<string, any>;
|
session: Record<string, any>;
|
||||||
args: Record<string, any>;
|
args: Record<string, any>;
|
||||||
request: HydroRequest;
|
request: HydroRequest;
|
||||||
@@ -459,6 +459,7 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
const h = new HandlerClass(ctx, this.ctx);
|
const h = new HandlerClass(ctx, this.ctx);
|
||||||
ctx.handler = h;
|
ctx.handler = h;
|
||||||
const method = ctx.method.toLowerCase();
|
const method = ctx.method.toLowerCase();
|
||||||
|
const name = (typeof HandlerClass[kHandler] === 'string' ? HandlerClass[kHandler] : HandlerClass.name).replace(/Handler$/, '');
|
||||||
try {
|
try {
|
||||||
const operation = (method === 'post' && ctx.request.body?.operation)
|
const operation = (method === 'post' && ctx.request.body?.operation)
|
||||||
? `_${ctx.request.body.operation}`.replace(/_([a-z])/gm, (s) => s[1].toUpperCase())
|
? `_${ctx.request.body.operation}`.replace(/_([a-z])/gm, (s) => s[1].toUpperCase())
|
||||||
@@ -479,7 +480,6 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
throw new MethodNotAllowedError(method);
|
throw new MethodNotAllowedError(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = HandlerClass.name.replace(/Handler$/, '');
|
|
||||||
const steps = [
|
const steps = [
|
||||||
'log/__init', 'init', 'handler/init',
|
'log/__init', 'init', 'handler/init',
|
||||||
`handler/before-prepare/${name}#${method}`, `handler/before-prepare/${name}`, 'handler/before-prepare',
|
`handler/before-prepare/${name}#${method}`, `handler/before-prepare/${name}`, 'handler/before-prepare',
|
||||||
@@ -516,7 +516,7 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
try {
|
try {
|
||||||
await this.ctx.serial(`handler/error/${HandlerClass.name.replace(/Handler$/, '')}`, h, e);
|
await this.ctx.serial(`handler/error/${name}`, h, e);
|
||||||
await this.ctx.serial('handler/error', h, e);
|
await this.ctx.serial('handler/error', h, e);
|
||||||
await h.onerror(e);
|
await h.onerror(e);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -596,7 +596,7 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`);
|
|||||||
|
|
||||||
private register(type: 'route' | 'conn', routeName: string, path: string, HandlerClass: any, ...permPrivChecker) {
|
private register(type: 'route' | 'conn', routeName: string, path: string, HandlerClass: any, ...permPrivChecker) {
|
||||||
if (!HandlerClass?.[kHandler] || !isClass(HandlerClass)) throw new Error('Invalid registration.');
|
if (!HandlerClass?.[kHandler] || !isClass(HandlerClass)) throw new Error('Invalid registration.');
|
||||||
const name = HandlerClass.name;
|
const name = typeof HandlerClass[kHandler] === 'string' ? HandlerClass[kHandler] : HandlerClass.name;
|
||||||
if (this.registrationCount[name] && this.registry[name] !== HandlerClass) {
|
if (this.registrationCount[name] && this.registry[name] !== HandlerClass) {
|
||||||
logger.warn('Route with name %s already exists.', name);
|
logger.warn('Route with name %s already exists.', name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,12 +124,12 @@ class MongoService {
|
|||||||
return [pageDocs, numPages, count];
|
return [pageDocs, numPages, count];
|
||||||
}
|
}
|
||||||
|
|
||||||
async ranked<T extends Record<string, any>>(cursor: FindCursor<T>, equ: (a: T, b: T) => boolean): Promise<[number, T][]> {
|
async ranked<T extends Record<string, any>>(cursor: T[] | FindCursor<T>, equ: (a: T, b: T) => boolean): Promise<[number, T][]> {
|
||||||
let last = null;
|
let last = null;
|
||||||
let r = 0;
|
let r = 0;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const results = [];
|
const results = [];
|
||||||
const docs = await cursor.toArray();
|
const docs = cursor instanceof Array ? cursor : await cursor.toArray();
|
||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
if ((doc as any).unrank) {
|
if ((doc as any).unrank) {
|
||||||
results.push([0, doc]);
|
results.push([0, doc]);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
{% import "components/contest.html" as contest with context %}
|
{% import "components/contest.html" as contest with context %}
|
||||||
{% import "components/problem.html" as problem with context %}
|
{% import "components/problem.html" as problem with context %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{{ set(UiContext, 'tdoc', tdoc) }}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="medium-9 columns">
|
<div class="medium-9 columns">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
Reference in new issue
Block a user