Compare commits

..

12 Commits

Author SHA1 Message Date
3f67dc2b2c feat(package): 添加 start 脚本命令
- 在 package.json 中新增 "start" 脚本- 使用 node index.js 启动应用- 便于生产环境直接运行服务
2025-10-18 13:05:10 +08:00
10a7bcbd2c Merge remote-tracking branch 'origin/master'
# Conflicts:
#	api/client/add.js
2025-10-18 12:59:12 +08:00
1730cb41a3 feat(api): 支持生成不同网络类型的客户端链接
- 添加对 TCP 网络类型链接生成的支持- 根据网络类型动态解析流设置参数
-优化 WS 和 TCP 链接格式的生成逻辑-修复构建脚本输出路径问题
- 调整代码格式以提高可读性
2025-10-18 12:56:30 +08:00
24f1f88a45 chore(project):重构项目入口文件结构
- 添加 index.js 作为新的入口文件
- 更新 package.json 中的 main 字段指向 index.js
- 修改 dev 脚本使用 index.js 启动应用
- 移除旧的 app.js 入口相关配置
- 添加 build 脚本用于打包应用
- 清理 package.json 中的冗余字段
2025-10-18 11:27:07 +08:00
319afb24ec refactor(api): 优化获取节点失败的错误信息
- 在 inbound 请求失败时,将错误信息详细输出
- 有助于调试和排查问题
2025-06-06 15:20:25 +08:00
d13b80611c refactor(api/client): 优化添加客户端接口
- 在请求体中增加 uuid 参数
- 如果请求体中提供了 uuid,则使用该值,否则生成新的 UUID
- 优化 email 的生成逻辑,使用 UUID 的第一部分作为用户名
2025-03-07 20:28:49 +08:00
b03396a467 fix(client): 优化用户添加功能
- 修复到期时间判断逻辑,提高代码可读性
- 完善错误信息提示,方便排查问题
2025-03-07 18:29:36 +08:00
5142e6f245 feat(api): 添加客户端状态接口
- 新增 client/status.js 文件实现客户端状态获取功能
- 移除 add.js 中未使用的 console.log 引用
2025-02-28 22:21:59 +08:00
aixianling
30236e4359 Merge branch 'master' of http://121.41.123.129:35417/kubbo/vless-api 2025-02-28 17:12:42 +08:00
aixianling
1ac6b88e75 refactor(api): 优化客户端添加逻辑
- 修改了 expiryTime 的判断条件,使用不等于 0 替代大于 0,以处理所有非零值
- 优化了代码结构,提高了可读性
2025-02-28 17:08:54 +08:00
01cccc21c1 feat(auth): 实现第三方 token 验证功能
- 添加了 AUTH_TOKEN 环境变量作为验证标准
- 修改了 verifyThirdPartyToken 函数,实现了基本的 token 验证逻辑
2025-02-27 21:38:44 +08:00
aixianling
d5798eacdb feat(api/client): 优化添加客户端接口
- 在请求体中增加 email 参数,允许自定义用户邮箱
- 如果请求体中未提供 email,则使用随机生成的 UUID 作为邮箱
- 优化了代码结构,提高了可读性和可维护性
2025-02-26 16:08:22 +08:00
5 changed files with 52 additions and 26 deletions

View File

