feat: 重构CNB管理模块,添加清理记录功能,更新中间件为统一认证方式,优化工作空间相关路由
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createSkill } from '@kevisual/router';
|
||||
import { app, cnb } from '../../app.ts';
|
||||
import { app, cnbManager } from '../../app.ts';
|
||||
import { tool } from '@opencode-ai/plugin/tool';
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ app.route({
|
||||
path: 'cnb',
|
||||
key: 'user-check',
|
||||
description: '检查用户登录状态,参数checkToken,default true; checkCookie, default false',
|
||||
middleware: ['auth-admin'],
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
@@ -24,6 +24,7 @@ app.route({
|
||||
const checkToken = ctx.query?.checkToken ?? true;
|
||||
const checkCookie = ctx.query?.checkCookie ?? false;
|
||||
let content = '';
|
||||
const cnb = await cnbManager.getContext(ctx);
|
||||
if (checkToken) {
|
||||
const res = await cnb.user.getUser();
|
||||
if (res?.code !== 200) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { createSkill, tool } from '@kevisual/router';
|
||||
import { app, cnb } from '../../app.ts';
|
||||
import { app, cnbManager } from '../../app.ts';
|
||||
|
||||
// 设置 CNB_COOKIE环境变量和获取环境变量,用于界面操作定制模块功能
|
||||
app.route({
|
||||
path: 'cnb',
|
||||
key: 'set-cnb-cookie',
|
||||
description: '设置当前cnb工作空间的cookie环境变量',
|
||||
middleware: ['auth-admin'],
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
@@ -19,6 +19,7 @@ app.route({
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const cnb = await cnbManager.getContext(ctx);
|
||||
const cookie = ctx.query?.cookie;
|
||||
if (!cookie) {
|
||||
ctx.body = { content: '请提供有效的cookie值' };
|
||||
@@ -33,7 +34,7 @@ app.route({
|
||||
path: 'cnb',
|
||||
key: 'get-cnb-cookie',
|
||||
description: '获取当前cnb工作空间的cookie环境变量',
|
||||
middleware: ['auth-admin'],
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
@@ -43,6 +44,7 @@ app.route({
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const cnb = await cnbManager.getContext(ctx);
|
||||
const cookie = cnb.cookie || '未设置cookie环境变量';
|
||||
ctx.body = { content: `当前cnb工作空间的cookie环境变量为:${cookie}` };
|
||||
}).addTo(app);
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createSkill, tool } from '@kevisual/router';
|
||||
import { app, cnb } from '../../app.ts';
|
||||
import { app, notCNBCheck } from '../../app.ts';
|
||||
|
||||
import { CNB_ENV } from "@/common/cnb-env.ts";
|
||||
|
||||
@@ -11,7 +11,7 @@ app.route({
|
||||
path: 'cnb',
|
||||
key: 'get-cnb-port-uri',
|
||||
description: '获取当前cnb工作空间的port代理uri',
|
||||
middleware: ['auth-admin'],
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
@@ -24,6 +24,7 @@ app.route({
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
if (notCNBCheck(ctx)) return;
|
||||
const port = ctx.query?.port || 51515;
|
||||
const uri = CNB_ENV?.CNB_VSCODE_PROXY_URI as string || '';
|
||||
const finalUri = uri.replace('{{port}}', port.toString());
|
||||
@@ -40,7 +41,7 @@ app.route({
|
||||
path: 'cnb',
|
||||
key: 'get-cnb-vscode-uri',
|
||||
description: '获取当前cnb工作空间的vscode代理uri, 包括多种访问方式, 如web、vscode、codebuddy、cursor、ssh',
|
||||
middleware: ['auth-admin'],
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
tags: ['opencode'],
|
||||
...createSkill({
|
||||
@@ -58,6 +59,7 @@ app.route({
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
if (notCNBCheck(ctx)) return;
|
||||
const web = ctx.query?.web ?? false;
|
||||
const vscode = ctx.query?.vscode ?? true; // 默认true
|
||||
const codebuddy = ctx.query?.codebuddy ?? false;
|
||||
|
||||
Reference in New Issue
Block a user