60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import prisma from '@/lib/prisma';
|
|
import { getCurrentUser } from '@/lib/auth';
|
|
import type { SummarizeRecordingResponse, SummarizeRecordingError400, SummarizeRecordingError404 } 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, transcript: true }
|
|
});
|
|
|
|
if (!recording) {
|
|
const error: SummarizeRecordingError404 = { error: 'Recording not found' };
|
|
return NextResponse.json(error, { status: 404 });
|
|
}
|
|
|
|
// Check ownership
|
|
if (recording.userId !== user.id) {
|
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
|
}
|
|
|
|
// Check if transcript exists
|
|
if (!recording.transcript) {
|
|
const error: SummarizeRecordingError400 = { error: 'Transcript not available' };
|
|
return NextResponse.json(error, { status: 400 });
|
|
}
|
|
|
|
// TODO: Call Gemini API to generate summary
|
|
// For now, we'll create a placeholder summary
|
|
const summary = `Summary of the recording (placeholder)`;
|
|
|
|
// Update recording with summary
|
|
await prisma.recording.update({
|
|
where: { id },
|
|
data: { summary }
|
|
});
|
|
|
|
const response: SummarizeRecordingResponse = {
|
|
recordingId: id,
|
|
summary,
|
|
};
|
|
|
|
return NextResponse.json(response, { status: 200 });
|
|
} catch (error) {
|
|
console.error('Summarize recording error:', error);
|
|
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
|
}
|
|
}
|