import { NextRequest, NextResponse } from 'next/server' import { getLibrary, resolveLibraryRoot } from '@/lib/libraries' import { scanDirectory } from '@/lib/files' import { requireLibraryAccess } from '@/lib/auth' export async function GET(request: NextRequest) { const { searchParams } = request.nextUrl const libraryId = searchParams.get('libraryId') const subpath = searchParams.get('path') ?? '' if (!libraryId) { return NextResponse.json({ error: 'Missing libraryId' }, { status: 400 }) } const auth = await requireLibraryAccess(request, libraryId) if (auth instanceof NextResponse) return auth const library = getLibrary(libraryId) if (!library) { return NextResponse.json({ error: 'Library not found' }, { status: 404 }) } if (library.type !== 'mixed') { return NextResponse.json({ error: 'Library is not a mixed library' }, { status: 400 }) } const root = resolveLibraryRoot(library) const listing = scanDirectory(root, libraryId, subpath) return NextResponse.json(listing) }