feat: 更新依赖版本,添加 cnb-board 环境检查功能
This commit is contained in:
@@ -49,7 +49,7 @@
|
|||||||
"@kevisual/local-app-manager": "^0.1.32",
|
"@kevisual/local-app-manager": "^0.1.32",
|
||||||
"@kevisual/logger": "^0.0.4",
|
"@kevisual/logger": "^0.0.4",
|
||||||
"@kevisual/query": "0.0.49",
|
"@kevisual/query": "0.0.49",
|
||||||
"@kevisual/router": "^0.0.83",
|
"@kevisual/router": "^0.0.84",
|
||||||
"@kevisual/types": "^0.0.12",
|
"@kevisual/types": "^0.0.12",
|
||||||
"@kevisual/use-config": "^1.0.30",
|
"@kevisual/use-config": "^1.0.30",
|
||||||
"@opencode-ai/plugin": "^1.2.10",
|
"@opencode-ai/plugin": "^1.2.10",
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ app.route({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
}).define(async (ctx) => {
|
}).define(async (ctx) => {
|
||||||
const { path, key = '' } = ctx.query;
|
const { path, key = '' } = ctx.args;
|
||||||
if (!path) {
|
if (!path) {
|
||||||
ctx.throw('路径path不能为空');
|
ctx.throw('路径path不能为空');
|
||||||
}
|
}
|
||||||
const res = await ctx.run({ path, key, payload: ctx.query.payload || {} }, {
|
const res = await ctx.run({ path, key, payload: ctx.args.payload || {} }, {
|
||||||
...ctx
|
...ctx
|
||||||
});
|
});
|
||||||
ctx.forward(res);
|
ctx.forward(res);
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ app.route({
|
|||||||
title: '查看客户端 IP 地址',
|
title: '查看客户端 IP 地址',
|
||||||
summary: '获取当前客户端的 IP 地址信息',
|
summary: '获取当前客户端的 IP 地址信息',
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
|
middleware: ['auth-admin']
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const networkInterfaces = os.networkInterfaces();
|
const networkInterfaces = os.networkInterfaces();
|
||||||
|
|||||||
@@ -76,10 +76,6 @@ app.route({
|
|||||||
message: '客户端重启命令已执行',
|
message: '客户端重启命令已执行',
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ctx.status = 500;
|
ctx.throw(500, '重启客户端失败');
|
||||||
ctx.body = {
|
|
||||||
message: '重启客户端失败',
|
|
||||||
error: error.message,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}).addTo(app);
|
}).addTo(app);
|
||||||
|
|||||||
@@ -3,6 +3,20 @@ import { getLiveMdContent } from './live/live-content.ts';
|
|||||||
import './cnb-dev-env.ts';
|
import './cnb-dev-env.ts';
|
||||||
import z from 'zod';
|
import z from 'zod';
|
||||||
import { execCommand } from '@/module/npm-install.ts';
|
import { execCommand } from '@/module/npm-install.ts';
|
||||||
|
import { useKey } from '@kevisual/context';
|
||||||
|
|
||||||
|
app.route({
|
||||||
|
path: 'cnb-board',
|
||||||
|
key: 'is-cnb-board',
|
||||||
|
description: '检查是否是 cnb-board 环境',
|
||||||
|
middleware: ['auth-admin']
|
||||||
|
}).define(async (ctx) => {
|
||||||
|
const isCNB = useKey('CNB');
|
||||||
|
ctx.body = {
|
||||||
|
isCNB: !!isCNB,
|
||||||
|
};
|
||||||
|
}).addTo(app);
|
||||||
|
|
||||||
app.route({
|
app.route({
|
||||||
path: 'cnb-board',
|
path: 'cnb-board',
|
||||||
key: 'live',
|
key: 'live',
|
||||||
|
|||||||
1
assistant/src/routes/cnb-board/modules/index.ts
Normal file
1
assistant/src/routes/cnb-board/modules/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './is-cnb.ts';
|
||||||
6
assistant/src/routes/cnb-board/modules/is-cnb.ts
Normal file
6
assistant/src/routes/cnb-board/modules/is-cnb.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { useKey } from "@kevisual/context";
|
||||||
|
|
||||||
|
export const isCnb = () => {
|
||||||
|
const CNB = useKey('CNB');
|
||||||
|
return !!CNB;
|
||||||
|
}
|
||||||
@@ -9,11 +9,13 @@ import type { WebSocketListenerFun } from "@kevisual/router";
|
|||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
import { renderNoAuthAndLogin } from '@/module/assistant/html/login.ts';
|
import { renderNoAuthAndLogin } from '@/module/assistant/html/login.ts';
|
||||||
import { LiveCode } from '@/module/livecode/index.ts';
|
import { LiveCode } from '@/module/livecode/index.ts';
|
||||||
|
import { isCnb } from '@/routes/cnb-board/modules/is-cnb.ts';
|
||||||
|
import { is } from 'zod/v4/locales';
|
||||||
const localProxy = new LocalProxy({});
|
const localProxy = new LocalProxy({});
|
||||||
localProxy.initFromAssistantConfig(assistantConfig);
|
localProxy.initFromAssistantConfig(assistantConfig);
|
||||||
|
|
||||||
const isOpenPath = (pathname: string): boolean => {
|
const isOpenPath = (pathname: string): boolean => {
|
||||||
const openPaths = ['/root/home', '/root/cli', '/root/login'];
|
const openPaths = ['/root/home', '/root/cli', '/root/login', '/root/cli-center'];
|
||||||
for (const openPath of openPaths) {
|
for (const openPath of openPaths) {
|
||||||
if (pathname.startsWith(openPath)) {
|
if (pathname.startsWith(openPath)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -81,12 +83,24 @@ const authFilter = async (req: http.IncomingMessage, res: http.ServerResponse) =
|
|||||||
}
|
}
|
||||||
export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||||
const _assistantConfig = assistantConfig.getCacheAssistantConfig();
|
const _assistantConfig = assistantConfig.getCacheAssistantConfig();
|
||||||
const home = _assistantConfig?.home || '/root/home';
|
let home = _assistantConfig?.home
|
||||||
const auth = _assistantConfig?.auth || {};
|
const auth = _assistantConfig?.auth || {};
|
||||||
|
// 没有管理员,需要去登陆
|
||||||
let noAdmin = !auth.username;
|
let noAdmin = !auth.username;
|
||||||
|
if (!home) {
|
||||||
|
if (isCnb()) {
|
||||||
|
home = '/root/cli-center/cnb-board'
|
||||||
|
} else {
|
||||||
|
home = '/root/cli-center/';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!home.startsWith('/')) {
|
||||||
|
home = '/' + home;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const toSetting = () => {
|
const toLogin = (redirect?: string) => {
|
||||||
res.writeHead(302, { Location: `/root/cli-center/` });
|
res.writeHead(302, { Location: `/root/login/` + (redirect ? `?redirect=${encodeURIComponent(redirect)}` : '') });
|
||||||
res.end();
|
res.end();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -94,10 +108,11 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
|
|||||||
const pathname = decodeURIComponent(url.pathname);
|
const pathname = decodeURIComponent(url.pathname);
|
||||||
if (pathname === '/') {
|
if (pathname === '/') {
|
||||||
if (noAdmin) {
|
if (noAdmin) {
|
||||||
return toSetting();
|
return toLogin(home + '/');
|
||||||
}
|
}
|
||||||
res.writeHead(302, { Location: `${home}/` });
|
res.writeHead(302, { Location: home });
|
||||||
return res.end();
|
res.end();
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if (pathname.startsWith('/favicon.ico')) {
|
if (pathname.startsWith('/favicon.ico')) {
|
||||||
res.statusCode = 404;
|
res.statusCode = 404;
|
||||||
@@ -162,8 +177,9 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
|
|||||||
}
|
}
|
||||||
const isOpen = isOpenPath(pathname)
|
const isOpen = isOpenPath(pathname)
|
||||||
logger.debug('proxyRoute', { _user, _app, pathname, noAdmin, isOpen });
|
logger.debug('proxyRoute', { _user, _app, pathname, noAdmin, isOpen });
|
||||||
|
// 没有管理员,且不是开放路径,去登录
|
||||||
if (noAdmin && !isOpen) {
|
if (noAdmin && !isOpen) {
|
||||||
return toSetting();
|
return toLogin();
|
||||||
}
|
}
|
||||||
if (_app && urls.length === 3) {
|
if (_app && urls.length === 3) {
|
||||||
// 重定向到
|
// 重定向到
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/cli",
|
"name": "@kevisual/cli",
|
||||||
"version": "0.1.9",
|
"version": "0.1.10",
|
||||||
"description": "envision 命令行工具",
|
"description": "envision 命令行工具",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"basename": "/root/cli",
|
"basename": "/root/cli",
|
||||||
|
|||||||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -185,8 +185,8 @@ importers:
|
|||||||
specifier: 0.0.49
|
specifier: 0.0.49
|
||||||
version: 0.0.49
|
version: 0.0.49
|
||||||
'@kevisual/router':
|
'@kevisual/router':
|
||||||
specifier: ^0.0.83
|
specifier: ^0.0.84
|
||||||
version: 0.0.83
|
version: 0.0.84
|
||||||
'@kevisual/types':
|
'@kevisual/types':
|
||||||
specifier: ^0.0.12
|
specifier: ^0.0.12
|
||||||
version: 0.0.12
|
version: 0.0.12
|
||||||
@@ -1363,8 +1363,8 @@ packages:
|
|||||||
'@kevisual/router@0.0.80':
|
'@kevisual/router@0.0.80':
|
||||||
resolution: {integrity: sha512-rVwi6Yf411bnNm2x94lMm+s4Csw0Yb7u/aj+VJJ59iouAYhjLuL7Rs1EcARhnQf47cegBJi6zozfGHgLsLHN2w==}
|
resolution: {integrity: sha512-rVwi6Yf411bnNm2x94lMm+s4Csw0Yb7u/aj+VJJ59iouAYhjLuL7Rs1EcARhnQf47cegBJi6zozfGHgLsLHN2w==}
|
||||||
|
|
||||||
'@kevisual/router@0.0.83':
|
'@kevisual/router@0.0.84':
|
||||||
resolution: {integrity: sha512-CVazzM1rXVyvU7QcMQr0/EuqacRNEGalThDDLGQcvKEVHyduJ9yWddn6kezgWFCpNlPKhzSCKkIFuZVixNVxDQ==}
|
resolution: {integrity: sha512-l/TUFuqTJegB/S3FZQRBMUoz0Spvg8EzV3C/kBi/VO9KKCzjqZDVvhZJJbTQh9879CBY6vUy1ajo9WcLYnwbNA==}
|
||||||
|
|
||||||
'@kevisual/types@0.0.12':
|
'@kevisual/types@0.0.12':
|
||||||
resolution: {integrity: sha512-zJXH2dosir3jVrQ6QG4i0+iLQeT9gJ3H+cKXs8ReWboxBSYzUZO78XssVeVrFPsJ33iaAqo4q3DWbSS1dWGn7Q==}
|
resolution: {integrity: sha512-zJXH2dosir3jVrQ6QG4i0+iLQeT9gJ3H+cKXs8ReWboxBSYzUZO78XssVeVrFPsJ33iaAqo4q3DWbSS1dWGn7Q==}
|
||||||
@@ -6800,7 +6800,7 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
es-toolkit: 1.44.0
|
es-toolkit: 1.44.0
|
||||||
|
|
||||||
'@kevisual/router@0.0.83':
|
'@kevisual/router@0.0.84':
|
||||||
dependencies:
|
dependencies:
|
||||||
es-toolkit: 1.44.0
|
es-toolkit: 1.44.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user