fix(api/client): 修复添加客户端时的总流量计算和数据获取问题
- 将 totalGB 转换为字节,以确保正确的流量限制 - 修正 inbound 数据获取路径,提高代码的健壮性
This commit is contained in:
@@ -5,7 +5,7 @@ const getCookie = require("../../auth/3xuiLogin");
|
|||||||
const { log } = require("console");
|
const { log } = require("console");
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
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) {
|
if (!ctx.state.cookie) {
|
||||||
ctx.state.cookie = await getCookie();
|
ctx.state.cookie = await getCookie();
|
||||||
ins.interceptors.request.use((config) => {
|
ins.interceptors.request.use((config) => {
|
||||||
@@ -17,11 +17,14 @@ module.exports = async (ctx) => {
|
|||||||
if (!inbound?.success) return (ctx.body = { code: "1", msg: "获取节点失败" });
|
if (!inbound?.success) return (ctx.body = { code: "1", msg: "获取节点失败" });
|
||||||
const uuid = randomUUID(),
|
const uuid = randomUUID(),
|
||||||
email = uuid.split("-")[0];
|
email = uuid.split("-")[0];
|
||||||
|
if (expiryTime > 0) {
|
||||||
expiryTime = dayjs(expiryTime, "YYYY-MM-DD HH:mm:ss").valueOf();
|
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 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) });
|
const result = await ins.post("/panel/api/inbounds/addClient", { id, settings: JSON.stringify(settings) });
|
||||||
if (result?.success) {
|
if (result?.success) {
|
||||||
const { remark, port, protocol, streamSettings = "{}" } = inbound.data?.obj || {};
|
const { remark, port, protocol, streamSettings = "{}" } = inbound.obj || {};
|
||||||
const {
|
const {
|
||||||
network = "ws",
|
network = "ws",
|
||||||
security = "none",
|
security = "none",
|
||||||
|
|||||||
Reference in New Issue
Block a user