From dd0160ea1266e100977b9fa4e98f16f5abdcdbe0 Mon Sep 17 00:00:00 2001 From: Giftina Date: Mon, 30 May 2022 16:36:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20#184=20=EF=BC=8C=E6=94=AF=E6=8C=81ipv6?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=8E=A5=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6791121b..4efb51f6 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ if (_cn_reg.test(process.cwd())) { /** * 声明依赖与配置 */ -const versionNumber = "v3.5.4"; //版本号 +const versionNumber = "v3.5.4-fix"; //版本号 const version = `ChatDACS ${versionNumber}`; //系统版本,会显示在web端标题栏 const utils = require("./plugins/system/utils.js"); //载入系统通用模块 const Constants = require("./config/constants.js"); //系统常量 @@ -191,9 +191,14 @@ io.on("connection", (socket) => { return 0; } - //获取地理位置 - const ip = socket.handshake.headers["x-forwarded-for"] ? socket.handshake.headers["x-forwarded-for"]?.split("::ffff:")[1] : socket.handshake.address.split("::ffff:")[1]; - const location = ipTranslator.searchIP(ip).Country; + //获取 ip 与 地理位置 + const ip = socket.handshake.headers["x-forwarded-for"] ? socket.handshake.headers["x-forwarded-for"]?.split("::ffff:")[1] : socket.handshake.address.split("::ffff:")[1] ?? socket.handshake.address; + let location = "未知归属地"; + try { + location = ipTranslator.searchIP(ip).Country; + } catch (error) { + logger.error(`获取地理位置失败: ${error}`); + } socket.emit("version", version); io.emit("onlineUsers", ++onlineUsers);