feat: connect guarded asset import api

This commit is contained in:
simoleo89
2026-07-12 19:12:25 +02:00
parent 3497df9dfd
commit eb759f54bf
26 changed files with 2342 additions and 24 deletions
+27
View File
@@ -0,0 +1,27 @@
import { withAdmin } from '@/lib/api-handler'
import { apiError, apiOk } from '@/lib/api-response'
import { PERMS } from '@/lib/permissions'
import { logAudit } from '@/lib/services/audit'
import { deleteImportedPet, getPetList, getPetStats } from '@/lib/services/pet-import'
export const GET = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request) => {
if (request.nextUrl.searchParams.get('action') === 'stats') return apiOk(getPetStats())
const search = request.nextUrl.searchParams.get('search') || ''
return apiOk({ pets: getPetList(search) })
})
export const DELETE = withAdmin({ permission: PERMS.ASSETS_IMPORT }, async (request, ctx) => {
const lib = request.nextUrl.searchParams.get('lib')
if (!lib) return apiError('Missing lib', 400)
const { deletedFile } = await deleteImportedPet(lib)
if (!deletedFile) return apiError(`Pet "${lib}" not found`, 404)
logAudit({
userId: ctx.session.user.id,
action: 'pet_delete',
target: 'PetAsset',
targetId: 0,
after: { lib },
})
return apiOk({ lib, deletedFile })
})