@@ -2,10 +2,9 @@ const { randomUUID } = require("crypto");
const ins = require("../../utils/http"); const ins = require("../../utils/http");
const dayjs = require("dayjs"); const dayjs = require("dayjs");
const getCookie = require("../../auth/3xuiLogin"); const getCookie = require("../../auth/3xuiLogin");
const { log } = require("console");
module.exports = async (ctx) => { module.exports = async (ctx) => {
let { id = 4, limitIp, expiryTime = 0, enable = !0, totalGB = 1, subId = "2rv0gb458kbfl532" } = ctx.request.body; let {id = 4, limitIp, expiryTime = 0, enable = !0, totalGB = 1, subId = "2rv0gb458kbfl532", email, uuid} = 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) => {
@@ -14,10 +13,10 @@ module.exports = async (ctx) => {
}); });
} }
const inbound = await ins.get(`/panel/api/inbounds/get/${id}`); const inbound = await ins.get(`/panel/api/inbounds/get/${id}`);
if (!inbound?.success) return (ctx.body = { code: "1", msg: "获取节点失败" }); if (!inbound?.success) return (ctx.body = { code: "1", msg: `获取节点失败:${inbound}` });
const uuid = randomUUID(), uuid = uuid || randomUUID();
email = uuid.split("-")[0]; email = email || uuid.split("-")[0];
if (expiryTime > 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; totalGB = totalGB * 1024 * 1024 * 1024;
@@ -25,20 +24,26 @@ module.exports = async (ctx) => {
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.obj || {}; const {remark, port, protocol, streamSettings = "{}"} = inbound.obj || {};
const { const setting = JSON.parse(streamSettings || "{}"), {network = "ws", security = "none"} = setting;
network = "ws", if (network === "ws") {
security = "none", const {wsSettings: {host, path}} = setting
wsSettings: { host, path },
} = JSON.parse(streamSettings);
ctx.body = { ctx.body = {
code: "0", code: "0", message: "success",
data: `${protocol}://${uuid}@vless.jjcp52.com:${port}?type=${network}&path=${path}&host=${host}&security=${security}#${remark}-${email}`, data: `${protocol}://${uuid}@vless.jjcp52.com:${port}?type=${network}&path=${path}&host=${host}&security=${security}#${remark}-${email}`,
message: "success",
}; };
} else if (network === "tcp") {
// 生成的链接格式 vless://842f52b6-4945-46c8-89ed-165bf51123fc@206.237.11.232:34261?type=tcp&security=reality&pbk=3-yeUp9rz5KacCLJqaLt_rHUY_6EKw6tveLpVB2hxQI&fp=random&sni=yahoo.com&sid=0f7f86d03b646595&spx=%2F#temu-reality-kubbo
const {serverNames: [sni], shortIds: [sid], settings: {publicKey, fingerprint, spiderX}} = (setting.realitySettings || {})
ctx.body = {
code: "0", message: "success",
data: `${protocol}://${uuid}@vless.jjcp52.com:${port}?type=${network}&security=${security}&pbk=${publicKey}&fp=${fingerprint}&sni=${sni}&sid=${sid}&spx=${spiderX}#${remark}-${email}`,
};
}
} else { } else {
ctx.body = { ctx.body = {
code: 1, code: 1,
message: "添加失败", message: "添加失败:" + result?.msg || "未知原因",
data: ctx.request.body, data: ctx.request.body,
}; };
} }

19
api/client/status.js Normal file
View File

@@ -0,0 +1,19 @@
const getCookie = require("../../auth/3xuiLogin");
const instance = require("../../utils/http");
module.exports = async (ctx) => {
let { id } = ctx.request.query;
if (!ctx.state.cookie) {
ctx.state.cookie = await getCookie();
instance.interceptors.request.use((config) => {
config.headers.Cookie = ctx.state.cookie;
return config;
});
}
const status = await instance.get(`/panel/api/inbounds/getClientTrafficsById/${id}`);
ctx.body = {
code: 0,
data: status.obj?.[0] || {},
msg: "success",
};
};

View File

@@ -1,3 +1,4 @@
module.exports = (token) => { module.exports = (token) => {
return { token, username: token }; const AUTH_TOKEN = process.env.AUTH_TOKEN || "pJENcyWA0eg47CsyBaztb2zCyx77D294";
return token === AUTH_TOKEN ? { token, username: "lsw" } : null;
}; };

1
index.js Normal file
View File

@@ -0,0 +1 @@
require("./app")

View File

@@ -1,11 +1,11 @@
{ {
"name": "vless-api", "name": "vless-api",
"version": "1.0.0", "version": "1.0.0",
"description": "", "main": "index.js",
"main": "app.js",
"scripts": { "scripts": {
"start": "node app.js", "start": "node index.js",
"dev": "nodemon app.js" "dev": "nodemon index.js",
"build": "pkg index.js --targets=node18-win-x64,node18-linux-x64 --output=dist/"
}, },
"author": "kubbo", "author": "kubbo",
"license": "ISC", "license": "ISC",