Compare commits
No commits in common. "81d31d705de44dc3ff9313ea1471f7f5d74986bf" and "6cd94c31f8230d5dcf5405ebd0efe277d30965fc" have entirely different histories.
81d31d705d
...
6cd94c31f8
8 changed files with 8 additions and 59 deletions
|
|
@ -173,15 +173,7 @@ 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
|
||||||
|
|
||||||
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`):
|
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`).
|
||||||
|
|
||||||
- `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,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "polaris-task-force",
|
"name": "polaris-task-force",
|
||||||
"version": "0.7.1",
|
"version": "0.7.0",
|
||||||
"description": "Web app for the Arma 3 unit Polaris Task Force. Uses Next.js for client- and server-side rendering, with a Postgres database and some other neat libraries.",
|
"description": "Web app for the Arma 3 unit Polaris Task Force. Uses Next.js for client- and server-side rendering, with a Postgres database and some other neat libraries.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
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 = {
|
||||||
|
|
@ -26,13 +25,7 @@ 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,5 +1,4 @@
|
||||||
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 = {
|
||||||
|
|
@ -29,13 +28,7 @@ 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,7 +3,6 @@ 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";
|
||||||
|
|
@ -274,15 +273,7 @@ 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,13 +23,9 @@ 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, collectionSlug } = useDocumentInfo();
|
const { data } = useDocumentInfo();
|
||||||
const doc = (data ?? {}) as UploadDocData;
|
const doc = (data ?? {}) as UploadDocData;
|
||||||
// File URLs are served per collection (/api/<slug>/file/<filename>) — fall
|
const url = doc.url ?? (doc.filename ? `/api/media/file/${doc.filename}` : "");
|
||||||
// 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,12 +30,9 @@ export interface VoiceoverScriptView {
|
||||||
otherSubmissionCount: number;
|
otherSubmissionCount: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Upload docs expose `url`; fall back to this collection's own file route (files are served per collection). */
|
/** Upload docs expose `url`; fall back to the media file route like wiki image uploads do. */
|
||||||
function submissionAudioUrl(submission: VoiceSubmission): string {
|
function submissionAudioUrl(submission: VoiceSubmission): string {
|
||||||
return (
|
return submission.url ?? (submission.filename ? `/api/media/file/${submission.filename}` : "");
|
||||||
submission.url ??
|
|
||||||
(submission.filename ? `/api/voice-submissions/file/${submission.filename}` : "")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toSubmissionSummary(submission: VoiceSubmission): VoiceoverSubmissionSummary {
|
function toSubmissionSummary(submission: VoiceSubmission): VoiceoverSubmissionSummary {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
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";
|
||||||
|
|
||||||
|
|
@ -9,18 +8,6 @@ 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).toBeDefined();
|
expect(VoiceSubmissions.upload).toBe(true);
|
||||||
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