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:
Admin
2026-03-04 15:21:17 +05:00
parent 53af7515a3
commit 0d7b985469
5 changed files with 26 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import { log } from '$lib/server/logger';
* GET /api/presign/audio?slug=...&n=...&voice=...&speed=...
* Returns a presigned MinIO URL for the audio file so the browser
* can stream it directly without going through the server.
* Returns 404 when the audio has not been generated yet.
*/
export const GET: RequestHandler = async ({ url }) => {
const slug = url.searchParams.get('slug');
@@ -22,6 +23,10 @@ export const GET: RequestHandler = async ({ url }) => {
const presignedUrl = await presignAudio(slug, n, voice, speed);
return json({ url: presignedUrl });
} catch (e) {
const status = (e as { status?: number }).status;
if (status === 404) {
error(404, 'Audio not found');
}
log.error('presign', 'presign audio failed', { slug, n, err: String(e) });
error(500, `Could not get presigned URL: ${e}`);
}