53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import prisma from '@/lib/prisma';
|
|
import { getCurrentUser } from '@/lib/auth';
|
|
import type { TranscribeRecordingResponse, TranscribeRecordingError404 } from '@/types/api-types';
|
|
|
|
export async function POST(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
const user = await getCurrentUser();
|
|
if (!user) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const { id } = await params;
|
|
|
|
const recording = await prisma.recording.findUnique({
|
|
where: { id },
|
|
select: { userId: true, audioFilePath: true }
|
|
});
|
|
|
|
if (!recording) {
|
|
const error: TranscribeRecordingError404 = { error: 'Recording not found' };
|
|
return NextResponse.json(error, { status: 404 });
|
|
}
|
|
|
|
// Check ownership
|
|
if (recording.userId !== user.id) {
|
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
|
}
|
|
|
|
// Set transcribing flag
|
|
await prisma.recording.update({
|
|
where: { id },
|
|
data: { isTranscribing: true }
|
|
});
|
|
|
|
// TODO: Trigger Whisper STT transcription job
|
|
// For now, we'll just set the flag and return
|
|
|
|
const response: TranscribeRecordingResponse = {
|
|
recordingId: id,
|
|
isTranscribing: true,
|
|
};
|
|
|
|
return NextResponse.json(response, { status: 200 });
|
|
} catch (error) {
|
|
console.error('Transcribe recording error:', error);
|
|
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
|
}
|
|
}
|