ai starter implementation

This commit is contained in:
Garret Patti
2026-04-12 15:39:48 -04:00
parent 0238dbda7a
commit 732e9134c3
5 changed files with 212 additions and 5 deletions

View File

@@ -0,0 +1,39 @@
import { NextRequest, NextResponse } from 'next/server'
import { requireLibraryAccess } from '@/lib/auth'
import { tagSingleItem } from '@/lib/ai-tagger'
export async function POST(request: NextRequest) {
let body: { itemKey?: string }
try {
body = await request.json()
} catch {
return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 })
}
const { itemKey } = body
if (!itemKey || typeof itemKey !== 'string') {
return NextResponse.json({ error: 'itemKey is required' }, { status: 400 })
}
const libraryId = itemKey.split(':')[0]
const auth = await requireLibraryAccess(request, libraryId)
if (auth instanceof NextResponse) return auth
try {
const tagIds = await tagSingleItem(itemKey)
return NextResponse.json({ tagIds })
} catch (err) {
const error = err as Error & { code?: string }
if (error.code === 'NOT_CONFIGURED') {
return NextResponse.json({ error: error.message }, { status: 400 })
}
if (error.code === 'NOT_FOUND') {
return NextResponse.json({ error: error.message }, { status: 404 })
}
if (error.code === 'NO_IMAGE') {
return NextResponse.json({ error: error.message }, { status: 404 })
}
console.error('[ai-tagging] Error tagging item:', error)
return NextResponse.json({ error: 'AI tagging failed' }, { status: 502 })
}
}

View File

@@ -174,7 +174,7 @@ export default function AiTaggingPage() {
</span>
</label>
<p className="mt-1 text-xs" style={{ color: 'var(--text-secondary)' }}>
When enabled, new media will be automatically tagged during library scans.
When enabled, new media will be automatically tagged during library scans. On-demand tagging from image cards is always available when an endpoint is configured.
</p>
</Field>