feat: 更新依赖版本,添加 cnb-board 环境检查功能

This commit is contained in:
2026-02-24 01:23:52 +08:00
parent 58a0e9e61f
commit bda7fc3b92
10 changed files with 57 additions and 23 deletions

View File

@@ -9,11 +9,13 @@ import type { WebSocketListenerFun } from "@kevisual/router";
import WebSocket from 'ws';
import { renderNoAuthAndLogin } from '@/module/assistant/html/login.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({});
localProxy.initFromAssistantConfig(assistantConfig);
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) {
if (pathname.startsWith(openPath)) {
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) => {
const _assistantConfig = assistantConfig.getCacheAssistantConfig();
const home = _assistantConfig?.home || '/root/home';
let home = _assistantConfig?.home
const auth = _assistantConfig?.auth || {};
// 没有管理员,需要去登陆
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 = () => {
res.writeHead(302, { Location: `/root/cli-center/` });
const toLogin = (redirect?: string) => {
res.writeHead(302, { Location: `/root/login/` + (redirect ? `?redirect=${encodeURIComponent(redirect)}` : '') });
res.end();
return true;
}
@@ -94,10 +108,11 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
const pathname = decodeURIComponent(url.pathname);
if (pathname === '/') {
if (noAdmin) {
return toSetting();
return toLogin(home + '/');
}
res.writeHead(302, { Location: `${home}/` });
return res.end();
res.writeHead(302, { Location: home });
res.end();
return
}
if (pathname.startsWith('/favicon.ico')) {
res.statusCode = 404;
@@ -162,8 +177,9 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
}
const isOpen = isOpenPath(pathname)
logger.debug('proxyRoute', { _user, _app, pathname, noAdmin, isOpen });
// 没有管理员,且不是开放路径,去登录
if (noAdmin && !isOpen) {
return toSetting();
return toLogin();
}
if (_app && urls.length === 3) {
// 重定向到