Feat: i18n develop for remote_service

This commit is contained in:
Suwings 2022-07-27 21:13:30 +08:00
parent e76dafb74a
commit 253497593e
3 changed files with 22 additions and 18 deletions

View File

@ -44,33 +44,34 @@ export default class RemoteService {
// 连接远程服务
public connect(connectOpts?: SocketIOClient.ConnectOpts) {
if (connectOpts) this.config.connectOpts = connectOpts;
if (this.available) {
logger.info(`[${this.uuid}] 用户发起重连已可用状态的远程服务,正在重置连接通道`);
this.disconnect();
}
// 防止重复注册事件
if (this.socket && this.socket.hasListeners("connect")) {
logger.info(`[${this.uuid}] 用户发起重复连接请求,现进行重置连接配置`);
return this.refreshReconnect();
}
// 开始正式连接远程Socket程序
let addr = `ws://${this.config.ip}:${this.config.port}`;
if (this.config.ip.indexOf("wss://") === 0 || this.config.ip.indexOf("ws://") === 0) {
addr = `${this.config.ip}:${this.config.port}`;
}
logger.info(`[${this.uuid}] 面板正在尝试连接远程服务 ${addr}`);
const daemonInfo = `[${this.uuid}] [${addr}]`;
if (this.available) {
logger.info(`${$t("daemonInfo.resetConnect")}:${daemonInfo}`);
this.disconnect();
}
// 防止重复注册事件
if (this.socket && this.socket.hasListeners("connect")) {
logger.info(`${$t("daemonInfo.replaceConnect")}:${daemonInfo}`);
return this.refreshReconnect();
}
logger.info(`${$t("daemonInfo.tryConnect")}:${daemonInfo}`);
this.socket = io.connect(addr, connectOpts);
// 注册内置事件
this.socket.on("connect", async () => {
logger.info(`远程服务 [${this.uuid}] [${this.config.ip}:${this.config.port}] 已连接`);
logger.info($t("daemonInfo.connect", { v: daemonInfo }));
await this.onConnect();
});
this.socket.on("disconnect", async () => {
logger.info(`远程服务 [${this.uuid}] [${this.config.ip}:${this.config.port}] 已断开`);
logger.info($t("daemonInfo.disconnect", { v: daemonInfo }));
await this.onDisconnect();
});
this.socket.on("connect_error", async (error: string) => {

View File

@ -47,7 +47,7 @@ export default {
off: "管理员已限制全部用户使用文件管理功能"
},
schedule: {
invaildName: "非法的计划任务名"
invalidName: "非法的计划任务名"
},
login: {
ban: "身份验证次数过多,您的 IP 地址已被锁定 10 分钟",
@ -63,7 +63,10 @@ export default {
authSuccess: "远程节点 {{v}} 验证成功",
authFailure: "远程节点 {{v}} 验证失败",
authError: "远程节点 {{v}} 验证错误",
closed: "主动断开远程节点 {{v}} "
closed: "主动断开远程节点 {{v}} ",
resetConnect: "用户发起重连已可用状态的远程节点,正在重置连接通道",
replaceConnect: "用户发起重复连接请求,现进行重置连接配置",
tryConnect: "正在尝试连接远程节点"
}
};
// import { $t } from "../../i18n";

View File

@ -84,7 +84,7 @@ router.post(
// 计划任务名需要文件名格式检查
const name = String(task.name);
FILENAME_BLACKLIST.forEach((ch) => {
if (name.includes(ch)) throw new Error($t("router.schedule.invaildName"));
if (name.includes(ch)) throw new Error($t("router.schedule.invalidName"));
});
ctx.body = await new RemoteRequest(RemoteServiceSubsystem.getInstance(serviceUuid)).request(