i18n: remote_server.ts

This commit is contained in:
Suwings 2022-07-26 11:58:04 +08:00
parent 4d30857f08
commit e76dafb74a
2 changed files with 16 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import { RemoteServiceConfig } from "./entity_interface";
import { logger } from "../service/log";
import RemoteRequest from "../service/remote_command";
import InstanceStreamListener from "../common/instance_stream";
import { $t } from "../i18n";
export default class RemoteService {
public static readonly STATUS_OK = 200;
@ -73,8 +74,6 @@ export default class RemoteService {
await this.onDisconnect();
});
this.socket.on("connect_error", async (error: string) => {
// 提示次数过于频繁,不再提示
// logger.warn(`远程服务 [${this.uuid}] [${this.config.ip}:${this.config.port}] 连接错误`);
await this.onDisconnect();
});
}
@ -84,18 +83,19 @@ export default class RemoteService {
// Generally, there is no need to execute it manually.
public async auth(key?: string) {
if (key) this.config.apiKey = key;
const daemonInfo = `[${this.uuid}] [${this.config.ip}:${this.config.port}]`;
try {
const res = await new RemoteRequest(this).request("auth", this.config.apiKey, 5000, true);
if (res === true) {
this.available = true;
logger.info(`远程服务 [${this.uuid}] [${this.config.ip}:${this.config.port}] 验证成功`);
logger.info($t("daemonInfo.connect", { v: daemonInfo }));
return true;
}
this.available = false;
logger.warn(`远程服务 [${this.uuid}] [${this.config.ip}:${this.config.port}] 验证失败`);
logger.warn($t("daemonInfo.disconnect", { v: daemonInfo }));
return false;
} catch (error) {
logger.warn(`远程服务 [${this.uuid}] [${this.config.ip}:${this.config.port}] 验证错误`);
logger.warn($t("daemonInfo.connectError", { v: daemonInfo }));
return false;
}
}
@ -115,7 +115,8 @@ export default class RemoteService {
disconnect() {
if (this.socket) {
logger.info(`[${this.uuid}] [${this.config.ip}:${this.config.port}] Socket 已主动释放连接`);
const daemonInfo = `[${this.uuid}] [${this.config.ip}:${this.config.port}]`;
logger.info($t("daemonInfo.closed", { v: daemonInfo }));
this.socket.removeAllListeners();
this.socket.disconnect();
this.socket.close();

View File

@ -55,6 +55,15 @@ export default {
init: "[安装面板] 正在初始化面板管理员账号: {{userName}}",
installed: "面板已安装,无法重新安装,请备份并删除 data 文件夹以实现全新安装"
}
},
daemonInfo: {
connect: "远程节点 {{v}} 已连接",
disconnect: "远程节点 {{v}} 已断开",
connectError: "连接远程节点错误:{{v}} ",
authSuccess: "远程节点 {{v}} 验证成功",
authFailure: "远程节点 {{v}} 验证失败",
authError: "远程节点 {{v}} 验证错误",
closed: "主动断开远程节点 {{v}} "
}
};
// import { $t } from "../../i18n";