feat: 更新获取CNB配置的路由,优化参数处理并添加错误处理
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user