Root cause of the upload failures: the launcher writes an <?xml version="1.0"?> prologue, Payload sniffs uploads with fileTypeFromBuffer, and the collection mimeTypes allowlist lacked application/xml, so every genuine launcher export was rejected with 'Invalid MIME type: application/xml'. - Add application/xml to the mod-lists upload mimeTypes (the document is still stored as text/html; verified end to end). - New pure parser src/lib/modlistPreset.ts validates the launcher export structure (arma:Type=preset meta + data-type=ModContainer rows) and is shared by the server action (authoritative) and CreateSideOpDialog (instant client-side feedback). - Plain-text lists are no longer accepted anywhere: dialog accept/hint, collection mimeTypes, and the action now agree on HTML presets only. - Upload name defaults to the preset's own arma:PresetName. - Tests: tests/int/modlist-preset.int.spec.ts (9 cases).
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { CollectionConfig } from "payload";
|
|
import path from "path";
|
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
|
|
|
export const ModLists: CollectionConfig = {
|
|
slug: "mod-lists",
|
|
admin: {
|
|
group: "Server",
|
|
},
|
|
access: {
|
|
create: requirePermission("mod-lists:create"),
|
|
update: requirePermission("mod-lists:update"),
|
|
delete: requirePermission("mod-lists:delete"),
|
|
read: requirePermission("mod-lists:read"),
|
|
},
|
|
fields: [
|
|
{
|
|
name: "modlistName",
|
|
type: "text",
|
|
admin: {
|
|
description: "A friendly name for the mod list.",
|
|
},
|
|
required: true,
|
|
},
|
|
{
|
|
name: "author",
|
|
type: "relationship",
|
|
relationTo: "users",
|
|
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: {
|
|
staticDir: path.resolve(process.cwd(), "media", "mod-lists"),
|
|
// Only Arma 3 Launcher preset exports; uploadSideOpModlist validates the
|
|
// file contents (arma:Type meta + ModContainer rows) before storing.
|
|
// application/xml is required because the launcher writes an
|
|
// `<?xml version="1.0"?>` prologue and Payload sniffs uploads with
|
|
// fileTypeFromBuffer, which reports those bytes as application/xml —
|
|
// without this entry every genuine launcher export fails with
|
|
// "Invalid MIME type: application/xml". The document itself is stored
|
|
// with the text/html mimetype the action passes.
|
|
mimeTypes: ["text/html", "application/xml"],
|
|
},
|
|
};
|