fix(ui/minio): don't rewrite presigned URL host for server-side chapter fetches

The SvelteKit server fetches chapter markdown server-side using the presigned
URL. rewriteHost() was replacing the internal minio:9000 host with the public
PUBLIC_MINIO_PUBLIC_URL (localhost:9000), which is unreachable from inside
Docker, causing MinIO 403/connection errors.

presignChapter now takes an optional rewrite=false parameter — the server-side
load function gets the raw internal URL, while any future browser-facing use
can pass rewrite=true to get the public-facing URL.
This commit is contained in:
Admin
2026-03-04 01:06:52 +05:00
parent f80b83309a
commit cabdd3ffdd

View File

@@ -37,10 +37,12 @@ function rewriteHost(presignedUrl: string): string {
/**
* Returns a presigned URL for a chapter markdown file.
* URL is valid for ~15 minutes (set by the scraper).
* The returned URL points to the public MinIO endpoint and can be used
* server-side (in a +page.server.ts load function) to fetch the markdown content.
*
* @param rewrite - if true, rewrites the MinIO host to PUBLIC_MINIO_PUBLIC_URL
* (for browser use). Defaults to false — the server-side load function fetches
* the URL directly from the internal MinIO endpoint.
*/
export async function presignChapter(slug: string, n: number): Promise<string> {
export async function presignChapter(slug: string, n: number, rewrite = false): Promise<string> {
log.debug('minio', 'presigning chapter', { slug, n });
let res: Response;
try {
@@ -56,7 +58,7 @@ export async function presignChapter(slug: string, n: number): Promise<string> {
}
const data = (await res.json()) as { url: string };
log.debug('minio', 'presign chapter ok', { slug, n });
return rewriteHost(data.url);
return rewrite ? rewriteHost(data.url) : data.url;
}
/**