From 3f3d19bc6dbdee330fcc91f905cbe7a4ebc17d5c Mon Sep 17 00:00:00 2001 From: aixianling Date: Wed, 26 Feb 2025 16:01:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(api/client):=20=E4=BF=AE=E5=A4=8D=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=97=B6=E7=9A=84=E6=80=BB?= =?UTF-8?q?=E6=B5=81=E9=87=8F=E8=AE=A1=E7=AE=97=E5=92=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 totalGB 转换为字节,以确保正确的流量限制 - 修正 inbound 数据获取路径,提高代码的健壮性 --- api/client/add.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/client/add.js b/api/client/add.js index 37832c8..3cc9ca0 100644 --- a/api/client/add.js +++ b/api/client/add.js @@ -5,7 +5,7 @@ const getCookie = require("../../auth/3xuiLogin"); const { log } = require("console"); module.exports = async (ctx) => { - let { id = 4, limitIp, expiryTime, enable = !0, totalGB = 1, subId = "2rv0gb458kbfl532" } = ctx.request.body; + let { id = 4, limitIp, expiryTime = 0, enable = !0, totalGB = 1, subId = "2rv0gb458kbfl532" } = ctx.request.body; if (!ctx.state.cookie) { ctx.state.cookie = await getCookie(); ins.interceptors.request.use((config) => { @@ -17,11 +17,14 @@ module.exports = async (ctx) => { if (!inbound?.success) return (ctx.body = { code: "1", msg: "获取节点失败" }); const uuid = randomUUID(), email = uuid.split("-")[0]; - expiryTime = dayjs(expiryTime, "YYYY-MM-DD HH:mm:ss").valueOf(); + if (expiryTime > 0) { + expiryTime = dayjs(expiryTime, "YYYY-MM-DD HH:mm:ss").valueOf(); + } + totalGB = totalGB * 1024 * 1024 * 1024; const settings = { clients: [{ id: uuid, flow: "", email, limitIp, enable, tgId: "", subId, reset: 0, totalGB, expiryTime }] }; const result = await ins.post("/panel/api/inbounds/addClient", { id, settings: JSON.stringify(settings) }); if (result?.success) { - const { remark, port, protocol, streamSettings = "{}" } = inbound.data?.obj || {}; + const { remark, port, protocol, streamSettings = "{}" } = inbound.obj || {}; const { network = "ws", security = "none",