diff --git a/routes/modelProxy/index.ts b/routes/modelProxy/index.ts index b2d3f0c..685391e 100644 --- a/routes/modelProxy/index.ts +++ b/routes/modelProxy/index.ts @@ -6,8 +6,12 @@ import { Context } from "../../types" * @returns */ export const manageModelProxyReq = async (ctx: Context) => { - const { req, logger } = ctx - logger.info("model proxy") + const { req, headers, logger } = ctx + const auth = headers.get("Authorization") + logger.info(`Start Model Proxy, Authorization: ${auth}`) + if (!auth || auth !== "Bearer sk-21a2ce1c2ee94bc2933798eac1bbcadc") { + return ctx.genResp.forbidden("Authorization required") + } const PROXY_URL = "http://ms-13871-nstruct-lmdeploy-2-0109140455.kscn-tj5-prod2-cloudml.xiaomi.srv" return fetch(PROXY_URL + new URL(req.url).pathname, { diff --git a/types/context.ts b/types/context.ts index d068c52..480c965 100644 --- a/types/context.ts +++ b/types/context.ts @@ -23,6 +23,7 @@ export interface Context { gitlabService: GitlabService path: PathCheckTool searchParams: URLSearchParams + headers: Headers app: "michat" | "egg" | string appInfo: AppInfoModel } diff --git a/utils/genContext.ts b/utils/genContext.ts index ef8dfee..8f5ae0a 100644 --- a/utils/genContext.ts +++ b/utils/genContext.ts @@ -42,6 +42,7 @@ const genContext = async (req: Request, rId?: string) => { } const larkBody = new LarkBody(body) const searchParams = new URL(req.url).searchParams + const headers = new Headers(req.headers) const app = searchParams.get("app") || "egg" const appInfo = APP_MAP[app] const requestId = rId || getPreRequestId(larkBody) || uuid() @@ -80,6 +81,7 @@ const genContext = async (req: Request, rId?: string) => { attachService, gitlabService, searchParams, + headers, app, appInfo, } as Context