From cabdd3ffdd05b49a13b2d7de0d472948c37c6e5c Mon Sep 17 00:00:00 2001 From: Admin Date: Wed, 4 Mar 2026 01:06:52 +0500 Subject: [PATCH] fix(ui/minio): don't rewrite presigned URL host for server-side chapter fetches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- ui/src/lib/server/minio.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ui/src/lib/server/minio.ts b/ui/src/lib/server/minio.ts index e1c276a..338fbf1 100644 --- a/ui/src/lib/server/minio.ts +++ b/ui/src/lib/server/minio.ts @@ -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 { +export async function presignChapter(slug: string, n: number, rewrite = false): Promise { log.debug('minio', 'presigning chapter', { slug, n }); let res: Response; try { @@ -56,7 +58,7 @@ export async function presignChapter(slug: string, n: number): Promise { } 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; } /**