feat(knowledge): add service library

This commit is contained in:
DS | Schubert 2026-07-03 10:25:52 +02:00
parent ecab0fe6b6
commit 228da8f814
32 changed files with 2878 additions and 6 deletions

View file

@ -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",
},
});
}