fix: improve delete library response message and add media deletion step

This commit is contained in:
tigeren 2025-08-26 02:36:36 +00:00
parent 6f938243ad
commit 6c58219ea0
2 changed files with 6 additions and 1 deletions

BIN
media.db

Binary file not shown.

View File

@ -10,12 +10,17 @@ export async function DELETE(request: NextRequest, { params: paramsPromise }: {
}
try {
// First, delete all media associated with this library
db.prepare('DELETE FROM media WHERE library_id = ?').run(id);
// Then delete the library itself
const info = db.prepare('DELETE FROM libraries WHERE id = ?').run(id);
if (info.changes === 0) {
return NextResponse.json({ error: 'Library not found' }, { status: 404 });
}
return NextResponse.json({ message: 'Library deleted' });
return NextResponse.json({ message: 'Library deleted successfully' });
} catch (error: any) {
console.error('Error deleting library:', error);
return NextResponse.json({ error: error.message }, { status: 500 });
}
}