feat: 添加Authorization头处理,更新Context类型以包含headers

This commit is contained in:
zhaoyingbo 2025-02-27 05:09:14 +00:00
parent 4abeb0a0f0
commit 7f4aedbfc8
3 changed files with 9 additions and 2 deletions

View File

@ -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, {

View File

@ -23,6 +23,7 @@ export interface Context {
gitlabService: GitlabService
path: PathCheckTool
searchParams: URLSearchParams
headers: Headers
app: "michat" | "egg" | string
appInfo: AppInfoModel
}

View File

@ -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