|
1 | 1 | import { NextResponse } from 'next/server' |
2 | 2 | import { createLogger } from '@/lib/logs/console-logger' |
| 3 | +import { uploadFile } from '@/lib/uploads/storage-client' |
3 | 4 |
|
4 | 5 | const logger = createLogger('ProxyTTSAPI') |
5 | 6 |
|
@@ -44,12 +45,20 @@ export async function POST(request: Request) { |
44 | 45 | return new NextResponse('Empty audio received', { status: 422 }) |
45 | 46 | } |
46 | 47 |
|
47 | | - return new NextResponse(audioBlob, { |
48 | | - headers: { |
49 | | - 'Content-Type': 'audio/mpeg', |
50 | | - 'Cache-Control': 'public, max-age=86400', // Cache for a day |
51 | | - 'Access-Control-Allow-Origin': '*', // CORS support |
52 | | - }, |
| 48 | + // Upload the audio file to storage and return multiple URL options |
| 49 | + const audioBuffer = Buffer.from(await audioBlob.arrayBuffer()) |
| 50 | + const timestamp = Date.now() |
| 51 | + const fileName = `elevenlabs-tts-${timestamp}.mp3` |
| 52 | + const fileInfo = await uploadFile(audioBuffer, fileName, 'audio/mpeg') |
| 53 | + |
| 54 | + // Generate the full URL for external use |
| 55 | + const host = request.headers.get('host') || 'localhost:3000' |
| 56 | + const protocol = request.headers.get('x-forwarded-proto') || 'http' |
| 57 | + const audioUrl = `${protocol}://${host}${fileInfo.path}` |
| 58 | + |
| 59 | + return NextResponse.json({ |
| 60 | + audioUrl, |
| 61 | + size: fileInfo.size, |
53 | 62 | }) |
54 | 63 | } catch (error) { |
55 | 64 | logger.error('Error proxying TTS:', error) |
|
0 commit comments