feat: 更新多个依赖版本,添加客户端认证模块及缓存功能

This commit is contained in:
2026-03-09 19:00:34 +08:00
parent d33db1b8e7
commit 060595c352
10 changed files with 95 additions and 19 deletions

View File

@@ -49,10 +49,10 @@
"@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.53", "@kevisual/query": "0.0.53",
"@kevisual/router": "^0.0.89", "@kevisual/router": "^0.0.90",
"@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.21", "@opencode-ai/plugin": "^1.2.22",
"@types/bun": "^1.3.10", "@types/bun": "^1.3.10",
"@types/node": "^25.3.5", "@types/node": "^25.3.5",
"@types/send": "^1.2.1", "@types/send": "^1.2.1",
@@ -80,7 +80,7 @@
"@kevisual/js-filter": "^0.0.5", "@kevisual/js-filter": "^0.0.5",
"@kevisual/oss": "^0.0.20", "@kevisual/oss": "^0.0.20",
"@kevisual/video-tools": "^0.0.13", "@kevisual/video-tools": "^0.0.13",
"@opencode-ai/sdk": "^1.2.21", "@opencode-ai/sdk": "^1.2.22",
"es-toolkit": "^1.45.1", "es-toolkit": "^1.45.1",
"eventemitter3": "^5.0.4", "eventemitter3": "^5.0.4",
"lowdb": "^7.0.1", "lowdb": "^7.0.1",

View File

