forked from akai/readest
@@ -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',
|
||||
|
||||
@@ -414,7 +414,7 @@ export default function BrowserPage() {
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
const pathname = new URL(url).pathname;
|
||||
const pathname = decodeURIComponent(new URL(url).pathname);
|
||||
const ext = getFileExtFromMimeType(parsed?.mediaType) || getFileExtFromPath(pathname);
|
||||
const basename = pathname.replaceAll('/', '_');
|
||||
const filename = ext ? `${basename}.${ext}` : basename;
|
||||
@@ -426,6 +426,7 @@ export default function BrowserPage() {
|
||||
let downloadUrl = useProxy ? getProxiedURL(url, '', true) : url;
|
||||
const headers: Record<string, string> = {
|
||||
'User-Agent': READEST_OPDS_USER_AGENT,
|
||||
Accept: '*/*',
|
||||
};
|
||||
if (username || password) {
|
||||
const authHeader = await probeAuth(url, username, password, useProxy);
|
||||
|
||||
@@ -207,7 +207,7 @@ export const probeAuth = async (
|
||||
const fetchURL = useProxy ? getProxiedURL(cleanUrl) : cleanUrl;
|
||||
const headers: Record<string, string> = {
|
||||
'User-Agent': READEST_OPDS_USER_AGENT,
|
||||
Accept: 'application/atom+xml, application/xml, text/xml',
|
||||
Accept: 'application/atom+xml, application/xml, text/xml, */*',
|
||||
};
|
||||
|
||||
// Probe with HEAD request
|
||||
@@ -240,7 +240,8 @@ export const probeAuth = async (
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// Komga returns 200 even if requires auth, so we return Basic auth header in this case
|
||||
return createBasicAuth(finalUsername, finalPassword);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -265,7 +266,7 @@ export const fetchWithAuth = async (
|
||||
const fetchURL = useProxy ? getProxiedURL(cleanUrl) : cleanUrl;
|
||||
const headers: Record<string, string> = {
|
||||
'User-Agent': READEST_OPDS_USER_AGENT,
|
||||
Accept: 'application/atom+xml, application/xml, text/xml',
|
||||
Accept: 'application/atom+xml, application/xml, text/xml, */*',
|
||||
...(options.headers as Record<string, string>),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user