add tag imports
This commit is contained in:
16
src/app/api/imported-tags/route.ts
Normal file
16
src/app/api/imported-tags/route.ts
Normal 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)
|
||||
}
|
||||
34
src/app/api/libraries/[id]/import-metadata/route.ts
Normal file
34
src/app/api/libraries/[id]/import-metadata/route.ts
Normal 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 })
|
||||
}
|
||||
21
src/app/api/tag-mappings/[id]/route.ts
Normal file
21
src/app/api/tag-mappings/[id]/route.ts
Normal 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 })
|
||||
}
|
||||
}
|
||||
44
src/app/api/tag-mappings/route.ts
Normal file
44
src/app/api/tag-mappings/route.ts
Normal 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 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user