add tag imports

This commit is contained in:
Garret Patti
2026-04-19 21:41:34 -04:00
parent 95bcaf53be
commit 0842769125
12 changed files with 1002 additions and 1 deletions

View File

@@ -0,0 +1,16 @@
import { NextRequest, NextResponse } from 'next/server'
import { getImportedTagsForLibrary } from '@/lib/comic-metadata'
import { requireAdmin } from '@/lib/auth'
export async function GET(request: NextRequest) {
const auth = await requireAdmin(request)
if (auth instanceof NextResponse) return auth
const libraryId = request.nextUrl.searchParams.get('libraryId')
if (!libraryId) {
return NextResponse.json({ error: 'libraryId is required' }, { status: 400 })
}
const tags = getImportedTagsForLibrary(libraryId)
return NextResponse.json(tags)
}

View File

@@ -0,0 +1,34 @@
import { NextRequest, NextResponse } from 'next/server'
import { getLibrary } from '@/lib/libraries'
import { importComicMetadata } from '@/lib/comic-metadata'
import { requireAdmin } from '@/lib/auth'
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const auth = await requireAdmin(request)
if (auth instanceof NextResponse) return auth
const { id } = await params
const library = getLibrary(id)
if (!library) {
return NextResponse.json({ error: 'Library not found' }, { status: 404 })
}
if (library.type !== 'comics') {
return NextResponse.json({ error: 'Metadata import is only supported for comic libraries' }, { status: 400 })
}
// Fire-and-forget
void Promise.resolve().then(() => {
try {
importComicMetadata(library)
} catch (err) {
console.error(`[import-metadata] Error importing metadata for "${library.name}":`, err)
}
})
return new NextResponse(null, { status: 202 })
}

View File

@@ -0,0 +1,21 @@
import { NextRequest, NextResponse } from 'next/server'
import { deleteTagMapping } from '@/lib/comic-metadata'
import { requireAdmin } from '@/lib/auth'
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const auth = await requireAdmin(request)
if (auth instanceof NextResponse) return auth
const { id } = await params
try {
deleteTagMapping(id)
return new NextResponse(null, { status: 204 })
} catch (err) {
const message = err instanceof Error ? err.message : 'Failed to delete mapping'
return NextResponse.json({ error: message }, { status: 404 })
}
}

View File

@@ -0,0 +1,44 @@
import { NextRequest, NextResponse } from 'next/server'
import { getTagMappingsForLibrary, createTagMapping } from '@/lib/comic-metadata'
import { requireAdmin } from '@/lib/auth'
export async function GET(request: NextRequest) {
const auth = await requireAdmin(request)
if (auth instanceof NextResponse) return auth
const libraryId = request.nextUrl.searchParams.get('libraryId')
if (!libraryId) {
return NextResponse.json({ error: 'libraryId is required' }, { status: 400 })
}
const mappings = getTagMappingsForLibrary(libraryId)
return NextResponse.json(mappings)
}
export async function POST(request: NextRequest) {
const auth = await requireAdmin(request)
if (auth instanceof NextResponse) return auth
let body: { libraryId?: string; importedTagName?: string; tagId?: string }
try {
body = await request.json()
} catch {
return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 })
}
const { libraryId, importedTagName, tagId } = body
if (!libraryId || !importedTagName || !tagId) {
return NextResponse.json(
{ error: 'libraryId, importedTagName, and tagId are required' },
{ status: 400 }
)
}
try {
const mapping = createTagMapping(libraryId, importedTagName, tagId)
return NextResponse.json(mapping, { status: 201 })
} catch (err) {
const message = err instanceof Error ? err.message : 'Failed to create mapping'
return NextResponse.json({ error: message }, { status: 400 })
}
}