- Add `movies` type: per-movie folders with video files, poster/backdrop images, and optional Jellyfin NFO metadata (title, year, plot, rating, genres, runtime). Grid view with 2:3 poster art, detail modal with play and two-click delete of the movie folder. - Add `tv` type: Series -> Season -> Episode hierarchy with lazy loading at each level. Reads tvshow.nfo and episodedetails NFO files for metadata. Episode grid with video thumbnails, streams via existing video player. Delete is limited to the entire series folder to avoid breaking Jellyfin. - Add fast-xml-parser dependency for Kodi/Jellyfin NFO parsing (lib/nfo.ts) - Migrate existing DB to expand the libraries CHECK constraint to include the two new types; migration is idempotent and preserves existing data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { getLibraries, addLibrary } from '@/lib/libraries'
|
|
import type { LibraryType } from '@/types'
|
|
|
|
export function GET() {
|
|
try {
|
|
const libraries = getLibraries()
|
|
return NextResponse.json(libraries)
|
|
} catch (err) {
|
|
console.error('Failed to read libraries', err)
|
|
return NextResponse.json({ error: 'Failed to load libraries' }, { status: 500 })
|
|
}
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
let body: { name?: string; path?: string; type?: string }
|
|
try {
|
|
body = await request.json()
|
|
} catch {
|
|
return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 })
|
|
}
|
|
|
|
const { name, path, type } = body
|
|
|
|
if (!name || !path || !type) {
|
|
return NextResponse.json({ error: 'name, path, and type are required' }, { status: 400 })
|
|
}
|
|
|
|
const validTypes: LibraryType[] = ['games', 'mixed', 'movies', 'tv']
|
|
if (!validTypes.includes(type as LibraryType)) {
|
|
return NextResponse.json({ error: `type must be one of: ${validTypes.join(', ')}` }, { status: 400 })
|
|
}
|
|
|
|
try {
|
|
const library = addLibrary(name, path, type as LibraryType)
|
|
return NextResponse.json(library, { status: 201 })
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : 'Failed to add library'
|
|
return NextResponse.json({ error: message }, { status: 400 })
|
|
}
|
|
}
|