react-audit(família 5): Media.ts sem hooks de revalidação — getCachedDocumentById('media') (documentReads.ts:43) nunca invalidava em edição/deleção no admin; afterChange+afterDelete espelham Post/Petition

This commit is contained in:
Francisco Solla 2026-08-25 12:23:40 -03:00
parent 43a3b21cf4
commit 63cef265c2

View file

@ -1,4 +1,5 @@
import { canManagePublishedContent } from '@/utilities/campaignAccess'
import { revalidateDocumentById } from '@/utilities/documents'
import type { CollectionConfig } from 'payload'
export const Media: CollectionConfig = {
@ -18,6 +19,21 @@ export const Media: CollectionConfig = {
update: canManagePublishedContent,
delete: canManagePublishedContent,
},
// The public pages read media through `getCachedDocumentById('media', …)`
// (`unstable_cache` under the `document_media:<id>` tag), so admin edits and
// deletions must bust that cache — same contract as Post/Petition.
hooks: {
afterChange: [
({ doc, previousDoc }) => {
revalidateDocumentById('media', previousDoc?.id ?? doc.id)
},
],
afterDelete: [
({ doc }) => {
revalidateDocumentById('media', doc.id)
},
],
},
fields: [
{
name: 'alt',