fix(uploads): store upload collections under the persistent media volume
VoiceSubmissions, ModLists and MissionFiles relied on Payload's default upload staticDir (the collection slug resolved from cwd), so prod wrote their files to /app/<slug> instead of the mounted /app/media volume and every redeploy wiped them (voice takes returned 500 on play/download). Pin all three under media/ subdirs like story Voiceovers already does, add regression guards, and fix the audio-preview fallbacks that pointed at the media collection's file route instead of the owning collection.
This commit is contained in:
parent
6cd94c31f8
commit
8e42077c1f
7 changed files with 58 additions and 7 deletions
|
|
@ -173,7 +173,15 @@ For dev (where `push: false` in `payload.config.ts`), run `bun run payload migra
|
||||||
|
|
||||||
## 8. Persistent media volume — important for rollbacks
|
## 8. Persistent media volume — important for rollbacks
|
||||||
|
|
||||||
Payload's `Media` collection (`src/collections/Media.ts`) uses `upload: true` with no storage adapter, so files land on local disk under `<projectRoot>/media` (i.e. `/app/media` inside the container, since `WORKDIR /app` and `process.cwd() = /app`).
|
Every upload collection stores files on local disk under `<projectRoot>/media` (i.e. `/app/media` inside the container, since `WORKDIR /app` and `process.cwd() = /app`). `Media` uses the default (slug) staticDir, which happens to resolve there; the others set it explicitly (`staticDir: path.resolve(process.cwd(), "media", "<subdir>")`) because Payload otherwise defaults an upload collection's staticDir to its own slug resolved from cwd (see the comment on `story/Voiceovers.ts`):
|
||||||
|
|
||||||
|
- `media` → `media/`
|
||||||
|
- `story-voiceovers` → `media/story-voiceovers/`
|
||||||
|
- `voice-submissions` → `media/voice-submissions/`
|
||||||
|
- `mod-lists` → `media/mod-lists/`
|
||||||
|
- `mission-files` → `media/mission-files/`
|
||||||
|
|
||||||
|
Any new upload collection MUST set an explicit `staticDir` under `media/` the same way, or its files land in an unmounted directory and vanish on every redeploy.
|
||||||
|
|
||||||
In Coolify:
|
In Coolify:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { CollectionConfig } from "payload";
|
import { CollectionConfig } from "payload";
|
||||||
|
import path from "path";
|
||||||
import { requirePermission } from "@/utils/access-control/hasPermission";
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
||||||
|
|
||||||
export const MissionFiles: CollectionConfig = {
|
export const MissionFiles: CollectionConfig = {
|
||||||
|
|
@ -25,7 +26,13 @@ export const MissionFiles: CollectionConfig = {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
// 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 <cwd>/mission-files and miss the persistent
|
||||||
|
// /app/media volume in production (PBOs vanish on every redeploy). media/
|
||||||
|
// is gitignored.
|
||||||
upload: {
|
upload: {
|
||||||
|
staticDir: path.resolve(process.cwd(), "media", "mission-files"),
|
||||||
mimeTypes: ["application/octet-stream"],
|
mimeTypes: ["application/octet-stream"],
|
||||||
},
|
},
|
||||||
hooks: {
|
hooks: {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { CollectionConfig } from "payload";
|
import { CollectionConfig } from "payload";
|
||||||
|
import path from "path";
|
||||||
import { requirePermission } from "@/utils/access-control/hasPermission";
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
||||||
|
|
||||||
export const ModLists: CollectionConfig = {
|
export const ModLists: CollectionConfig = {
|
||||||
|
|
@ -28,7 +29,13 @@ export const ModLists: CollectionConfig = {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
// 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 <cwd>/mod-lists and miss the persistent
|
||||||
|
// /app/media volume in production (lists vanish on every redeploy). media/
|
||||||
|
// is gitignored.
|
||||||
upload: {
|
upload: {
|
||||||
|
staticDir: path.resolve(process.cwd(), "media", "mod-lists"),
|
||||||
mimeTypes: ["text/html", "text/plain"],
|
mimeTypes: ["text/html", "text/plain"],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {
|
||||||
type CollectionAfterChangeHook,
|
type CollectionAfterChangeHook,
|
||||||
type CollectionBeforeChangeHook,
|
type CollectionBeforeChangeHook,
|
||||||
} from "payload";
|
} from "payload";
|
||||||
|
import path from "path";
|
||||||
import type { User, VoiceScript, VoiceSubmission } from "@/payload-types";
|
import type { User, VoiceScript, VoiceSubmission } from "@/payload-types";
|
||||||
import hasRoles from "@/utils/access-control/hasRoles";
|
import hasRoles from "@/utils/access-control/hasRoles";
|
||||||
import { isSuperuser } from "@/utils/access-control/hasPermission";
|
import { isSuperuser } from "@/utils/access-control/hasPermission";
|
||||||
|
|
@ -273,7 +274,15 @@ export const VoiceSubmissions: CollectionConfig = {
|
||||||
// allowlist rejects browser-recorded takes. The submit action is the gate
|
// allowlist rejects browser-recorded takes. The submit action is the gate
|
||||||
// instead (audio/* base type + size cap); restricted file types (executables,
|
// instead (audio/* base type + size cap); restricted file types (executables,
|
||||||
// scripts, …) stay blocked by Payload's built-in checks.
|
// scripts, …) stay blocked by Payload's built-in checks.
|
||||||
upload: true,
|
//
|
||||||
|
// 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 <cwd>/voice-submissions and miss the persistent
|
||||||
|
// /app/media volume in production (takes vanish on every redeploy). media/ is
|
||||||
|
// gitignored.
|
||||||
|
upload: {
|
||||||
|
staticDir: path.resolve(process.cwd(), "media", "voice-submissions"),
|
||||||
|
},
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
hooks: {
|
hooks: {
|
||||||
beforeChange: [guardReviewTransition],
|
beforeChange: [guardReviewTransition],
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,13 @@ const formatBytes = (bytes: number | null | undefined): string => {
|
||||||
* Reads the document's file URL from document info (no form state involved).
|
* Reads the document's file URL from document info (no form state involved).
|
||||||
*/
|
*/
|
||||||
export const AudioPreviewField = () => {
|
export const AudioPreviewField = () => {
|
||||||
const { data } = useDocumentInfo();
|
const { data, collectionSlug } = useDocumentInfo();
|
||||||
const doc = (data ?? {}) as UploadDocData;
|
const doc = (data ?? {}) as UploadDocData;
|
||||||
const url = doc.url ?? (doc.filename ? `/api/media/file/${doc.filename}` : "");
|
// File URLs are served per collection (/api/<slug>/file/<filename>) — fall
|
||||||
|
// back to THIS collection's route, never another collection's.
|
||||||
|
const url =
|
||||||
|
doc.url ??
|
||||||
|
(doc.filename && collectionSlug ? `/api/${collectionSlug}/file/${doc.filename}` : "");
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,12 @@ export interface VoiceoverScriptView {
|
||||||
otherSubmissionCount: number;
|
otherSubmissionCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Upload docs expose `url`; fall back to the media file route like wiki image uploads do. */
|
/** Upload docs expose `url`; fall back to this collection's own file route (files are served per collection). */
|
||||||
function submissionAudioUrl(submission: VoiceSubmission): string {
|
function submissionAudioUrl(submission: VoiceSubmission): string {
|
||||||
return submission.url ?? (submission.filename ? `/api/media/file/${submission.filename}` : "");
|
return (
|
||||||
|
submission.url ??
|
||||||
|
(submission.filename ? `/api/voice-submissions/file/${submission.filename}` : "")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toSubmissionSummary(submission: VoiceSubmission): VoiceoverSubmissionSummary {
|
function toSubmissionSummary(submission: VoiceSubmission): VoiceoverSubmissionSummary {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
import { VoiceSubmissions } from "@/collections/voiceover/VoiceSubmissions";
|
import { VoiceSubmissions } from "@/collections/voiceover/VoiceSubmissions";
|
||||||
|
|
||||||
|
|
@ -8,6 +9,18 @@ describe("VoiceSubmissions upload config", () => {
|
||||||
// every in-browser recording. The collection must accept any audio format;
|
// every in-browser recording. The collection must accept any audio format;
|
||||||
// the submit server action is the audio/* gate instead.
|
// the submit server action is the audio/* gate instead.
|
||||||
it("accepts any standard audio format (no MIME allowlist)", () => {
|
it("accepts any standard audio format (no MIME allowlist)", () => {
|
||||||
expect(VoiceSubmissions.upload).toBe(true);
|
expect(VoiceSubmissions.upload).toBeDefined();
|
||||||
|
expect(VoiceSubmissions.upload).not.toHaveProperty("mimeTypes");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Regression guard: Payload defaults an upload collection's staticDir to its
|
||||||
|
// slug resolved from cwd (dist/collections/config/sanitize.js). Without an
|
||||||
|
// explicit override, takes are written to <cwd>/voice-submissions, which is
|
||||||
|
// NOT the persistent /app/media volume in production — every redeploy wipes
|
||||||
|
// them and playback/download 404s (2026-10 prod incident).
|
||||||
|
it("stores files under the persistent media volume (explicit staticDir)", () => {
|
||||||
|
expect(VoiceSubmissions.upload).toMatchObject({
|
||||||
|
staticDir: path.resolve(process.cwd(), "media", "voice-submissions"),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue