56 lines
2.1 KiB
TypeScript
56 lines
2.1 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"],
|
|
// Payload streams uploads inline by default, so the browser renders the
|
|
// preset HTML instead of saving it. Force a download for every link to the
|
|
// file (the Discord modlist embed and the web UI both use this URL).
|
|
modifyResponseHeaders: ({ headers }) => {
|
|
headers.set("Content-Disposition", "attachment");
|
|
return headers;
|
|
},
|
|
},
|
|
};
|