44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
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); |