feat: 添加非 cnb-board 环境检查,更新相关路由返回值;更新版本号至 0.1.12,新增 common.ts 文件
This commit is contained in:
@@ -2,7 +2,17 @@ import { app } from '../../app.ts';
|
|||||||
import { useKey } from '@kevisual/context'
|
import { useKey } from '@kevisual/context'
|
||||||
import { getLiveMdContent } from './live/live-content.ts';
|
import { getLiveMdContent } from './live/live-content.ts';
|
||||||
import z from 'zod';
|
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({
|
app.route({
|
||||||
path: 'cnb_board',
|
path: 'cnb_board',
|
||||||
key: 'live',
|
key: 'live',
|
||||||
@@ -16,6 +26,7 @@ app.route({
|
|||||||
}).define(async (ctx) => {
|
}).define(async (ctx) => {
|
||||||
const more = ctx.query?.more ?? false
|
const more = ctx.query?.more ?? false
|
||||||
const list = getLiveMdContent({ more: more });
|
const list = getLiveMdContent({ more: more });
|
||||||
|
if (notCNBCheck(ctx)) return;
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
title: '开发环境模式配置',
|
title: '开发环境模式配置',
|
||||||
list,
|
list,
|
||||||
@@ -31,7 +42,8 @@ app.route({
|
|||||||
const repoSlug = useKey('CNB_REPO_SLUG') || '';
|
const repoSlug = useKey('CNB_REPO_SLUG') || '';
|
||||||
const repoName = useKey('CNB_REPO_NAME') || '';
|
const repoName = useKey('CNB_REPO_NAME') || '';
|
||||||
const repoId = useKey('CNB_REPO_ID') || '';
|
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 提取仓库名称
|
// 从 repoSlug 提取仓库名称
|
||||||
const repoNameFromSlug = repoSlug.split('/').pop() || '';
|
const repoNameFromSlug = repoSlug.split('/').pop() || '';
|
||||||
|
|
||||||
@@ -80,6 +92,7 @@ app.route({
|
|||||||
description: '获取cnb-board live的构建信息',
|
description: '获取cnb-board live的构建信息',
|
||||||
middleware: ['auth-admin']
|
middleware: ['auth-admin']
|
||||||
}).define(async (ctx) => {
|
}).define(async (ctx) => {
|
||||||
|
if (notCNBCheck(ctx)) return;
|
||||||
const labels = [
|
const labels = [
|
||||||
{
|
{
|
||||||
title: 'CNB_BUILD_ID',
|
title: 'CNB_BUILD_ID',
|
||||||
@@ -325,6 +338,7 @@ app.route({
|
|||||||
description: '获取cnb-board live的NPC信息',
|
description: '获取cnb-board live的NPC信息',
|
||||||
middleware: ['auth-admin']
|
middleware: ['auth-admin']
|
||||||
}).define(async (ctx) => {
|
}).define(async (ctx) => {
|
||||||
|
if (notCNBCheck(ctx)) return;
|
||||||
const labels = [
|
const labels = [
|
||||||
{
|
{
|
||||||
title: 'CNB_NPC_SLUG',
|
title: 'CNB_NPC_SLUG',
|
||||||
@@ -370,6 +384,7 @@ app.route({
|
|||||||
description: '获取cnb-board live的评论信息',
|
description: '获取cnb-board live的评论信息',
|
||||||
middleware: ['auth-admin']
|
middleware: ['auth-admin']
|
||||||
}).define(async (ctx) => {
|
}).define(async (ctx) => {
|
||||||
|
if (notCNBCheck(ctx)) return;
|
||||||
const labels = [
|
const labels = [
|
||||||
{
|
{
|
||||||
title: 'CNB_COMMENT_ID',
|
title: 'CNB_COMMENT_ID',
|
||||||
|
|||||||
0
assistant/src/routes/cnb-board/common.ts
Normal file
0
assistant/src/routes/cnb-board/common.ts
Normal file
@@ -65,47 +65,56 @@ export const getLiveMdContent = (opts?: { more?: boolean }) => {
|
|||||||
`
|
`
|
||||||
const labels = [
|
const labels = [
|
||||||
{
|
{
|
||||||
title: 'vscodeWebUrl',
|
key: 'vscodeWebUrl',
|
||||||
|
title: 'VSCode Web 地址',
|
||||||
value: vscodeWebUrl,
|
value: vscodeWebUrl,
|
||||||
description: 'VSCode Web 的访问地址'
|
description: 'VSCode Web 的访问地址'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'kevisualUrl',
|
key: 'kevisualUrl',
|
||||||
|
title: 'Kevisual 地址',
|
||||||
value: kevisualUrl,
|
value: kevisualUrl,
|
||||||
description: 'Kevisual 的访问地址,可以通过该地址访问 Kevisual 服务'
|
description: 'Kevisual 的访问地址,可以通过该地址访问 Kevisual 服务'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'cnbTempToken',
|
key: 'cnbTempToken',
|
||||||
|
title: 'CNB Token',
|
||||||
value: token,
|
value: token,
|
||||||
description: 'CNB 临时 Token,保持和环境变量 CNB_TOKEN 一致'
|
description: 'CNB 临时 Token,保持和环境变量 CNB_TOKEN 一致'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'openWebUrl',
|
key: 'openWebUrl',
|
||||||
|
title: 'OpenWebUI 地址',
|
||||||
value: openWebUrl,
|
value: openWebUrl,
|
||||||
description: 'OpenWebUI 的访问地址,可以通过该地址访问 OpenWebUI 服务'
|
description: 'OpenWebUI 的访问地址,可以通过该地址访问 OpenWebUI 服务'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'openclawUrl',
|
key: 'openclawUrl',
|
||||||
|
title: 'OpenClaw 地址',
|
||||||
value: openclawUrl,
|
value: openclawUrl,
|
||||||
description: 'OpenClaw 的访问地址,可以通过该地址访问 OpenClaw 服务'
|
description: 'OpenClaw 的访问地址,可以通过该地址访问 OpenClaw 服务'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'openclawUrlSecret',
|
key: 'openclawUrlSecret',
|
||||||
|
title: 'OpenClaw 访问地址(含 Token)',
|
||||||
value: openclawUrlSecret,
|
value: openclawUrlSecret,
|
||||||
description: 'OpenClaw 的访问地址,包含 token 参数,可以直接访问 OpenClaw 服务'
|
description: 'OpenClaw 的访问地址,包含 token 参数,可以直接访问 OpenClaw 服务'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'opencodeUrl',
|
key: 'opencodeUrl',
|
||||||
|
title: 'OpenCode 地址',
|
||||||
value: opencodeUrl,
|
value: opencodeUrl,
|
||||||
description: 'OpenCode 的访问地址,可以通过该地址访问 OpenCode 服务'
|
description: 'OpenCode 的访问地址,可以通过该地址访问 OpenCode 服务'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'opencodeUrlSecret',
|
key: 'opencodeUrlSecret',
|
||||||
|
title: 'OpenCode 访问地址(含 Token)',
|
||||||
value: opencodeUrlSecret,
|
value: opencodeUrlSecret,
|
||||||
description: 'OpenCode 的访问地址,包含 token 参数,可以直接访问 OpenCode 服务'
|
description: 'OpenCode 的访问地址,包含 token 参数,可以直接访问 OpenCode 服务'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'docs',
|
key: 'docs',
|
||||||
|
title: '配置说明文档',
|
||||||
value: TEMPLATE,
|
value: TEMPLATE,
|
||||||
description: '开发环境模式配置说明文档'
|
description: '开发环境模式配置说明文档'
|
||||||
}
|
}
|
||||||
@@ -117,7 +126,7 @@ export const getLiveMdContent = (opts?: { more?: boolean }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createOSInfo = (more = false) => {
|
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') || ''
|
const startTimer = useKey('CNB_BUILD_START_TIME') || ''
|
||||||
|
|
||||||
// CPU 使用率
|
// CPU 使用率
|
||||||
@@ -162,16 +171,17 @@ const createOSInfo = (more = false) => {
|
|||||||
return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i]
|
return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启动时间
|
|
||||||
const bootTime = os.uptime()
|
|
||||||
|
|
||||||
// 运行时间格式化
|
// 运行时间格式化
|
||||||
const formatUptime = (seconds: number) => {
|
const formatUptime = (seconds: number) => {
|
||||||
const days = Math.floor(seconds / 86400)
|
const days = Math.floor(seconds / 86400)
|
||||||
const hours = Math.floor((seconds % 86400) / 3600)
|
const hours = Math.floor((seconds % 86400) / 3600)
|
||||||
const minutes = Math.floor((seconds % 3600) / 60)
|
const minutes = Math.floor((seconds % 3600) / 60)
|
||||||
const secs = Math.floor(seconds % 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 命令,获取当前目录)
|
// 磁盘使用情况 (使用 du 命令,获取当前目录)
|
||||||
@@ -185,45 +195,47 @@ const createOSInfo = (more = false) => {
|
|||||||
|
|
||||||
labels.push(
|
labels.push(
|
||||||
{
|
{
|
||||||
title: 'cpuUsage',
|
key: 'cpuUsage',
|
||||||
|
title: 'CPU 使用率',
|
||||||
value: `${cpuUsage}%`,
|
value: `${cpuUsage}%`,
|
||||||
description: 'CPU 使用率'
|
description: 'CPU 使用率'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'cpuCores',
|
key: 'cpuCores',
|
||||||
|
title: 'CPU 核心数',
|
||||||
value: `${cpus.length}`,
|
value: `${cpus.length}`,
|
||||||
description: 'CPU 核心数'
|
description: 'CPU 核心数'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'memoryUsed',
|
key: 'memoryUsed',
|
||||||
|
title: '已使用内存',
|
||||||
value: formatBytes(memUsed),
|
value: formatBytes(memUsed),
|
||||||
description: '已使用内存'
|
description: '已使用内存'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'memoryTotal',
|
key: 'memoryTotal',
|
||||||
|
title: '总内存',
|
||||||
value: formatBytes(memTotal),
|
value: formatBytes(memTotal),
|
||||||
description: '总内存'
|
description: '总内存'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'memoryFree',
|
key: 'memoryFree',
|
||||||
|
title: '空闲内存',
|
||||||
value: formatBytes(memFree),
|
value: formatBytes(memFree),
|
||||||
description: '空闲内存'
|
description: '空闲内存'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'memoryUsage',
|
key: 'memoryUsage',
|
||||||
|
title: '内存使用率',
|
||||||
value: `${memUsage}%`,
|
value: `${memUsage}%`,
|
||||||
description: '内存使用率'
|
description: '内存使用率'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'diskUsage',
|
key: 'diskUsage',
|
||||||
|
title: '磁盘使用',
|
||||||
value: diskUsage,
|
value: diskUsage,
|
||||||
description: '当前目录磁盘使用情况'
|
description: '当前目录磁盘使用情况'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: 'uptime',
|
|
||||||
value: formatUptime(bootTime),
|
|
||||||
description: '系统运行时间'
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 如果有 CNB_BUILD_START_TIME,添加构建启动时间
|
// 如果有 CNB_BUILD_START_TIME,添加构建启动时间
|
||||||
@@ -237,12 +249,14 @@ const createOSInfo = (more = false) => {
|
|||||||
|
|
||||||
labels.push(
|
labels.push(
|
||||||
{
|
{
|
||||||
title: 'buildStartTime',
|
key: 'buildStartTime',
|
||||||
|
title: '构建启动时间',
|
||||||
value: buildStartTime,
|
value: buildStartTime,
|
||||||
description: '构建启动时间'
|
description: '构建启动时间'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'buildUptime',
|
key: 'buildUptime',
|
||||||
|
title: '构建已运行时间',
|
||||||
value: buildUptimeStr,
|
value: buildUptimeStr,
|
||||||
description: '构建已运行时间'
|
description: '构建已运行时间'
|
||||||
}
|
}
|
||||||
@@ -259,11 +273,13 @@ const createOSInfo = (more = false) => {
|
|||||||
const timeTo4Str = `[距离晚上4点重启时间: ${formatUptime(Math.floor(timeTo4 / 1000))}]`
|
const timeTo4Str = `[距离晚上4点重启时间: ${formatUptime(Math.floor(timeTo4 / 1000))}]`
|
||||||
|
|
||||||
labels.push({
|
labels.push({
|
||||||
title: 'buildMaxRunTime',
|
key: 'buildMaxRunTime',
|
||||||
|
title: '最大运行时间',
|
||||||
value: formatUptime(Math.floor(maxRunTime / 1000)),
|
value: formatUptime(Math.floor(maxRunTime / 1000)),
|
||||||
description: '构建最大运行时间(限制时间)'
|
description: '构建最大运行时间(限制时间)'
|
||||||
})
|
})
|
||||||
labels.unshift({
|
labels.unshift({
|
||||||
|
key: 'remainingTime',
|
||||||
title: '剩余时间',
|
title: '剩余时间',
|
||||||
value: formatUptime(Math.floor((maxRunTime - buildUptime) / 1000)) + ' ' + timeTo4Str,
|
value: formatUptime(Math.floor((maxRunTime - buildUptime) / 1000)) + ' ' + timeTo4Str,
|
||||||
description: '构建剩余时间'
|
description: '构建剩余时间'
|
||||||
@@ -276,37 +292,44 @@ const createOSInfo = (more = false) => {
|
|||||||
const loadavg = os.loadavg()
|
const loadavg = os.loadavg()
|
||||||
labels.push(
|
labels.push(
|
||||||
{
|
{
|
||||||
title: 'hostname',
|
key: 'hostname',
|
||||||
|
title: '主机名',
|
||||||
value: os.hostname(),
|
value: os.hostname(),
|
||||||
description: '主机名'
|
description: '主机名'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'platform',
|
key: 'platform',
|
||||||
|
title: '运行平台',
|
||||||
value: os.platform(),
|
value: os.platform(),
|
||||||
description: '运行平台'
|
description: '运行平台'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'arch',
|
key: 'arch',
|
||||||
|
title: '系统架构',
|
||||||
value: os.arch(),
|
value: os.arch(),
|
||||||
description: '系统架构'
|
description: '系统架构'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'osType',
|
key: 'osType',
|
||||||
|
title: '操作系统类型',
|
||||||
value: os.type(),
|
value: os.type(),
|
||||||
description: '操作系统类型'
|
description: '操作系统类型'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'loadavg1m',
|
key: 'loadavg1m',
|
||||||
|
title: '系统负载 (1分钟)',
|
||||||
value: loadavg[0].toFixed(2),
|
value: loadavg[0].toFixed(2),
|
||||||
description: '系统负载 (1分钟)'
|
description: '系统负载 (1分钟)'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'loadavg5m',
|
key: 'loadavg5m',
|
||||||
|
title: '系统负载 (5分钟)',
|
||||||
value: loadavg[1].toFixed(2),
|
value: loadavg[1].toFixed(2),
|
||||||
description: '系统负载 (5分钟)'
|
description: '系统负载 (5分钟)'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'loadavg15m',
|
key: 'loadavg15m',
|
||||||
|
title: '系统负载 (15分钟)',
|
||||||
value: loadavg[2].toFixed(2),
|
value: loadavg[2].toFixed(2),
|
||||||
description: '系统负载 (15分钟)'
|
description: '系统负载 (15分钟)'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/cli",
|
"name": "@kevisual/cli",
|
||||||
"version": "0.1.11",
|
"version": "0.1.12",
|
||||||
"description": "envision 命令行工具",
|
"description": "envision 命令行工具",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"basename": "/root/cli",
|
"basename": "/root/cli",
|
||||||
|
|||||||
Reference in New Issue
Block a user