feat: 添加非 cnb-board 环境检查,更新相关路由返回值;更新版本号至 0.1.12,新增 common.ts 文件

This commit is contained in:
2026-02-24 23:44:05 +08:00
parent d3104bd5a5
commit 37e00a9ff3
4 changed files with 77 additions and 39 deletions

View File

@@ -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',

View File

View File

@@ -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分钟)'
}

View File

@@ -1,6 +1,6 @@
{
"name": "@kevisual/cli",
"version": "0.1.11",
"version": "0.1.12",
"description": "envision 命令行工具",
"type": "module",
"basename": "/root/cli",