ordinarthur 6dcae6956c
All checks were successful
Build & Deploy Web / build-and-deploy (push) Successful in 1m32s
Build & Deploy API / build-and-deploy (push) Successful in 2m20s
Build & Deploy Landing / build-and-deploy (push) Successful in 1m20s
feat(blog): admin CRUD + image upload + sidebar link
L'éditeur du blog (jusqu'ici limité au seeder) a maintenant une vraie
interface au-dessus de l'API.

Backend (apps/api) :
* Migration users.is_admin (boolean default false).
* Middleware admin (404 si user.is_admin=false après auth).
* Commande ace promote:admin --email=… [--revoke].
* AdminPostsController CRUD complet : list/show/store/update/publish/
  unpublish/destroy + suggest-slug. Au save, contentHtml + wordCount +
  readingTime sont re-calculés via blog_renderer. Au publish, durcit la
  validation SEO (titre ≤60, excerpt 120-160, hero+alt requis, ≥600 mots),
  flippe status='published' + publishedAt, ping Google+Bing pour le sitemap.
* BlogUploadsController :
  - POST /api/v1/admin/uploads (multipart, JPEG/PNG/WebP, max 4MB)
    → MinIO clé uploads/blog/{uuid}.{ext}
    → renvoie URL relative /api/v1/uploads/blog/{filename}
  - GET /api/v1/uploads/blog/:filename (public, cache immutable 1 an)
    → stream depuis MinIO, regex anti-traversal sur le nom.
* UserTransformer expose isAdmin (cf. shared/types/user).
* k3s/app/landing.yml : NodePort 30111 explicite (pour Traefik repo proxmox).

Frontend (apps/web) :
* Lib typée admin-blog (calls API, queryKeys, helpers URL).
* Route /admin/blog : liste filtrable avec status badge, ouverture
  publique, dépublier, supprimer, "+ Nouveau brouillon".
* Route /admin/blog/:id : éditeur 2-colonnes
  - Gauche : @uiw/react-md-editor (lazy import) avec preview live.
  - Droite : hero image (drag&drop + alt), excerpt avec compteur
    120-160, tags, aperçu Google snippet, validations bloquantes.
  - Autosave debounce 2s + bouton Publier qui sauve d'abord.
  - Hero image upload via MinIO (HeroImageUpload component).
* Sidebar : lien "Blog (admin)" si user.isAdmin.
* Gate côté client (beforeLoad redirect si non admin) + côté serveur
  (middleware admin) — defense in depth.

Note : les requirements de publish miroir backend ↔ frontend (cf.
PUBLISH_REQUIREMENTS dans validators/post.ts et VALIDATION_RULES dans
admin.blog_.\$id.tsx). À synchroniser si un seuil bouge.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 17:25:34 +02:00

73 lines
2.5 KiB
TypeScript

import vine from '@vinejs/vine'
/**
* Règles SEO + édito :
* - title ≤ 60 chars (sweet spot Google snippet)
* - excerpt 120-160 chars (sweet spot meta description)
* - slug kebab-case ASCII unique
* - tags max 5
*/
const slug = () =>
vine
.string()
.minLength(3)
.maxLength(200)
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
const title = () => vine.string().minLength(5).maxLength(80)
const excerpt = () => vine.string().minLength(80).maxLength(280)
const tags = () => vine.array(vine.string().maxLength(50)).maxLength(5).distinct()
/**
* Création d'un brouillon. On accepte `status` mais c'est toujours `draft`
* à la création — la publication passe par /publish.
*/
export const createPostValidator = vine.compile(
vine.object({
slug: slug(),
title: title(),
excerpt: excerpt(),
contentMd: vine.string().minLength(50),
tags: tags().optional(),
authorName: vine.string().minLength(2).maxLength(100).optional(),
heroImageUrl: vine.string().url().nullable().optional(),
heroImageAlt: vine.string().maxLength(250).nullable().optional(),
ogImageUrl: vine.string().url().nullable().optional(),
canonicalUrl: vine.string().url().nullable().optional(),
noindex: vine.boolean().optional(),
}),
)
/**
* Update partiel d'un post existant. Tous les champs optionnels.
* `status` n'est pas mutable ici (passer par publish/unpublish).
*/
export const updatePostValidator = vine.compile(
vine.object({
slug: slug().optional(),
title: title().optional(),
excerpt: excerpt().optional(),
contentMd: vine.string().minLength(50).optional(),
tags: tags().optional(),
authorName: vine.string().minLength(2).maxLength(100).optional(),
heroImageUrl: vine.string().url().nullable().optional(),
heroImageAlt: vine.string().maxLength(250).nullable().optional(),
ogImageUrl: vine.string().url().nullable().optional(),
canonicalUrl: vine.string().url().nullable().optional(),
noindex: vine.boolean().optional(),
}),
)
/**
* Au publish on durcit les règles SEO inline dans AdminPostsController.publish
* (cf. PUBLISH_REQUIREMENTS) — pas un validator vine séparé car on raisonne
* sur l'objet Post déjà persisté (avec wordCount calculé), pas sur un payload
* de requête.
*/
export const PUBLISH_REQUIREMENTS = {
titleMaxChars: 60, // sweet spot snippet Google
excerptMinChars: 120,
excerptMaxChars: 160,
minWordCount: 600, // ~3 min de lecture, considéré "substantiel"
} as const