compat(opds): support Komga OPDS v1.2 and v2, closes #2839 (#2851)

This commit is contained in:
Huang Xin
2026-01-03 18:04:39 +01:00
committed by GitHub
parent 8a263235ed
commit ca8d25341e
3 changed files with 12 additions and 8 deletions
@@ -113,7 +113,7 @@ async function handleRequest(request: NextRequest, method: 'GET' | 'HEAD') {
});
}
if (stream === 'true' || (contentLength && parseInt(contentLength) > 1024 * 1024)) {
if (stream === 'true' && contentLength && parseInt(contentLength) > 1024 * 1024) {
console.log(`[OPDS Proxy] Streaming: ${url}`);
return new NextResponse(response.body, {
@@ -129,13 +129,15 @@ async function handleRequest(request: NextRequest, method: 'GET' | 'HEAD') {
},
});
} else {
const data = await response.text();
console.log(`[OPDS Proxy] Success: ${url} (${data.length} bytes)`);
const buf = await response.arrayBuffer();
const length = buf.byteLength;
console.log(`[OPDS Proxy] Success: ${url} (${length} bytes)`);
return new NextResponse(data, {
return new NextResponse(buf, {
status: 200,
headers: {
'Content-Type': contentType,
'Content-Length': length.toString(),
'Cache-Control': 'public, max-age=300',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS',