Files
cnb/agent/routes/cnb-env/check.ts

44 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: ['admin-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);