diff --git a/assistant/package.json b/assistant/package.json index 2b74403..f8f6baa 100644 --- a/assistant/package.json +++ b/assistant/package.json @@ -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", diff --git a/assistant/src/module/assistant/local-app-manager/assistant-app.ts b/assistant/src/module/assistant/local-app-manager/assistant-app.ts index 4182971..a38e04e 100644 --- a/assistant/src/module/assistant/local-app-manager/assistant-app.ts +++ b/assistant/src/module/assistant/local-app-manager/assistant-app.ts @@ -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: { diff --git a/assistant/src/module/client-auth/cache-auth.ts b/assistant/src/module/client-auth/cache-auth.ts new file mode 100644 index 0000000..41ec63e --- /dev/null +++ b/assistant/src/module/client-auth/cache-auth.ts @@ -0,0 +1,6 @@ +import { LRUCache } from 'lru-cache' + +export const authCache = new LRUCache({ + max: 10000, // 最大缓存数量 + ttl: 1000 * 60 * 60 * 24 * 7, // 缓存过期时间,单位为毫秒,这里设置为7天 +}); diff --git a/assistant/src/module/client-auth/index.ts b/assistant/src/module/client-auth/index.ts new file mode 100644 index 0000000..41a26d6 --- /dev/null +++ b/assistant/src/module/client-auth/index.ts @@ -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 } + } +}; \ No newline at end of file diff --git a/assistant/src/module/client-auth/package.json b/assistant/src/module/client-auth/package.json new file mode 100644 index 0000000..c4c81bf --- /dev/null +++ b/assistant/src/module/client-auth/package.json @@ -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 (https://www.xiongxiao.me)", + "license": "MIT", + "packageManager": "pnpm@10.31.0", + "type": "module" +} diff --git a/assistant/src/module/remote-app/package.json b/assistant/src/module/remote-app/package.json index 78c3e93..ce30b9d 100644 --- a/assistant/src/module/remote-app/package.json +++ b/assistant/src/module/remote-app/package.json @@ -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 (https://www.xiongxiao.me)", "license": "MIT", - "packageManager": "pnpm@10.28.2", + "packageManager": "pnpm@10.31.0", "type": "module" } \ No newline at end of file diff --git a/assistant/src/module/remote-app/remote-app.ts b/assistant/src/module/remote-app/remote-app.ts index 4fcb4de..01c161e 100644 --- a/assistant/src/module/remote-app/remote-app.ts +++ b/assistant/src/module/remote-app/remote-app.ts @@ -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; diff --git a/assistant/src/routes/cnb-board/index.ts b/assistant/src/routes/cnb-board/index.ts index fd022d2..cac00a0 100644 --- a/assistant/src/routes/cnb-board/index.ts +++ b/assistant/src/routes/cnb-board/index.ts @@ -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); \ No newline at end of file +}).addTo(app, { overwrite: false }); \ No newline at end of file diff --git a/assistant/src/services/proxy/proxy-page-index.ts b/assistant/src/services/proxy/proxy-page-index.ts index 4b14f25..9771fd7 100644 --- a/assistant/src/services/proxy/proxy-page-index.ts +++ b/assistant/src/services/proxy/proxy-page-index.ts @@ -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); diff --git a/package.json b/package.json index eb95847..69447cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cli", - "version": "0.1.19", + "version": "0.1.20", "description": "envision 命令行工具", "type": "module", "basename": "/root/cli", @@ -45,13 +45,13 @@ "@kevisual/app": "^0.0.2", "@kevisual/auth": "^2.0.3", "@kevisual/context": "^0.0.8", - "@kevisual/router": "^0.0.89", + "@kevisual/router": "^0.0.90", "@kevisual/use-config": "^1.0.30", - "@opencode-ai/sdk": "^1.2.21", + "@opencode-ai/sdk": "^1.2.22", "@types/busboy": "^1.5.4", "busboy": "^1.6.0", "eventemitter3": "^5.0.4", - "jose": "^6.2.0", + "jose": "^6.2.1", "lowdb": "^7.0.1", "lru-cache": "^11.2.6", "micromatch": "^4.0.8", @@ -82,7 +82,7 @@ "ignore": "^7.0.5", "jsonwebtoken": "^9.0.3", "pm2": "^6.0.14", - "tar": "^7.5.10", + "tar": "^7.5.11", "zustand": "^5.0.11" }, "engines": {