import path from "path"; import type { CollectionConfig } from "payload"; import hasRoles from "@/utils/access-control/hasRoles"; function isStoryAuthor(user: Parameters[1]): boolean { return hasRoles(["admin", "developer"], user); } export const Voiceovers: CollectionConfig = { slug: "story-voiceovers", labels: { singular: "Chronicle Voiceover", plural: "Chronicle Voiceovers", }, admin: { group: "Chronicle", useAsTitle: "filename", defaultColumns: ["filename", "mimeType", "updatedAt"], description: "Audio narrations for Chronicle entries. Attach to an entry via its Voiceover field.", }, access: { read: ({ req }) => Boolean(req.user), create: ({ req }) => isStoryAuthor(req.user), update: ({ req }) => isStoryAuthor(req.user), delete: ({ req }) => isStoryAuthor(req.user), }, // staticDir must be set explicitly: Payload defaults an upload collection's // staticDir to its slug resolved from cwd (dist/collections/config/sanitize.js), // which would write files to /story-voiceovers and miss the persistent // /app/media volume in production. media/ is gitignored. upload: { staticDir: path.resolve(process.cwd(), "media", "story-voiceovers"), mimeTypes: ["audio/*"], }, fields: [ { name: "aiGenerated", type: "checkbox", label: "AI-generated", defaultValue: false, admin: { description: "Tick if this narration was generated by AI (text-to-speech) rather than recorded by a person. Adds a note under the player on /story.", }, }, ], };