feat(cnb-env): 添加用户登录状态检查路由,更新版本至 0.0.7,移除旧的用户检查路由

This commit is contained in:
2026-01-29 13:34:04 +08:00
parent 86b24cc9ef
commit 5db3b4a51b
3 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
import { createSkill } from '@kevisual/router';
import { app, cnb } from '../../app.ts';
import { tool } from '@opencode-ai/plugin/tool';
app.route({
path: 'cnb',
key: 'user-check',
description: '检查用户登录状态参数checkToken,default true; checkCookie, default false',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'cnb-login-verify',
title: 'CNB 登录验证信息',
summary: '验证 CNB 登录信息是否有效',
args: {
checkToken: tool.schema.boolean().describe('是否检查 Token 的有效性').default(true),
checkCookie: tool.schema.boolean().describe('是否检查 Cookie 的有效性').default(false),
},
})
}
}).define(async (ctx) => {
const checkToken = ctx.query?.checkToken ?? true;
const checkCookie = ctx.query?.checkCookie ?? false;
let content = '';
if (checkToken) {
const res = await cnb.user.getUser();
if (res?.code !== 200) {
content += `Token 无效,请检查 CNB_TOKEN 配置。\n`;
} else {
content += `Token 有效Token用户昵称${res.data?.nickname}\n`;
}
}
if (checkCookie) {
const res = await cnb.user.getCurrentUser();
if (res?.code !== 200) {
content += `Cookie 无效,请检查 CNB_COOKIE 配置。\n`;
} else {
content += `Cookie 有效当前Cookie用户${res.data?.nickname}\n`;
}
}
ctx.body = { content };
}).addTo(app);