Number entries on publish, delete media, read the cover

- drafts stay unnumbered, the number is handed out when an entry goes live
- DELETE /api/v1/media/:id and a delete control in the media library
- cover_media_id in the draft read, coverMediaId and coverUrl in the archive read
This commit is contained in:
Matthias G
2026-08-01 12:25:01 +02:00
parent afaa323848
commit 2fd71fd406
31 changed files with 2286 additions and 76 deletions
+33
View File
@@ -0,0 +1,33 @@
import { findMedia } from '~/data/repositories/media'
import { resolveClient } from '~/lib/api-auth'
import { removeMedia } from '~/lib/media-delete'
import { problem } from '~/lib/problem'
export async function DELETE(request: Request, context: { params: Promise<{ id: string }> }) {
const client = await resolveClient(request)
if (!client) {
return problem(401, 'unauthorized')
}
if (client.mode !== 'write') {
return problem(403, 'forbidden', 'Dieses Token darf nur lesen.')
}
const { id } = await context.params
const item = await findMedia(id)
if (!item || (client.projectId !== null && item.projectId !== client.projectId)) {
return problem(404, 'media_not_found')
}
const result = await removeMedia(id, item.projectId)
if (!result.ok) {
return result.reason === 'in_use'
? problem(409, 'media_in_use', 'Das Bild hängt noch an einem Beitrag.')
: problem(404, 'media_not_found')
}
return Response.json({ deleted: id })
}
+2 -1
View File
@@ -1,6 +1,7 @@
import { z } from 'zod'
import { findPost, findPostIdBySlug } from '~/data/repositories/posts'
import { resolveClient } from '~/lib/api-auth'
import { withCover } from '~/lib/api-covers'
import { apiDeleteEntry, apiReadEntry, apiUpdateEntry } from '~/lib/api-entries'
import { entryProblem } from '~/lib/api-problem'
import { problem } from '~/lib/problem'
@@ -34,7 +35,7 @@ export async function GET(request: Request, context: { params: Promise<{ slug: s
const post = await findPost(slug, client.scope, client.projectId ?? undefined)
if (post) {
return Response.json(post)
return Response.json(await withCover(post))
}
const id = await findPostIdBySlug(slug)
+2 -1
View File
@@ -4,6 +4,7 @@ import { isPostTypeKey } from '~/domain/post-type'
import { apiCreateEntry } from '~/lib/api-entries'
import { entryProblem } from '~/lib/api-problem'
import { resolveClient } from '~/lib/api-auth'
import { withCovers } from '~/lib/api-covers'
import { problem } from '~/lib/problem'
const querySchema = z.object({
@@ -42,7 +43,7 @@ export async function GET(request: Request) {
})
return Response.json({
items: result.items,
items: await withCovers(result.items),
meta: { total: result.total, page: query.page, per_page: query.per_page },
})
}