50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { app, cnbManager } from '../../app.ts';
|
||
|
||
// "列出我的代码仓库,search blog"
|
||
// 列出我的知识库的代码仓库
|
||
app.route({
|
||
path: 'cnb',
|
||
key: 'clear-me-manager',
|
||
description: '清理我的cnb-manager记录',
|
||
middleware: ['auth'],
|
||
|
||
}).define(async (ctx) => {
|
||
const tokenUser = ctx.state?.tokenUser;
|
||
if (!tokenUser) {
|
||
ctx.throw(401, '未授权');
|
||
}
|
||
const username = tokenUser.username;
|
||
if (!username) {
|
||
ctx.throw(400, '无效的用户信息');
|
||
}
|
||
if (username !== 'default') {
|
||
cnbManager.clearUsername(username);
|
||
}
|
||
ctx.body = { content: '已清理cnb-manager记录' };
|
||
}).addTo(app);
|
||
|
||
app.route({
|
||
path: 'cnb',
|
||
key: 'get-my-config',
|
||
description: '获取我的cnb配置',
|
||
middleware: ['auth'],
|
||
}).define(async (ctx) => {
|
||
const tokenUser = ctx.state?.tokenUser;
|
||
const username = 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);
|