Remove dead segment audio presign route and legacy helpers
This commit is contained in:
parent
513128b802
commit
df841210a3
4 changed files with 5 additions and 65 deletions
|
|
@ -22,7 +22,7 @@ export async function GET(request: NextRequest) {
|
||||||
return new NextResponse(null, {
|
return new NextResponse(null, {
|
||||||
status: 416,
|
status: 416,
|
||||||
headers: {
|
headers: {
|
||||||
...buildSegmentAudioCacheHeaders('fallback'),
|
...buildSegmentAudioCacheHeaders(),
|
||||||
'Accept-Ranges': 'bytes',
|
'Accept-Ranges': 'bytes',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -31,7 +31,7 @@ export async function GET(request: NextRequest) {
|
||||||
const audio = await getTtsSegmentAudioObjectStream(resolved.audioKey, range ? { range } : undefined);
|
const audio = await getTtsSegmentAudioObjectStream(resolved.audioKey, range ? { range } : undefined);
|
||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
'Content-Type': audio.contentType || 'audio/mpeg',
|
'Content-Type': audio.contentType || 'audio/mpeg',
|
||||||
...buildSegmentAudioCacheHeaders('fallback'),
|
...buildSegmentAudioCacheHeaders(),
|
||||||
'Accept-Ranges': audio.acceptRanges || 'bytes',
|
'Accept-Ranges': audio.acceptRanges || 'bytes',
|
||||||
};
|
};
|
||||||
if (audio.contentLength !== null) headers['Content-Length'] = String(audio.contentLength);
|
if (audio.contentLength !== null) headers['Content-Length'] = String(audio.contentLength);
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
import { NextRequest, NextResponse } from 'next/server';
|
|
||||||
import { isS3Configured } from '@/lib/server/storage/s3';
|
|
||||||
import {
|
|
||||||
buildSegmentAudioCacheHeaders,
|
|
||||||
resolveCompletedSegmentAudio,
|
|
||||||
ttsSegmentsS3NotConfiguredResponse,
|
|
||||||
} from '@/lib/server/tts/segments-audio';
|
|
||||||
import { presignTtsSegmentAudioGet } from '@/lib/server/tts/segments-blobstore';
|
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic';
|
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
|
||||||
try {
|
|
||||||
if (!isS3Configured()) return ttsSegmentsS3NotConfiguredResponse();
|
|
||||||
|
|
||||||
const resolved = await resolveCompletedSegmentAudio(request);
|
|
||||||
if (resolved instanceof Response) return resolved;
|
|
||||||
|
|
||||||
const fallbackUrl = `/api/tts/segments/audio/fallback?documentId=${encodeURIComponent(resolved.documentId)}&segmentId=${encodeURIComponent(resolved.segmentId)}`;
|
|
||||||
const directUrl = await presignTtsSegmentAudioGet(resolved.audioKey).catch(() => null);
|
|
||||||
if (!directUrl) {
|
|
||||||
console.warn('[blob-fallback] presign segment audio unavailable, redirecting to proxy fallback', {
|
|
||||||
documentId: resolved.documentId,
|
|
||||||
segmentId: resolved.segmentId,
|
|
||||||
});
|
|
||||||
return NextResponse.redirect(fallbackUrl, {
|
|
||||||
status: 307,
|
|
||||||
headers: buildSegmentAudioCacheHeaders('redirect'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return NextResponse.redirect(directUrl, {
|
|
||||||
status: 307,
|
|
||||||
headers: buildSegmentAudioCacheHeaders('redirect'),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error creating segment audio signature:', error);
|
|
||||||
return NextResponse.json({ error: 'Failed to prepare segment audio' }, { status: 500 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -11,7 +11,6 @@ export type ResolvedSegmentAudio = {
|
||||||
audioKey: string;
|
audioKey: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TTS_SEGMENT_REDIRECT_CACHE_CONTROL = 'private, max-age=60, stale-while-revalidate=30';
|
|
||||||
export const TTS_SEGMENT_FALLBACK_CACHE_CONTROL = 'private, max-age=300, stale-while-revalidate=60';
|
export const TTS_SEGMENT_FALLBACK_CACHE_CONTROL = 'private, max-age=300, stale-while-revalidate=60';
|
||||||
export const TTS_SEGMENT_AUDIO_VARY = 'Cookie, Authorization';
|
export const TTS_SEGMENT_AUDIO_VARY = 'Cookie, Authorization';
|
||||||
|
|
||||||
|
|
@ -22,20 +21,9 @@ export function ttsSegmentsS3NotConfiguredResponse(): NextResponse {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function streamAudioBuffer(buffer: Buffer): ReadableStream<Uint8Array> {
|
export function buildSegmentAudioCacheHeaders(): Record<string, string> {
|
||||||
return new ReadableStream<Uint8Array>({
|
|
||||||
start(controller) {
|
|
||||||
controller.enqueue(new Uint8Array(buffer));
|
|
||||||
controller.close();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildSegmentAudioCacheHeaders(kind: 'redirect' | 'fallback'): Record<string, string> {
|
|
||||||
return {
|
return {
|
||||||
'Cache-Control': kind === 'redirect'
|
'Cache-Control': TTS_SEGMENT_FALLBACK_CACHE_CONTROL,
|
||||||
? TTS_SEGMENT_REDIRECT_CACHE_CONTROL
|
|
||||||
: TTS_SEGMENT_FALLBACK_CACHE_CONTROL,
|
|
||||||
Vary: TTS_SEGMENT_AUDIO_VARY,
|
Vary: TTS_SEGMENT_AUDIO_VARY,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,11 @@ import {
|
||||||
normalizeAudioByteRangeHeader,
|
normalizeAudioByteRangeHeader,
|
||||||
TTS_SEGMENT_AUDIO_VARY,
|
TTS_SEGMENT_AUDIO_VARY,
|
||||||
TTS_SEGMENT_FALLBACK_CACHE_CONTROL,
|
TTS_SEGMENT_FALLBACK_CACHE_CONTROL,
|
||||||
TTS_SEGMENT_REDIRECT_CACHE_CONTROL,
|
|
||||||
} from '../../src/lib/server/tts/segments-audio';
|
} from '../../src/lib/server/tts/segments-audio';
|
||||||
|
|
||||||
test.describe('tts segment audio cache headers', () => {
|
test.describe('tts segment audio cache headers', () => {
|
||||||
test('builds redirect cache headers', () => {
|
|
||||||
expect(buildSegmentAudioCacheHeaders('redirect')).toEqual({
|
|
||||||
'Cache-Control': TTS_SEGMENT_REDIRECT_CACHE_CONTROL,
|
|
||||||
Vary: TTS_SEGMENT_AUDIO_VARY,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('builds fallback cache headers', () => {
|
test('builds fallback cache headers', () => {
|
||||||
expect(buildSegmentAudioCacheHeaders('fallback')).toEqual({
|
expect(buildSegmentAudioCacheHeaders()).toEqual({
|
||||||
'Cache-Control': TTS_SEGMENT_FALLBACK_CACHE_CONTROL,
|
'Cache-Control': TTS_SEGMENT_FALLBACK_CACHE_CONTROL,
|
||||||
Vary: TTS_SEGMENT_AUDIO_VARY,
|
Vary: TTS_SEGMENT_AUDIO_VARY,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue