105 lines
2.9 KiB
TypeScript
105 lines
2.9 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import prisma from '@/lib/prisma';
|
|
import { getCurrentUser } from '@/lib/auth';
|
|
import type { GetRecordingResponse, GetRecordingError404, DeleteRecordingResponse, DeleteRecordingError404 } from '@/types/api-types';
|
|
|
|
export async function GET(
|
|
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: {
|
|
id: true,
|
|
userId: true,
|
|
title: true,
|
|
audioFilePath: true,
|
|
duration: true,
|
|
transcript: true,
|
|
summary: true,
|
|
isTranscribing: true,
|
|
createdAt: true,
|
|
}
|
|
});
|
|
|
|
if (!recording) {
|
|
const error: GetRecordingError404 = { error: 'Recording not found' };
|
|
return NextResponse.json(error, { status: 404 });
|
|
}
|
|
|
|
// Check ownership
|
|
if (recording.userId !== user.id) {
|
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
|
}
|
|
|
|
const response: GetRecordingResponse = {
|
|
id: recording.id,
|
|
title: recording.title,
|
|
audioFilePath: recording.audioFilePath,
|
|
duration: recording.duration,
|
|
transcript: recording.transcript || '',
|
|
summary: recording.summary || '',
|
|
isTranscribing: recording.isTranscribing,
|
|
createdAt: recording.createdAt.toISOString(),
|
|
};
|
|
|
|
return NextResponse.json(response, { status: 200 });
|
|
} catch (error) {
|
|
console.error('Get recording error:', error);
|
|
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function DELETE(
|
|
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: DeleteRecordingError404 = { error: 'Recording not found' };
|
|
return NextResponse.json(error, { status: 404 });
|
|
}
|
|
|
|
// Check ownership
|
|
if (recording.userId !== user.id) {
|
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
|
|
}
|
|
|
|
// Delete recording
|
|
await prisma.recording.delete({
|
|
where: { id }
|
|
});
|
|
|
|
// TODO: Delete audio file from MinIO/S3
|
|
|
|
const response: DeleteRecordingResponse = {
|
|
success: true,
|
|
};
|
|
|
|
return NextResponse.json(response, { status: 200 });
|
|
} catch (error) {
|
|
console.error('Delete recording error:', error);
|
|
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
|
}
|
|
}
|