@@ -46,7 +46,6 @@ export class AssistantApp extends Manager {
if (token) { if (token) {
console.log('用户已登录,正在初始化远程应用连接...'); console.log('用户已登录,正在初始化远程应用连接...');
await manager.initRemoteApp({ token }); await manager.initRemoteApp({ token });
await manager.initRemoteApp();
await manager.initRouterProxyLightApp(); await manager.initRouterProxyLightApp();
} }
await manager.initRouterProxyApp(); await manager.initRouterProxyApp();
@@ -212,7 +211,7 @@ export class AssistantApp extends Manager {
const query = new Query({ url }); const query = new Query({ url });
try { try {
initApi({ initApi({
router: this.mainApp, router: this.mainApp as any,
item: { item: {
type: 'api', type: 'api',
api: { api: {

View File

@@ -0,0 +1,6 @@
import { LRUCache } from 'lru-cache'
export const authCache = new LRUCache<string, any>({
max: 10000, // 最大缓存数量
ttl: 1000 * 60 * 60 * 24 * 7, // 缓存过期时间单位为毫秒这里设置为7天
});

View File

@@ -0,0 +1,58 @@
import { Query } from "@kevisual/query";
import { authCache } from './cache-auth.ts';
const getTokenUser = async (token: string) => {
const query = new Query();
const res = await query.post({
path: 'user',
key: 'me',
token: token,
});
return res;
}
export const getTokenUserCache = async (token: string) => {
const tokenUser = await authCache.get(token);
if (tokenUser) {
return {
code: 200,
data: tokenUser,
};
}
const res = await getTokenUser(token);
if (res.code === 200) {
authCache.set(token, res.data);
}
return res;
}
export const checkAuth = async (ctx: any, isAdmin = false) => {
const token = ctx.query.token;
if (!token) {
return {
code: 401,
message: '未登录',
}
}
// 鉴权代理
let tokenUser = await authCache.get(token);
if (!tokenUser) {
const tokenUserRes = await getTokenUser(token);
if (tokenUserRes.code !== 200) {
return {
code: tokenUserRes.code,
message: '验证失败' + tokenUserRes.message,
}
} else {
tokenUser = tokenUserRes.data;
}
authCache.set(token, tokenUser);
}
ctx.state = {
...ctx.state,
token,
tokenUser,
};
return {
code: 200,
data: { tokenUser, token }
}
};

View File

@@ -0,0 +1,14 @@
{
"name": "client-auth",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
"license": "MIT",
"packageManager": "pnpm@10.31.0",
"type": "module"
}

View File

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/remote-app", "name": "@kevisual/remote-app",
"version": "0.0.4", "version": "0.0.6",
"description": "", "description": "",
"main": "dist/app.js", "main": "dist/app.js",
"scripts": { "scripts": {
@@ -19,10 +19,10 @@
}, },
"devDependencies": { "devDependencies": {
"eventemitter3": "^5.0", "eventemitter3": "^5.0",
"@kevisual/router": "^0.0.70" "@kevisual/router": "^0.0.90"
}, },
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)", "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
"license": "MIT", "license": "MIT",
"packageManager": "pnpm@10.28.2", "packageManager": "pnpm@10.31.0",
"type": "module" "type": "module"
} }

View File

@@ -44,7 +44,7 @@ export class RemoteApp {
constructor(opts?: RemoteAppOptions) { constructor(opts?: RemoteAppOptions) {
this.mainApp = opts?.app; this.mainApp = opts?.app;
const token = opts.token; const token = opts.token;
const url = opts.url; const url = opts.url || 'https://kevisual.cn/ws/proxy';
const id = opts.id; const id = opts.id;
const username = opts.username; const username = opts.username;
this.username = username; this.username = username;

View File

@@ -4,7 +4,7 @@ import { execCommand } from '@/module/npm-install.ts';
import { useKey } from '@kevisual/context'; import { useKey } from '@kevisual/context';
app.route({ app.route({
path: 'cnb-board', path: 'cnb_board',
key: 'is-cnb-board', key: 'is-cnb-board',
description: '检查是否是 cnb-board 环境', description: '检查是否是 cnb-board 环境',
middleware: ['auth-admin'] middleware: ['auth-admin']
@@ -13,17 +13,17 @@ app.route({
ctx.body = { ctx.body = {
isCNB: !!isCNB, isCNB: !!isCNB,
}; };
}).addTo(app); }).addTo(app, { overwrite: false });
app.route({ app.route({
path: 'cnb-board', path: 'cnb_board',
key: 'exit', key: 'exit',
description: 'cnb的工作环境退出程序', description: 'cnb的工作环境退出程序',
middleware: ['auth-admin'], middleware: ['auth-admin'],
}).define(async (ctx) => { }).define(async (ctx) => {
const cmd = 'kill 1'; const cmd = 'kill 1';
execCommand(cmd); execCommand(cmd);
}).addTo(app); }).addTo(app, { overwrite: false });

View File

@@ -10,7 +10,6 @@ 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 { 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);

View File

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/cli", "name": "@kevisual/cli",
"version": "0.1.19", "version": "0.1.20",
"description": "envision 命令行工具", "description": "envision 命令行工具",
"type": "module", "type": "module",
"basename": "/root/cli", "basename": "/root/cli",
@@ -45,13 +45,13 @@
"@kevisual/app": "^0.0.2", "@kevisual/app": "^0.0.2",
"@kevisual/auth": "^2.0.3", "@kevisual/auth": "^2.0.3",
"@kevisual/context": "^0.0.8", "@kevisual/context": "^0.0.8",
"@kevisual/router": "^0.0.89", "@kevisual/router": "^0.0.90",
"@kevisual/use-config": "^1.0.30", "@kevisual/use-config": "^1.0.30",
"@opencode-ai/sdk": "^1.2.21", "@opencode-ai/sdk": "^1.2.22",
"@types/busboy": "^1.5.4", "@types/busboy": "^1.5.4",
"busboy": "^1.6.0", "busboy": "^1.6.0",
"eventemitter3": "^5.0.4", "eventemitter3": "^5.0.4",
"jose": "^6.2.0", "jose": "^6.2.1",
"lowdb": "^7.0.1", "lowdb": "^7.0.1",
"lru-cache": "^11.2.6", "lru-cache": "^11.2.6",
"micromatch": "^4.0.8", "micromatch": "^4.0.8",
@@ -82,7 +82,7 @@
"ignore": "^7.0.5", "ignore": "^7.0.5",
"jsonwebtoken": "^9.0.3", "jsonwebtoken": "^9.0.3",
"pm2": "^6.0.14", "pm2": "^6.0.14",
"tar": "^7.5.10", "tar": "^7.5.11",
"zustand": "^5.0.11" "zustand": "^5.0.11"
}, },
"engines": { "engines": {