27 lines
879 B
TypeScript
27 lines
879 B
TypeScript
import { json, error } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { presignAudio } from '$lib/server/minio';
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
export const GET: RequestHandler = async ({ url }) => {
|
|
const slug = url.searchParams.get('slug');
|
|
const n = parseInt(url.searchParams.get('n') ?? '', 10);
|
|
const voice = url.searchParams.get('voice') ?? undefined;
|
|
const speed = parseFloat(url.searchParams.get('speed') ?? '1') || 1;
|
|
|
|
if (!slug || !n || n < 1) {
|
|
error(400, 'Missing slug or n');
|
|
}
|
|
|
|
try {
|
|
const presignedUrl = await presignAudio(slug, n, voice, speed);
|
|
return json({ url: presignedUrl });
|
|
} catch (e) {
|
|
error(500, `Could not get presigned URL: ${e}`);
|
|
}
|
|
};
|