From 37e00a9ff3cb3b1deee37beb74dd9e81b8ec01e5 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Tue, 24 Feb 2026 23:44:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=9D=9E=20cnb-board?= =?UTF-8?q?=20=E7=8E=AF=E5=A2=83=E6=A3=80=E6=9F=A5=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=9B=B8=E5=85=B3=E8=B7=AF=E7=94=B1=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=EF=BC=9B=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E8=87=B3=200.1.12=EF=BC=8C=E6=96=B0=E5=A2=9E=20common.ts=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assistant/src/routes/cnb-board/cnb-dev-env.ts | 19 +++- assistant/src/routes/cnb-board/common.ts | 0 .../src/routes/cnb-board/live/live-content.ts | 95 ++++++++++++------- package.json | 2 +- 4 files changed, 77 insertions(+), 39 deletions(-) create mode 100644 assistant/src/routes/cnb-board/common.ts diff --git a/assistant/src/routes/cnb-board/cnb-dev-env.ts b/assistant/src/routes/cnb-board/cnb-dev-env.ts index adc5330..8f9c010 100644 --- a/assistant/src/routes/cnb-board/cnb-dev-env.ts +++ b/assistant/src/routes/cnb-board/cnb-dev-env.ts @@ -2,7 +2,17 @@ import { app } from '../../app.ts'; import { useKey } from '@kevisual/context' import { getLiveMdContent } from './live/live-content.ts'; import z from 'zod'; - +const notCNBCheck = (ctx: any) => { + const isCNB = useKey('CNB'); + if (!isCNB) { + ctx.body = { + title: '非 cnb-board 环境', + list: [] + } + return true; + } + return false; +} app.route({ path: 'cnb_board', key: 'live', @@ -16,6 +26,7 @@ app.route({ }).define(async (ctx) => { const more = ctx.query?.more ?? false const list = getLiveMdContent({ more: more }); + if (notCNBCheck(ctx)) return; ctx.body = { title: '开发环境模式配置', list, @@ -31,7 +42,8 @@ app.route({ const repoSlug = useKey('CNB_REPO_SLUG') || ''; const repoName = useKey('CNB_REPO_NAME') || ''; const repoId = useKey('CNB_REPO_ID') || ''; - const repoUrlHttps = useKey('CNB_REPO_URL_HTTPS') || ''; + const repoUrlHttps = useKey('CNB_REPO_UR if (notCNBCheck(ctx)) return;L_HTTPS') || ''; + if (notCNBCheck(ctx)) return; // 从 repoSlug 提取仓库名称 const repoNameFromSlug = repoSlug.split('/').pop() || ''; @@ -80,6 +92,7 @@ app.route({ description: '获取cnb-board live的构建信息', middleware: ['auth-admin'] }).define(async (ctx) => { + if (notCNBCheck(ctx)) return; const labels = [ { title: 'CNB_BUILD_ID', @@ -325,6 +338,7 @@ app.route({ description: '获取cnb-board live的NPC信息', middleware: ['auth-admin'] }).define(async (ctx) => { + if (notCNBCheck(ctx)) return; const labels = [ { title: 'CNB_NPC_SLUG', @@ -370,6 +384,7 @@ app.route({ description: '获取cnb-board live的评论信息', middleware: ['auth-admin'] }).define(async (ctx) => { + if (notCNBCheck(ctx)) return; const labels = [ { title: 'CNB_COMMENT_ID', diff --git a/assistant/src/routes/cnb-board/common.ts b/assistant/src/routes/cnb-board/common.ts new file mode 100644 index 0000000..e69de29 diff --git a/assistant/src/routes/cnb-board/live/live-content.ts b/assistant/src/routes/cnb-board/live/live-content.ts index 650f787..09e18c5 100644 --- a/assistant/src/routes/cnb-board/live/live-content.ts +++ b/assistant/src/routes/cnb-board/live/live-content.ts @@ -65,47 +65,56 @@ export const getLiveMdContent = (opts?: { more?: boolean }) => { ` const labels = [ { - title: 'vscodeWebUrl', + key: 'vscodeWebUrl', + title: 'VSCode Web 地址', value: vscodeWebUrl, description: 'VSCode Web 的访问地址' }, { - title: 'kevisualUrl', + key: 'kevisualUrl', + title: 'Kevisual 地址', value: kevisualUrl, description: 'Kevisual 的访问地址,可以通过该地址访问 Kevisual 服务' }, { - title: 'cnbTempToken', + key: 'cnbTempToken', + title: 'CNB Token', value: token, description: 'CNB 临时 Token,保持和环境变量 CNB_TOKEN 一致' }, { - title: 'openWebUrl', + key: 'openWebUrl', + title: 'OpenWebUI 地址', value: openWebUrl, description: 'OpenWebUI 的访问地址,可以通过该地址访问 OpenWebUI 服务' }, { - title: 'openclawUrl', + key: 'openclawUrl', + title: 'OpenClaw 地址', value: openclawUrl, description: 'OpenClaw 的访问地址,可以通过该地址访问 OpenClaw 服务' }, { - title: 'openclawUrlSecret', + key: 'openclawUrlSecret', + title: 'OpenClaw 访问地址(含 Token)', value: openclawUrlSecret, description: 'OpenClaw 的访问地址,包含 token 参数,可以直接访问 OpenClaw 服务' }, { - title: 'opencodeUrl', + key: 'opencodeUrl', + title: 'OpenCode 地址', value: opencodeUrl, description: 'OpenCode 的访问地址,可以通过该地址访问 OpenCode 服务' }, { - title: 'opencodeUrlSecret', + key: 'opencodeUrlSecret', + title: 'OpenCode 访问地址(含 Token)', value: opencodeUrlSecret, description: 'OpenCode 的访问地址,包含 token 参数,可以直接访问 OpenCode 服务' }, { - title: 'docs', + key: 'docs', + title: '配置说明文档', value: TEMPLATE, description: '开发环境模式配置说明文档' } @@ -117,7 +126,7 @@ export const getLiveMdContent = (opts?: { more?: boolean }) => { } const createOSInfo = (more = false) => { - const labels: Array<{ title: string; value: string; description: string }> = [] + const labels: Array<{ key: string; title: string; value: string; description: string }> = [] const startTimer = useKey('CNB_BUILD_START_TIME') || '' // CPU 使用率 @@ -162,16 +171,17 @@ const createOSInfo = (more = false) => { return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i] } - // 启动时间 - const bootTime = os.uptime() - // 运行时间格式化 const formatUptime = (seconds: number) => { const days = Math.floor(seconds / 86400) const hours = Math.floor((seconds % 86400) / 3600) const minutes = Math.floor((seconds % 3600) / 60) const secs = Math.floor(seconds % 60) - return `${days}天 ${hours}小时 ${minutes}分钟 ${secs}秒` + let uptimeStr = '' + if (days > 0) uptimeStr += `${days}天 ` + if (hours > 0) uptimeStr += `${hours}小时 ` + if (minutes > 0) uptimeStr += `${minutes}分钟 ` + return `${uptimeStr}${secs}秒` } // 磁盘使用情况 (使用 du 命令,获取当前目录) @@ -185,45 +195,47 @@ const createOSInfo = (more = false) => { labels.push( { - title: 'cpuUsage', + key: 'cpuUsage', + title: 'CPU 使用率', value: `${cpuUsage}%`, description: 'CPU 使用率' }, { - title: 'cpuCores', + key: 'cpuCores', + title: 'CPU 核心数', value: `${cpus.length}`, description: 'CPU 核心数' }, { - title: 'memoryUsed', + key: 'memoryUsed', + title: '已使用内存', value: formatBytes(memUsed), description: '已使用内存' }, { - title: 'memoryTotal', + key: 'memoryTotal', + title: '总内存', value: formatBytes(memTotal), description: '总内存' }, { - title: 'memoryFree', + key: 'memoryFree', + title: '空闲内存', value: formatBytes(memFree), description: '空闲内存' }, { - title: 'memoryUsage', + key: 'memoryUsage', + title: '内存使用率', value: `${memUsage}%`, description: '内存使用率' }, { - title: 'diskUsage', + key: 'diskUsage', + title: '磁盘使用', value: diskUsage, description: '当前目录磁盘使用情况' }, - { - title: 'uptime', - value: formatUptime(bootTime), - description: '系统运行时间' - } ) // 如果有 CNB_BUILD_START_TIME,添加构建启动时间 @@ -237,12 +249,14 @@ const createOSInfo = (more = false) => { labels.push( { - title: 'buildStartTime', + key: 'buildStartTime', + title: '构建启动时间', value: buildStartTime, description: '构建启动时间' }, { - title: 'buildUptime', + key: 'buildUptime', + title: '构建已运行时间', value: buildUptimeStr, description: '构建已运行时间' } @@ -259,11 +273,13 @@ const createOSInfo = (more = false) => { const timeTo4Str = `[距离晚上4点重启时间: ${formatUptime(Math.floor(timeTo4 / 1000))}]` labels.push({ - title: 'buildMaxRunTime', + key: 'buildMaxRunTime', + title: '最大运行时间', value: formatUptime(Math.floor(maxRunTime / 1000)), description: '构建最大运行时间(限制时间)' }) labels.unshift({ + key: 'remainingTime', title: '剩余时间', value: formatUptime(Math.floor((maxRunTime - buildUptime) / 1000)) + ' ' + timeTo4Str, description: '构建剩余时间' @@ -276,37 +292,44 @@ const createOSInfo = (more = false) => { const loadavg = os.loadavg() labels.push( { - title: 'hostname', + key: 'hostname', + title: '主机名', value: os.hostname(), description: '主机名' }, { - title: 'platform', + key: 'platform', + title: '运行平台', value: os.platform(), description: '运行平台' }, { - title: 'arch', + key: 'arch', + title: '系统架构', value: os.arch(), description: '系统架构' }, { - title: 'osType', + key: 'osType', + title: '操作系统类型', value: os.type(), description: '操作系统类型' }, { - title: 'loadavg1m', + key: 'loadavg1m', + title: '系统负载 (1分钟)', value: loadavg[0].toFixed(2), description: '系统负载 (1分钟)' }, { - title: 'loadavg5m', + key: 'loadavg5m', + title: '系统负载 (5分钟)', value: loadavg[1].toFixed(2), description: '系统负载 (5分钟)' }, { - title: 'loadavg15m', + key: 'loadavg15m', + title: '系统负载 (15分钟)', value: loadavg[2].toFixed(2), description: '系统负载 (15分钟)' } diff --git a/package.json b/package.json index 15309b1..c82b7a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cli", - "version": "0.1.11", + "version": "0.1.12", "description": "envision 命令行工具", "type": "module", "basename": "/root/cli",