fix(audio): return 404 from presign when audio object not yet uploaded
handlePresignAudio now checks AudioExists before presigning; previously it would generate a valid-looking signed URL for a non-existent object, causing the browser to get 404 from MinIO directly. - Add AudioExists to Store interface and HybridStore - Guard handlePresignAudio with AudioExists check, return 404 if missing - Propagate 404 through presignAudio() in minio.ts (typed error.status=404) - SvelteKit presign route forwards 404 to the browser instead of 500
This commit is contained in:
@@ -64,6 +64,7 @@ export async function presignChapter(slug: string, n: number, rewrite = false):
|
||||
/**
|
||||
* Returns a presigned URL for an audio file.
|
||||
* URL is valid for ~1 hour. The URL is returned to the browser for direct streaming.
|
||||
* Throws with { status: 404 } when the audio object has not been generated yet.
|
||||
*/
|
||||
export async function presignAudio(
|
||||
slug: string,
|
||||
@@ -83,6 +84,12 @@ export async function presignAudio(
|
||||
log.error('minio', 'presign audio network error', { slug, n, err: String(e) });
|
||||
throw new Error(`presign audio ${slug}/${n}: network error`);
|
||||
}
|
||||
if (res.status === 404) {
|
||||
// Audio hasn't been generated / uploaded yet — caller should surface this as 404.
|
||||
const err = new Error(`presign audio ${slug}/${n}: not found`) as Error & { status: number };
|
||||
err.status = 404;
|
||||
throw err;
|
||||
}
|
||||
if (!res.ok) {
|
||||
const body = await res.text().catch(() => '');
|
||||
log.error('minio', 'presign audio failed', { slug, n, status: res.status, body });
|
||||
|
||||
Reference in New Issue
Block a user