1
0
Fork 0

Compare commits

..

No commits in common. "e57633c57542ad611d4238b75fc8bd131b08841e" and "81d31d705de44dc3ff9313ea1471f7f5d74986bf" have entirely different histories.

7 changed files with 18 additions and 227 deletions

View file

@ -1,39 +1,5 @@
# Changelog
# v0.7.2
A small but important patch: uploading a mod list with a side op was broken for everyone, and now it works.
### Fixes
- **Mod list uploads work again.** Export files from the launcher were being rejected even when they were perfectly valid. Uploads now go through, and the list picks up its name straight from the preset. If a file isn't a proper Arma 3 Launcher export, you get clear instructions on how to export one instead of a mystery error.
---
# v0.7.1
A small patch focused on keeping the things you upload safe.
### Fixes
- **Uploads survive site updates.** Voice takes, mod lists, and mission files were being stored in a spot that got wiped on every site update, which is why some voice takes had stopped playing or downloading. They now live in permanent storage, and anything you upload from here on sticks around.
---
# v0.7.0
Mostly staff-side tooling under the hood this time. Players see two small touches.
### Features
- **Sensitive, marked.** Restricted entries on the dashboard's Recent Events list now show a small lock icon, so you can tell at a glance which log entries are sensitive.
### Fixes
- The countdown timer in conversations now spaces its time units more evenly.
---
# v0.6.0
NPC conversations get a lot deeper this time: they remember what you have done, mark what you have not seen yet, and some of them only open once you have earned them.

View file

