feat(knowledge): add service library
This commit is contained in:
parent
ecab0fe6b6
commit
228da8f814
32 changed files with 2878 additions and 6 deletions
|
|
@ -57,3 +57,47 @@ export async function proxyHermesRequest(
|
|||
|
||||
return hermesJsonResponse(hermesResponse);
|
||||
}
|
||||
|
||||
export async function proxyHermesStreamRequest(
|
||||
request: NextRequest,
|
||||
path: string,
|
||||
) {
|
||||
const token = await getAccessToken();
|
||||
|
||||
if (!token) {
|
||||
return unauthorizedResponse();
|
||||
}
|
||||
|
||||
const hermesUrl = getHermesUrl();
|
||||
|
||||
if (!hermesUrl) {
|
||||
return upstreamConfigurationErrorResponse();
|
||||
}
|
||||
|
||||
let hermesResponse: Response;
|
||||
|
||||
try {
|
||||
hermesResponse = await fetch(`${hermesUrl}${path}`, {
|
||||
method: request.method,
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
Accept: request.headers.get("accept") ?? "*/*",
|
||||
},
|
||||
cache: "no-store",
|
||||
});
|
||||
} catch {
|
||||
return upstreamUnavailableResponse();
|
||||
}
|
||||
|
||||
if (!hermesResponse.ok) {
|
||||
return hermesJsonResponse(hermesResponse);
|
||||
}
|
||||
|
||||
return new Response(hermesResponse.body, {
|
||||
status: hermesResponse.status,
|
||||
headers: {
|
||||
"Content-Type": hermesResponse.headers.get("content-type") ?? "application/octet-stream",
|
||||
"Content-Disposition": hermesResponse.headers.get("content-disposition") ?? "attachment",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue