mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add querystring and originalPath property on request
This commit is contained in:
1 parent
512a912080
commit
9576d35e21
6 files changed
+23
-18
No files matched your search
@@ -107,7 +107,7 @@ class ApiHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async get() {
|
async get() {
|
||||||
const q = decodeURIComponent(this.ctx.request.querystring);
|
const q = decodeURIComponent(this.request.querystring);
|
||||||
if (q === 'schema') {
|
if (q === 'schema') {
|
||||||
this.response.type = 'application/json';
|
this.response.type = 'application/json';
|
||||||
this.response.body = { schema: schemaStr };
|
this.response.body = { schema: schemaStr };
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ export default async (ctx, next) => {
|
|||||||
body: ctx.request.body,
|
body: ctx.request.body,
|
||||||
files: ctx.request.files as any,
|
files: ctx.request.files as any,
|
||||||
query: ctx.query,
|
query: ctx.query,
|
||||||
|
querystring: ctx.querystring,
|
||||||
path: ctx.path,
|
path: ctx.path,
|
||||||
|
originalPath: ctx.originalPath,
|
||||||
params: ctx.params,
|
params: ctx.params,
|
||||||
referer: ctx.request.headers.referer || '',
|
referer: ctx.request.headers.referer || '',
|
||||||
json: (ctx.request.headers.accept || '').includes('application/json'),
|
json: (ctx.request.headers.accept || '').includes('application/json'),
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ export interface HydroRequest {
|
|||||||
body: any;
|
body: any;
|
||||||
files: Record<string, import('formidable').File>;
|
files: Record<string, import('formidable').File>;
|
||||||
query: any;
|
query: any;
|
||||||
|
querystring: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
originalPath: string;
|
||||||
params: any;
|
params: any;
|
||||||
referer: string;
|
referer: string;
|
||||||
json: boolean;
|
json: boolean;
|
||||||
@@ -114,17 +116,18 @@ export class HandlerCommon {
|
|||||||
session: Record<string, any>;
|
session: Record<string, any>;
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
domainId: string;
|
domainId: string;
|
||||||
|
ctx: Context = global.app;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public ctx: KoaContext, public args: Record<string, any>,
|
public context: KoaContext, public args: Record<string, any>,
|
||||||
public request: HydroRequest, public response: HydroResponse,
|
public request: HydroRequest, public response: HydroResponse,
|
||||||
public user: User, public domain: DomainDoc, public UiContext: Record<string, any>,
|
public user: User, public domain: DomainDoc, public UiContext: Record<string, any>,
|
||||||
) {
|
) {
|
||||||
this.render = ctx.render.bind(ctx);
|
this.render = context.render.bind(context);
|
||||||
this.renderHTML = ctx.renderHTML.bind(ctx);
|
this.renderHTML = context.renderHTML.bind(context);
|
||||||
this.url = ctx.getUrl.bind(ctx);
|
this.url = context.getUrl.bind(context);
|
||||||
this.translate = ctx.translate.bind(ctx);
|
this.translate = context.translate.bind(context);
|
||||||
this.session = ctx.session;
|
this.session = context.session;
|
||||||
this.domainId = args.domainId;
|
this.domainId = args.domainId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +143,8 @@ export class HandlerCommon {
|
|||||||
|
|
||||||
renderTitle(str: string) {
|
renderTitle(str: string) {
|
||||||
const name = this.domain?.ui?.name || system.get('server.name');
|
const name = this.domain?.ui?.name || system.get('server.name');
|
||||||
if (this.UiContext.extraTitleContent) return `${this.ctx.translate(str)} - ${this.UiContext.extraTitleContent} - ${name}`;
|
if (this.UiContext.extraTitleContent) return `${this.translate(str)} - ${this.UiContext.extraTitleContent} - ${name}`;
|
||||||
return `${this.ctx.translate(str)} - ${name}`;
|
return `${this.translate(str)} - ${name}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPerm(...args: bigint[]) {
|
checkPerm(...args: bigint[]) {
|
||||||
@@ -193,9 +196,9 @@ export class Handler extends HandlerCommon {
|
|||||||
if (error.stack) logger.error(error.stack);
|
if (error.stack) logger.error(error.stack);
|
||||||
}
|
}
|
||||||
if (this.user?._id === 0 && (error instanceof PermissionError || error instanceof PrivilegeError)) {
|
if (this.user?._id === 0 && (error instanceof PermissionError || error instanceof PrivilegeError)) {
|
||||||
this.response.redirect = this.ctx.getUrl('user_login', {
|
this.response.redirect = this.url('user_login', {
|
||||||
query: {
|
query: {
|
||||||
redirect: (this.ctx.originalPath || this.request.path) + this.ctx.search,
|
redirect: (this.context.originalPath || this.request.path) + this.context.search,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -330,10 +333,10 @@ export class ConnectionHandler extends HandlerCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onerror(err: HydroError) {
|
onerror(err: HydroError) {
|
||||||
if (err instanceof UserFacingError) err.stack = this.ctx.HydroContext.request.path;
|
if (err instanceof UserFacingError) err.stack = this.request.path;
|
||||||
if (!(err instanceof NotFoundError)
|
if (!(err instanceof NotFoundError)
|
||||||
&& !((err instanceof PrivilegeError || err instanceof PermissionError) && this.user?._id === 0)) {
|
&& !((err instanceof PrivilegeError || err instanceof PermissionError) && this.user?._id === 0)) {
|
||||||
logger.error(`Path:${this.ctx.HydroContext.request.path}, User:${this.user?._id}(${this.user?.uname})`);
|
logger.error(`Path:${this.request.path}, User:${this.user?._id}(${this.user?.uname})`);
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
this.send({
|
this.send({
|
||||||
|
|||||||
@@ -135,7 +135,11 @@ class ImportQduojHandler extends Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const name = 'import-qduoj';
|
||||||
export async function apply(ctx: Context) {
|
export async function apply(ctx: Context) {
|
||||||
ctx.Route('problem_import_qduoj', '/problem/import/qduoj', ImportQduojHandler, PERM.PERM_CREATE_PROBLEM);
|
ctx.Route('problem_import_qduoj', '/problem/import/qduoj', ImportQduojHandler, PERM.PERM_CREATE_PROBLEM);
|
||||||
ctx.inject('ProblemAdd', 'problem_import_qduoj', { icon: 'copy', text: 'From QDUOJ Export' });
|
ctx.inject('ProblemAdd', 'problem_import_qduoj', { icon: 'copy', text: 'From QDUOJ Export' });
|
||||||
|
ctx.i18n.load('zh', {
|
||||||
|
'From QDUOJ Export': '从 QDUOJ 导入',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
From QDUOJ Export: 从 QDUOJ 导入
|
|
||||||
@@ -6,8 +6,5 @@
|
|||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true
|
||||||
"dependencies": {
|
|
||||||
"decode-html": "^2.0.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user