This commit is contained in:
xiongxiao
2026-01-16 02:30:21 +08:00
parent fc7a75b154
commit d85f42d38b
7 changed files with 83 additions and 36 deletions

View File

@@ -1,4 +1,6 @@
import { createSkill } from '@kevisual/router';
import { app, cnb } from '../../app.ts';
import { tool } from '@opencode-ai/plugin/tool';
app.route({
@@ -7,27 +9,36 @@ app.route({
description: '检查用户登录状态参数checkToken,default true; checkCookie, default false',
middleware: ['auth'],
metadata: {
tags: ['opencode']
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 output = '';
let content = '';
if (checkToken) {
const res = await cnb.user.getUser();
if (res?.code !== 200) {
output += `Token 无效,请检查 CNB_TOKEN 配置。\n`;
content += `Token 无效,请检查 CNB_TOKEN 配置。\n`;
} else {
output += `Token 有效Token用户昵称${res.data?.nickname}\n`;
content += `Token 有效Token用户昵称${res.data?.nickname}\n`;
}
}
if (checkCookie) {
const res = await cnb.user.getCurrentUser();
if (res?.code !== 200) {
output += `Cookie 无效,请检查 CNB_COOKIE 配置。\n`;
content += `Cookie 无效,请检查 CNB_COOKIE 配置。\n`;
} else {
output += `Cookie 有效当前Cookie用户${res.data?.nickname}\n`;
content += `Cookie 有效当前Cookie用户${res.data?.nickname}\n`;
}
}
ctx.body = { output };
ctx.body = { content };
}).addTo(app);