@ -1,6 +1,6 @@
{
"name": "polaris-task-force",
"version": "0.7.2",
"version": "0.7.1",
"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",
"type": "module",

View file

@ -23,7 +23,6 @@ import {
zonedParts,
zonedWeekday,
} from "@/lib/intelligence/fridayTime";
import { describeArmaPresetFailure, parseArmaPreset } from "@/lib/modlistPreset";
import type { Mission, User } from "@/payload-types";
export interface ActionResult<T = undefined> {
@ -211,16 +210,17 @@ export async function uploadSideOpModlist(
if (file.size > 10 * 1024 * 1024) {
return { success: false, error: "Mod list file must be 10 MB or smaller." };
}
// Only genuine Arma 3 Launcher preset exports are accepted. Validate the
// file CONTENTS, not the extension or the browser-guessed mimetype: junk
// uploads then fail with actionable guidance instead of a stored useless
// file, and valid exports pass regardless of what file.type reports.
const buffer = Buffer.from(await file.arrayBuffer());
const parsed = parseArmaPreset(buffer.toString("utf-8"));
if (!parsed.ok) {
return { success: false, error: describeArmaPresetFailure(parsed.reason) };
// Only HTML mod lists exported from the Arma 3 launcher are supported. Some
// browsers report an empty file.type, so also accept by extension.
const isHtml = file.type === "text/html" || /\.html?$/i.test(file.name);
if (!isHtml) {
return {
success: false,
error: "Mod list must be an HTML file exported from the Arma 3 launcher.",
};
}
const buffer = Buffer.from(await file.arrayBuffer());
const created = await payload.create({
collection: "mod-lists",
overrideAccess: true,
@ -230,7 +230,7 @@ export async function uploadSideOpModlist(
},
file: {
data: buffer,
mimetype: "text/html",
mimetype: file.type || "text/html",
name: file.name,
size: file.size,
},
@ -242,7 +242,8 @@ export async function uploadSideOpModlist(
if (/invalid: file/i.test(message)) {
return {
success: false,
error: describeArmaPresetFailure("notPreset"),
error:
"That file type is not accepted. Please upload the .html file exported from the Arma 3 launcher, or a .txt mod list.",
};
}
return message === "Unauthorized"

View file

@ -36,14 +36,6 @@ export const ModLists: CollectionConfig = {
// 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"],
mimeTypes: ["text/html", "text/plain"],
},
};

View file

@ -30,7 +30,6 @@ import {
type FridaySideOpInput,
} from "@/app/(frontend)/intelligence/missions/actions";
import { uploadUgcImage } from "./create";
import { describeArmaPresetFailure, parseArmaPreset } from "@/lib/modlistPreset";
import {
SideOpNarrativeFields,
type SideOpNarrative,
@ -244,19 +243,9 @@ export function CreateSideOpDialog({
async function handleModlistUpload(file: File) {
setModlistUploading(true);
try {
// Pre-validate with the same parser the server action uses so users get
// instant feedback; the server still re-checks the bytes it receives.
const parsed = parseArmaPreset(await file.text());
if (!parsed.ok) {
toast.error(describeArmaPresetFailure(parsed.reason));
return;
}
const formData = new FormData();
formData.append("file", file);
formData.append(
"name",
modlistName.trim() || parsed.presetName || file.name.replace(/\.html?$/i, ""),
);
formData.append("name", modlistName.trim() || file.name.replace(/\.html?$/i, ""));
const result = await uploadSideOpModlist(formData);
if (!result.success || !result.data) {
toast.error(result.error ?? "Failed to upload the mod list.");
@ -552,7 +541,7 @@ export function CreateSideOpDialog({
/>
<Input
type="file"
accept=".html,.htm,text/html"
accept=".html,.htm,.txt,text/html,text/plain"
disabled={modlistUploading}
onChange={(e) => {
const file = e.target.files?.[0];
@ -561,8 +550,8 @@ export function CreateSideOpDialog({
}}
/>
<p className="text-xs text-muted-foreground">
Upload the .html preset exported from the Arma 3 launcher (MODS tab &rarr; Export
preset to HTML), or pick an existing one.
Upload the mod list file exported from the Arma 3 launcher (.html) or a .txt mod list,
or pick an existing one.
</p>
</div>

View file

@ -1,64 +0,0 @@
/**
* Validation for Arma 3 Launcher preset exports (the only accepted mod list
* format). Pure module (client-safe): the server action treats it as
* authoritative, and CreateSideOpDialog uses it for instant client-side
* feedback before the upload starts.
*
* A launcher export is an HTML document carrying `<meta name="arma:Type"
* content="preset">`, an optional `<meta name="arma:PresetName" ...>`, and one
* `<tr data-type="ModContainer">` row per mod. We validate those structural
* markers rather than the generator/footer strings, which third-party launcher
* clones rewrite.
*/
export type ArmaPresetFailureReason = "notPreset" | "empty";
export type ArmaPresetSummary =
| { ok: true; presetName: string | null; modCount: number }
| { ok: false; reason: ArmaPresetFailureReason };
const META_TAG_RE = /<meta\b[^>]*>/gi;
const NAME_ATTR_RE = /\bname\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i;
const CONTENT_ATTR_RE = /\bcontent\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i;
const MOD_ROW_RE = /\bdata-type\s*=\s*(?:"ModContainer"|'ModContainer'|ModContainer)/gi;
function attr(tag: string, attribute: RegExp): string | null {
const match = tag.match(attribute);
if (!match) return null;
return (match[1] ?? match[2] ?? match[3] ?? "").trim();
}
/**
* Inspect a candidate file's text. Returns the preset name and mod count when
* the content matches the launcher export format, otherwise a failure reason:
* - `notPreset`: not an HTML Arma 3 preset export at all (wrong file type).
* - `empty`: a valid preset containing zero mod entries.
*/
export function parseArmaPreset(source: string): ArmaPresetSummary {
const html = source.replace(/^\uFEFF/, "");
if (!/<html\b/i.test(html)) return { ok: false, reason: "notPreset" };
let armaType: string | null = null;
let presetName: string | null = null;
for (const tag of html.match(META_TAG_RE) ?? []) {
const name = attr(tag, NAME_ATTR_RE)?.toLowerCase();
if (name === "arma:type") armaType = attr(tag, CONTENT_ATTR_RE)?.toLowerCase() ?? null;
else if (name === "arma:presetname") presetName = attr(tag, CONTENT_ATTR_RE) || null;
}
if (armaType !== "preset") return { ok: false, reason: "notPreset" };
const modCount = (html.match(MOD_ROW_RE) ?? []).length;
if (modCount === 0) return { ok: false, reason: "empty" };
return { ok: true, presetName, modCount };
}
/** Shared user-facing copy for each failure reason (client + server). */
export function describeArmaPresetFailure(reason: ArmaPresetFailureReason): string {
switch (reason) {
case "notPreset":
return "That file is not an Arma 3 Launcher mod list export. In the launcher, open the MODS tab, use the menu and choose 'Export preset to HTML', then upload that .html file.";
case "empty":
return "That Arma 3 Launcher preset does not contain any mods. Select your mods in the launcher, export again, and re-upload.";
}
}

View file

@ -1,93 +0,0 @@
import { describe, expect, it } from "vitest";
import { describeArmaPresetFailure, parseArmaPreset } from "@/lib/modlistPreset";
/** Trimmed fixture mirroring the structure of a real Arma 3 Launcher export. */
function presetHtml(modRows: string, presetName = "The World We Knew"): string {
return `<?xml version="1.0" encoding="utf-8"?>
<html>
<head>
<meta name="arma:Type" content="preset" />
<meta name="arma:PresetName" content="${presetName}" />
<meta name="generator" content="Arma 3 Launcher - https://www.arma3.com" />
<title>Arma 3</title>
</head>
<body>
<h1>Arma 3 - Preset <strong>${presetName}</strong></h1>
<div class="mod-list">
<table>
${modRows}
</table>
</div>
<div class="dlc-list">
<table></table>
</div>
<div class="footer">
<span>Created by Arma 3 Launcher by Bohemia Interactive.</span>
</div>
</body>
</html>`;
}
const MOD_ROW = ` <tr data-type="ModContainer">
<td data-type="DisplayName">ACE3</td>
<td><span class="from-steam">Steam</span></td>
<td><a href="https://steamcommunity.com/sharedfiles/filedetails/?id=463939057" data-type="Link">link</a></td>
</tr>`;
describe("parseArmaPreset", () => {
it("accepts a launcher preset export and reports name + mod count", () => {
const result = parseArmaPreset(presetHtml(`${MOD_ROW}\n${MOD_ROW}`));
expect(result).toEqual({ ok: true, presetName: "The World We Knew", modCount: 2 });
});
it("tolerates a UTF-8 BOM", () => {
const result = parseArmaPreset(`\uFEFF${presetHtml(MOD_ROW)}`);
expect(result.ok).toBe(true);
});
it("tolerates single-quoted and uppercase attributes", () => {
const html = presetHtml(MOD_ROW)
.replace('<meta name="arma:Type" content="preset" />', "<META NAME='arma:Type' CONTENT='preset'>")
.replace('data-type="ModContainer"', "DATA-TYPE='ModContainer'");
const result = parseArmaPreset(html);
expect(result.ok).toBe(true);
});
it("reports a null preset name when the meta tag is absent", () => {
const html = presetHtml(MOD_ROW).replace(
/<meta name="arma:PresetName"[^>]*>/,
"",
);
expect(parseArmaPreset(html)).toEqual({ ok: true, presetName: null, modCount: 1 });
});
it("rejects an unrelated HTML page", () => {
const result = parseArmaPreset(
"<html><body><h1>My mod list</h1><ul><li>ACE3</li></ul></body></html>",
);
expect(result).toEqual({ ok: false, reason: "notPreset" });
});
it("rejects a plain-text mod list", () => {
expect(parseArmaPreset("CUP Units\nCUP Vehicles\nACE3\n")).toEqual({
ok: false,
reason: "notPreset",
});
});
it("rejects launcher exports of other arma:Type values", () => {
const html = presetHtml(MOD_ROW).replace('content="preset"', 'content="save"');
expect(parseArmaPreset(html)).toEqual({ ok: false, reason: "notPreset" });
});
it("rejects a valid preset with zero mods", () => {
expect(parseArmaPreset(presetHtml(""))).toEqual({ ok: false, reason: "empty" });
});
});
describe("describeArmaPresetFailure", () => {
it("gives actionable copy for every reason", () => {
expect(describeArmaPresetFailure("notPreset")).toMatch(/Export preset to HTML/i);
expect(describeArmaPresetFailure("empty")).toMatch(/does not contain any mods/i);
});
});