feat: 更新获取CNB配置的路由,优化参数处理并添加错误处理

This commit is contained in:
xiongxiao
2026-03-09 19:13:20 +08:00
committed by cnb
parent a40c2352bf
commit 7d227d3913
3 changed files with 27 additions and 6 deletions

View File

@@ -45,10 +45,7 @@ export class CNBManager {
return cnbItem
}
async getCNB(opts?: { username?: string, kevisualToken?: string }): Promise<CNBItem | null> {
if (opts?.username) {
return this.getDefaultCNB()
}
const username = opts?.kevisualToken
const username = opts?.username
const cnbItem = this.cnbMap.get(username)
if (cnbItem) {
cnbItem.runAt = Date.now()

View File

@@ -21,4 +21,28 @@ app.route({
cnbManager.clearUsername(username);
}
ctx.body = { content: '已清理cnb-manager记录' };
}).addTo(app);
}).addTo(app);
app.route({
path: 'cnb',
key: 'get-my-config',
description: '获取我的cnb配置',
middleware: ['auth'],
}).define(async (ctx) => {
const username = ctx.tokenUser?.username;
const token = ctx.query?.token;
if (!username) {
ctx.throw(400, '未授权');
}
if (!token) {
ctx.throw(400, '缺少token参数');
}
const cnbItem = await cnbManager.getCNB({ username, kevisualToken: token });
if (!cnbItem) {
ctx.throw(404, '未找到cnb-manager记录');
}
ctx.body = {
token: cnbItem.token,
cookie: cnbItem.cookie,
}
}).addTo(app);

View File

@@ -1,6 +1,6 @@
{
"name": "@kevisual/cnb",
"version": "0.0.38",
"version": "0.0.39",
"description": "",
"main": "index.js",
"basename": "/root/cnb",