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

View File

@@ -46,7 +46,6 @@ export class AssistantApp extends Manager {
if (token) {
console.log('用户已登录,正在初始化远程应用连接...');
await manager.initRemoteApp({ token });
await manager.initRemoteApp();
await manager.initRouterProxyLightApp();
}
await manager.initRouterProxyApp();
@@ -212,7 +211,7 @@ export class AssistantApp extends Manager {
const query = new Query({ url });
try {
initApi({
router: this.mainApp,
router: this.mainApp as any,
item: {
type: '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",
"version": "0.0.4",
"version": "0.0.6",
"description": "",
"main": "dist/app.js",
"scripts": {
@@ -19,10 +19,10 @@
},
"devDependencies": {
"eventemitter3": "^5.0",
"@kevisual/router": "^0.0.70"
"@kevisual/router": "^0.0.90"
},
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
"license": "MIT",
"packageManager": "pnpm@10.28.2",
"packageManager": "pnpm@10.31.0",
"type": "module"
}

View File

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

View File

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