mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: translation enhance
This commit is contained in:
1 parent
2b0bd3df04
commit
0bb6be0eaf
4 files changed
+5
-4
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "3.14.1",
|
||||
"version": "3.14.2",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -5,6 +5,7 @@ import token from 'hydrooj/src/model/token';
|
||||
|
||||
export default async (ctx, next) => {
|
||||
const forceDomain = /^\/d\/([^/]+)\//.exec(ctx.request.path);
|
||||
ctx.originalPath = ctx.request.path;
|
||||
ctx.path = ctx.request.path = ctx.request.path.replace(/^\/d\/[^/]+\//, '/');
|
||||
const [xff, xhost] = system.getMany(['server.xff', 'server.xhost']);
|
||||
const ip = ctx.request.headers[xff?.toLowerCase() || ''] as string || ctx.request.ip;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ObjectID } from 'mongodb';
|
||||
import avatar from 'hydrooj/src/lib/avatar';
|
||||
import * as system from 'hydrooj/src/model/system';
|
||||
import type { KoaContext } from '../server';
|
||||
|
||||
function serializer(k: string, v: any) {
|
||||
@@ -66,7 +65,7 @@ export default (router, logger) => async (ctx: KoaContext, next) => {
|
||||
ctx.translate = (str: string) => {
|
||||
if (!str) return '';
|
||||
const lang = ctx.HydroContext.user?.viewLang || ctx.session?.viewLang;
|
||||
return str.toString().translate(lang, ...ctx.acceptsLanguages(), system.get('server.language'));
|
||||
return str.toString().translate(lang, ...ctx.acceptsLanguages());
|
||||
};
|
||||
await next();
|
||||
};
|
||||
@@ -232,7 +232,8 @@ export class Handler extends HandlerCommon {
|
||||
if (!error.msg) error.msg = () => error.message;
|
||||
if (error instanceof UserFacingError && !process.env.DEV) error.stack = '';
|
||||
if (!(error instanceof NotFoundError)) {
|
||||
logger.error(`User: ${this.user._id}(${this.user.uname}) ${this.request.method}: ${this.request.path}`, error.msg(), error.params);
|
||||
// eslint-disable-next-line max-len
|
||||
logger.error(`User: ${this.user._id}(${this.user.uname}) ${this.request.method}: /d/${this.domain._id}${this.request.path}`, error.msg(), error.params);
|
||||
if (error.stack) logger.error(error.stack);
|
||||
}
|
||||
if (this.user?._id === 0 && (error instanceof PermissionError || error instanceof PrivilegeError)) {
|
||||
|
||||
Reference in new issue
Block a user