From 67960685230839df62bf2a9f7f867e096cd43b87 Mon Sep 17 00:00:00 2001 From: whyour Date: Thu, 11 Jun 2026 23:18:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=9B=BD=E9=99=85=E5=8C=96?= =?UTF-8?q?=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/config.ts | 4 ++-- back/api/system.ts | 3 ++- back/api/user.ts | 7 ++++--- back/loaders/express.ts | 3 ++- back/services/config.ts | 3 ++- back/services/cron.ts | 2 +- back/services/notify.ts | 5 +++-- back/services/open.ts | 3 ++- back/services/subscription.ts | 3 ++- back/shared/i18n.ts | 6 ++++++ 10 files changed, 26 insertions(+), 13 deletions(-) diff --git a/back/api/config.ts b/back/api/config.ts index 7d9552a3..f40a8cab 100644 --- a/back/api/config.ts +++ b/back/api/config.ts @@ -83,10 +83,10 @@ export default (app: Router) => { !path.startsWith(config.configPath) && !path.startsWith(config.scriptPath) ) { - return res.send({ code: 403, message: '文件路径无效' }); + return res.send({ code: 403, message: t('文件路径无效') }); } await writeFileWithLock(path, content); - res.send({ code: 200, message: '保存成功' }); + res.send({ code: 200, message: t('保存成功') }); } catch (e) { return next(e); } diff --git a/back/api/system.ts b/back/api/system.ts index 86e9f3d9..cf662c30 100644 --- a/back/api/system.ts +++ b/back/api/system.ts @@ -6,6 +6,7 @@ import config from '../config'; import SystemService from '../services/system'; import { celebrate, Joi } from 'celebrate'; import UserService from '../services/user'; +import { t } from '../shared/i18n'; import { getUniqPath, handleLogPath, @@ -401,7 +402,7 @@ export default (app: Router) => { try { const userService = Container.get(UserService); await userService.resetAuthInfo(req.body); - res.send({ code: 200, message: '更新成功' }); + res.send({ code: 200, message: t('更新成功') }); } catch (e) { return next(e); } diff --git a/back/api/user.ts b/back/api/user.ts index 6155f0a4..9e284dba 100644 --- a/back/api/user.ts +++ b/back/api/user.ts @@ -8,6 +8,7 @@ import path from 'path'; import { v4 as uuidV4 } from 'uuid'; import rateLimit from 'express-rate-limit'; import config from '../config'; +import { t } from '../shared/i18n'; import { isDemoEnv, getToken } from '../config/util'; const route = Router(); @@ -76,11 +77,11 @@ export default (app: Router) => { async (req: Request, res: Response, next: NextFunction) => { try { if (isDemoEnv()) { - return res.send({ code: 450, message: '未知错误' }); + return res.send({ code: 450, message: t('未知错误') }); } const userService = Container.get(UserService); await userService.updateUsernameAndPassword(req.body); - res.send({ code: 200, message: '更新成功' }); + res.send({ code: 200, message: t('更新成功') }); } catch (e) { return next(e); } @@ -229,7 +230,7 @@ export default (app: Router) => { try { const userService = Container.get(UserService); await userService.updateUsernameAndPassword(req.body); - res.send({ code: 200, message: '更新成功' }); + res.send({ code: 200, message: t('更新成功') }); } catch (e) { return next(e); } diff --git a/back/loaders/express.ts b/back/loaders/express.ts index b5bf221b..6b322e93 100644 --- a/back/loaders/express.ts +++ b/back/loaders/express.ts @@ -11,6 +11,7 @@ import { serveEnv } from '../config/serverEnv'; import { IKeyvStore, shareStore } from '../shared/store'; import { isValidToken } from '../shared/auth'; import path from 'path'; +import { t } from '../shared/i18n'; export default ({ app }: { app: Application }) => { // Security: Enable strict routing to prevent case-insensitive path bypass @@ -143,7 +144,7 @@ export default ({ app }: { app: Application }) => { } if (isInitialized) { - return res.send({ code: 450, message: '未知错误' }); + return res.send({ code: 450, message: t('未知错误') }); } else { return next(); } diff --git a/back/services/config.ts b/back/services/config.ts index a12a9419..7e7e5985 100644 --- a/back/services/config.ts +++ b/back/services/config.ts @@ -2,6 +2,7 @@ import { Service, Inject } from 'typedi'; import path, { join } from 'path'; import config from '../config'; import { getFileContentByName } from '../config/util'; +import { t } from '../shared/i18n'; import { Response } from 'express'; import { request } from 'undici'; @@ -23,7 +24,7 @@ export default class ConfigService { ) || !filePath ) { - return res.send({ code: 403, message: '文件无法访问' }); + return res.send({ code: 403, message: t('文件无法访问') }); } if (filePath.startsWith('sample/')) { diff --git a/back/services/cron.ts b/back/services/cron.ts index ee14a669..5a4bd774 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -577,7 +577,7 @@ export default class CronService { { where: { id: instance.cron_id } }, ); } - return { code: 200, message: '实例已停止' }; + return { code: 200, message: t('实例已停止') }; } private async runSingle(cronId: number): Promise { diff --git a/back/services/notify.ts b/back/services/notify.ts index 39a0e47b..abf1f96c 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -3,6 +3,7 @@ import nodemailer from 'nodemailer'; import { Inject, Service } from 'typedi'; import { parseBody, parseHeaders } from '../config/util'; import { NotificationInfo } from '../data/notify'; +import { t } from '../shared/i18n'; import UserService from './user'; import { httpClient } from '../config/http'; import { ProxyAgent } from 'undici'; @@ -727,7 +728,7 @@ export default class NotificationService { // topic_ids 和 uids 至少要有一个 if (!topicIds.length && !uids.length) { - throw new Error('wxPusher 服务的 TopicIds 和 Uids 至少配置一个才行'); + throw new Error(t('wxPusher 服务的 TopicIds 和 Uids 至少配置一个才行')); } const url = `https://wxpusher.zjiecode.com/api/send/message`; @@ -823,7 +824,7 @@ export default class NotificationService { } = this.params; if (!webhookUrl?.includes('$title') && !webhookBody?.includes('$title')) { - throw new Error('Url 或者 Body 中必须包含 $title'); + throw new Error(t('Url 或者 Body 中必须包含 $title')); } const headers = parseHeaders(webhookHeaders); diff --git a/back/services/open.ts b/back/services/open.ts index 59dcc5bc..19d846c0 100644 --- a/back/services/open.ts +++ b/back/services/open.ts @@ -5,6 +5,7 @@ import { App, AppModel } from '../data/open'; import { v4 as uuidV4 } from 'uuid'; import sequelize, { Op } from 'sequelize'; import { shareStore } from '../shared/store'; +import { t } from '../shared/i18n'; @Service() export default class OpenService { @@ -151,7 +152,7 @@ export default class OpenService { }, }; } else { - return { code: 400, message: 'client_id 或 client_seret 有误' }; + return { code: 400, message: t('client_id 或 client_seret 有误') }; } } diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 1a8638f8..ed7f5b40 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -24,6 +24,7 @@ import path, { join } from 'path'; import ScheduleService, { TaskCallbacks } from './schedule'; import { SimpleIntervalSchedule } from 'toad-scheduler'; import SockService from './sock'; +import { t } from '../shared/i18n'; import SshKeyService from './sshKey'; import dayjs from 'dayjs'; import { LOG_END_SYMBOL } from '../config/const'; @@ -192,7 +193,7 @@ export default class SubscriptionService { this.sockService.sendMessage({ type: 'runSubscriptionEnd', - message: '订阅执行完成', + message: t('订阅执行完成'), references: [doc.id as number], }); }, diff --git a/back/shared/i18n.ts b/back/shared/i18n.ts index e260633f..04eaa769 100644 --- a/back/shared/i18n.ts +++ b/back/shared/i18n.ts @@ -74,6 +74,12 @@ const messages: Record> = { '用户名不能为admin': 'Username cannot be admin', '不能删除自己': 'Cannot delete yourself', '不能禁用自己': 'Cannot disable yourself', + '文件路径无效': 'Invalid file path', + '保存成功': 'Saved successfully', + 'client_id 或 client_seret 有误': 'Invalid client_id or client_secret', + '订阅执行完成': 'Subscription completed', + 'wxPusher 服务的 TopicIds 和 Uids 至少配置一个才行': 'wxPusher requires at least one of TopicIds or Uids', + 'Url 或者 Body 中必须包含 $title': 'Url or Body must contain $title', }, };