feat: 重构CNB管理模块,添加清理记录功能,更新中间件为统一认证方式,优化工作空间相关路由

This commit is contained in:
xiongxiao
2026-03-09 18:54:33 +08:00
committed by cnb
parent 21ba07e55b
commit 382c4809ea
25 changed files with 296 additions and 73 deletions

View File

@@ -1,5 +1,5 @@
import { tool } from '@kevisual/router';
import { app, cnb } from '../../app.ts';
import { app, cnbManager, notCNBCheck } from '../../app.ts';
import { addKeepAliveData, KeepAliveData, removeKeepAliveData, createLiveData } from '../../../src/workspace/keep-file-live.ts';
import { useKey } from '@kevisual/context';
@@ -8,7 +8,7 @@ app.route({
path: 'cnb',
key: 'keep-workspace-alive',
description: '保持工作空间存活技能参数repo:代码仓库路径,例如 user/repopipelineId:流水线ID例如 cnb-708-1ji9sog7o-001',
middleware: ['auth-admin'],
middleware: ['auth'],
metadata: {
tags: [],
...({
@@ -19,9 +19,11 @@ app.route({
})
}
}).define(async (ctx) => {
const cnb = await cnbManager.getContext(ctx);
const repo = ctx.query?.repo as string;
const pipelineId = ctx.query?.pipelineId as string;
if (notCNBCheck(ctx)) return;
if (!repo || !pipelineId) {
ctx.throw(400, '缺少参数 repo 或 pipelineId');
}
@@ -51,7 +53,7 @@ app.route({
path: 'cnb',
key: 'stop-keep-workspace-alive',
description: '停止保持工作空间存活技能, 参数repo:代码仓库路径,例如 user/repopipelineId:流水线ID例如 cnb-708-1ji9sog7o-001',
middleware: ['auth-admin'],
middleware: ['auth'],
metadata: {
tags: [],
...({
@@ -62,6 +64,7 @@ app.route({
})
}
}).define(async (ctx) => {
if (notCNBCheck(ctx)) return;
const repo = ctx.query?.repo as string;
const pipelineId = ctx.query?.pipelineId as string;
@@ -79,7 +82,7 @@ app.route({
path: 'cnb',
key: 'keep-alive-current-workspace',
description: '保持当前工作空间存活技能',
middleware: ['auth-admin'],
middleware: ['auth'],
metadata: {
tags: ['opencode'],
skill: 'keep-alive-current-workspace',
@@ -87,6 +90,7 @@ app.route({
summary: '保持当前工作空间存活,防止被关闭或释放资源',
}
}).define(async (ctx) => {
if (notCNBCheck(ctx)) return;
const pipelineId = useKey('CNB_PIPELINE_ID');
const repo = useKey('CNB_REPO_SLUG_LOWERCASE');
if (!pipelineId || !repo) {