feat: 添加Authorization头处理,更新Context类型以包含headers
This commit is contained in:
parent
4abeb0a0f0
commit
7f4aedbfc8
@ -6,8 +6,12 @@ import { Context } from "../../types"
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const manageModelProxyReq = async (ctx: Context) => {
|
export const manageModelProxyReq = async (ctx: Context) => {
|
||||||
const { req, logger } = ctx
|
const { req, headers, logger } = ctx
|
||||||
logger.info("model proxy")
|
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 =
|
const PROXY_URL =
|
||||||
"http://ms-13871-nstruct-lmdeploy-2-0109140455.kscn-tj5-prod2-cloudml.xiaomi.srv"
|
"http://ms-13871-nstruct-lmdeploy-2-0109140455.kscn-tj5-prod2-cloudml.xiaomi.srv"
|
||||||
return fetch(PROXY_URL + new URL(req.url).pathname, {
|
return fetch(PROXY_URL + new URL(req.url).pathname, {
|
||||||
|
@ -23,6 +23,7 @@ export interface Context {
|
|||||||
gitlabService: GitlabService
|
gitlabService: GitlabService
|
||||||
path: PathCheckTool
|
path: PathCheckTool
|
||||||
searchParams: URLSearchParams
|
searchParams: URLSearchParams
|
||||||
|
headers: Headers
|
||||||
app: "michat" | "egg" | string
|
app: "michat" | "egg" | string
|
||||||
appInfo: AppInfoModel
|
appInfo: AppInfoModel
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ const genContext = async (req: Request, rId?: string) => {
|
|||||||
}
|
}
|
||||||
const larkBody = new LarkBody(body)
|
const larkBody = new LarkBody(body)
|
||||||
const searchParams = new URL(req.url).searchParams
|
const searchParams = new URL(req.url).searchParams
|
||||||
|
const headers = new Headers(req.headers)
|
||||||
const app = searchParams.get("app") || "egg"
|
const app = searchParams.get("app") || "egg"
|
||||||
const appInfo = APP_MAP[app]
|
const appInfo = APP_MAP[app]
|
||||||
const requestId = rId || getPreRequestId(larkBody) || uuid()
|
const requestId = rId || getPreRequestId(larkBody) || uuid()
|
||||||
@ -80,6 +81,7 @@ const genContext = async (req: Request, rId?: string) => {
|
|||||||
attachService,
|
attachService,
|
||||||
gitlabService,
|
gitlabService,
|
||||||
searchParams,
|
searchParams,
|
||||||
|
headers,
|
||||||
app,
|
app,
|
||||||
appInfo,
|
appInfo,
|
||||||
} as Context
|
} as Context
|
||||||
|
Loading…
x
Reference in New Issue
Block a user