From d86f4dc48ff975b99edfff5d836751e04c2bcdda Mon Sep 17 00:00:00 2001 From: xiongxiao Date: Tue, 13 Jan 2026 17:26:38 +0800 Subject: [PATCH] fix: update --- agent/app.ts | 4 +++- agent/routes/index.ts | 13 ++++++++++--- agent/routes/repo/index.ts | 2 +- agent/routes/user/check.ts | 2 +- agent/routes/workspace/index.ts | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/agent/app.ts b/agent/app.ts index 65a0c91..b88cd83 100644 --- a/agent/app.ts +++ b/agent/app.ts @@ -13,5 +13,7 @@ export const cnb = useContextKey('cnb', () => { }) export const appId = nanoid(); export const app = useContextKey('app', () => { - return new App() + return new App({ + appId + }) }) \ No newline at end of file diff --git a/agent/routes/index.ts b/agent/routes/index.ts index d65455c..7b4614e 100644 --- a/agent/routes/index.ts +++ b/agent/routes/index.ts @@ -1,8 +1,15 @@ -import { app, appId } from '@/agent/app.ts'; +import { app, appId } from '../app.ts'; import './user/check.ts' - +import { isEqual } from 'es-toolkit' +/** + * 验证上下文中的 App ID 是否与指定的 App ID 匹配 + * @param {any} ctx - 上下文对象,可能包含 appId 属性 + * @param {string} appId - 需要验证的目标 App ID + * @returns {boolean} 如果 ctx 中包含 appId 且匹配则返回 true,否则返回 false + * @throws {Error} 如果 ctx 中包含 appId 但不匹配,则抛出 403 错误 + */ const checkAppId = (ctx: any, appId: string) => { - const _appId = ctx?.appId; + const _appId = ctx?.app?.appId; if (_appId) { if (_appId !== appId) { ctx.throw(403, 'Invalid App ID'); diff --git a/agent/routes/repo/index.ts b/agent/routes/repo/index.ts index 3bf7156..526cfbf 100644 --- a/agent/routes/repo/index.ts +++ b/agent/routes/repo/index.ts @@ -1,4 +1,4 @@ -import { app, cnb } from '@/agent/app.ts'; +import { app, cnb } from '../../app.ts'; app.route({ path: 'cnb', diff --git a/agent/routes/user/check.ts b/agent/routes/user/check.ts index 4e52714..7b0dc70 100644 --- a/agent/routes/user/check.ts +++ b/agent/routes/user/check.ts @@ -1,4 +1,4 @@ -import { app, cnb } from '@/agent/app.ts'; +import { app, cnb } from '../../app.ts'; app.route({ diff --git a/agent/routes/workspace/index.ts b/agent/routes/workspace/index.ts index d811e3e..a4cbcca 100644 --- a/agent/routes/workspace/index.ts +++ b/agent/routes/workspace/index.ts @@ -1,4 +1,4 @@ -import { app, cnb } from '@/agent/app.ts'; +import { app, cnb } from '../../app.ts'; app.route({ path: 'cnb',