37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
|
|
const { randomUUID } = require("crypto");
|
||
|
|
const http = require("../../utils/http");
|
||
|
|
const dayjs = require("dayjs");
|
||
|
|
|
||
|
|
module.exports = async (ctx) => {
|
||
|
|
let { id = 4, limitIp, expiryTime, enable = !0, totalGB = 1, subId = "2rv0gb458kbfl532" } = ctx.request.body;
|
||
|
|
const inbound = await http.get(`/api/inbounds/get/${id}`);
|
||
|
|
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();
|
||
|
|
const settings = { clients: [{ id: uuid, flow: "", email, limitIp, enable, tgId: "", subId, reset: 0, totalGB, expiryTime }] };
|
||
|
|
http
|
||
|
|
.post("/api/inbounds/addClient", { id, settings: JSON.stringify(settings) })
|
||
|
|
.then((res) => {
|
||
|
|
if (res?.success) {
|
||
|
|
const { remark, port, protocol, streamSettings = "{}" } = inbound.obj || {};
|
||
|
|
const {
|
||
|
|
network = "ws",
|
||
|
|
security = "none",
|
||
|
|
wsSettings: { host, path },
|
||
|
|
} = JSON.parse(streamSettings);
|
||
|
|
return ctx.body = {
|
||
|
|
code: "0",
|
||
|
|
data: `${protocol}://${uuid}@vless.jjcp52.com:${port}?type=${network}&path=${path}&host=${host}&security=${security}#${remark}-${email}`,
|
||
|
|
message: "success",
|
||
|
|
};
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.finally(() => {
|
||
|
|
ctx.body = {
|
||
|
|
message: "Example POST API",
|
||
|
|
data: ctx.request.body,
|
||
|
|
};
|
||
|
|
});
|
||
|
|
};
|