Website: /mods/submit, the registry's submission form
Sign in with GitHub through the registry's service (no scope), then send the file and its page; the service checks the file, stages it and opens the pull request, and the page links to it or says what to fix. A file named <id>-<version>.<ext> fills in its kind, id and version. Shader packs are listed and disabled until Horizon's own format exists. Caddy sends /api/mods/* to REGISTRY_UPSTREAM (unset: the form says it isn't open), and "Submit yours" now leads here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+6
-1
@@ -35,7 +35,12 @@
|
||||
rewrite /benchmarks /benchmarks.html
|
||||
@doc path_regexp doc ^/docs/([a-z-]+)$
|
||||
rewrite @doc /docs/{re.doc.1}.html
|
||||
# The registry: /mods, and /mods/<id> baked at build time, else the list page, whose script shows a project
|
||||
# The registry's submission service (crates/horizon-mod-registry), over Railway's private network. Unset, the
|
||||
# form says it isn't open.
|
||||
handle /api/mods/* {
|
||||
reverse_proxy {$REGISTRY_UPSTREAM:127.0.0.1:9}
|
||||
}
|
||||
# The registry: /mods, /mods/submit and /mods/<id> baked at build time, else the list page, whose script shows a project
|
||||
# published since.
|
||||
rewrite /mods /mods.html
|
||||
@mod {
|
||||
|
||||
+4
-2
@@ -29,7 +29,7 @@ src/style.css every style, on top of the tokens
|
||||
src/main.js the home page: download buttons, recent releases, links, contributors, nav, tabs, lightbox, motion
|
||||
src/chrome.js the light/dark switch, the phone menu and GitHub fetching, shared by the pages
|
||||
src/releases-page.js the Releases page: the channel filter and the refresh from GitHub
|
||||
src/mods.js the registry's markup (list, project page), shared by build and page; mods-page.js: the filter, the search, the refresh
|
||||
src/mods.js the registry's markup (list, project page, submit form), shared by build and page; mods-page.js: the filter, the search, the refresh; mods-submit.js: the form's sign-in and sending
|
||||
src/benchmarks-page.js the Benchmarks page: players' results from the telemetry server, the picker
|
||||
src/bench.js the Benchmarks tables, shared by build and page
|
||||
src/hardware.js the spec table estimates use (GPU TFLOPS and bandwidth, CPU single-thread score)
|
||||
@@ -110,7 +110,9 @@ a Caddy stage serves `dist/` on `$PORT` with compression, cache headers, a stric
|
||||
Content-Security-Policy and the 404 page. Its watch patterns also redeploy when the README
|
||||
or `launcher/links.json` change on main. No variables are needed; an optional
|
||||
`GITHUB_TOKEN` (read-only, public repos) lets the build bake the releases even when
|
||||
GitHub's anonymous rate limit is hit.
|
||||
GitHub's anonymous rate limit is hit. `REGISTRY_UPSTREAM`
|
||||
(`horizon-mod-registry.railway.internal:8080`) sends `/api/mods/*` to the registry's submission
|
||||
service (`crates/horizon-mod-registry`); unset, `/mods/submit` says the form isn't open.
|
||||
|
||||
## Rules the site keeps
|
||||
|
||||
|
||||
+5
-4
@@ -16,7 +16,7 @@ import { machinesHtml, playersHtml } from "./src/bench.js";
|
||||
import { CPUS, GPUS, singleThread } from "./src/hardware.js";
|
||||
import { isGame, isLauncher, launcherVersion, newestFirst } from "./src/versions.js";
|
||||
import { contributorsFrom, contributorsHtml } from "./src/contributors.js";
|
||||
import { INDEX_URL, KINDS, SUBMIT, listHtml, projectHtml, readIndex } from "./src/mods.js";
|
||||
import { INDEX_URL, KINDS, SUBMIT, listHtml, projectHtml, readIndex, submitHtml } from "./src/mods.js";
|
||||
|
||||
const site = dirname(fileURLToPath(import.meta.url));
|
||||
const dist = join(site, "dist");
|
||||
@@ -186,7 +186,7 @@ await writeFile(join(dist, "favicon.ico"), Buffer.concat([ico, png32]));
|
||||
const names = {};
|
||||
const rewrite = (code) => code.replace(/"\.\/(\w+\.js)"/g, (all, file) => (names[file] ? `"./${names[file]}"` : all));
|
||||
// Dependencies before what imports them.
|
||||
const modules = ["markdown.js", "versions.js", "chrome.js", "hardware.js", "estimate.js", "releases.js", "contributors.js", "bench.js", "main.js", "releases-page.js", "benchmarks-page.js", "mods.js", "mods-page.js"];
|
||||
const modules = ["markdown.js", "versions.js", "chrome.js", "hardware.js", "estimate.js", "releases.js", "contributors.js", "bench.js", "main.js", "releases-page.js", "benchmarks-page.js", "mods.js", "mods-page.js", "mods-submit.js"];
|
||||
for (const file of modules) {
|
||||
const code = rewrite(await readFile(join(site, "src", file), "utf8"));
|
||||
names[file] = `${file.replace(".js", "")}.${fingerprint(code)}.js`;
|
||||
@@ -401,7 +401,8 @@ ${listHtml(modProjects)}
|
||||
</div>`;
|
||||
const modPages = [
|
||||
{ file: "mods.html", path: "/mods", title: "Mods", description: "Mods, modpacks and resource packs made for Horizon, reviewed, each with what it may do and how to install it.", main: modsList },
|
||||
...modProjects.map((p) => ({ file: `mods/${p.id}.html`, path: `/mods/${p.id}`, title: p.name, description: p.summary || p.name, main: projectHtml(p) })),
|
||||
{ file: "mods/submit.html", path: "/mods/submit", title: "Submit to the registry", description: "Submit a mod, a modpack or a resource pack made for Horizon: it is checked, reviewed, then listed here and in the launcher.", main: submitHtml(), js: "mods-submit.js" },
|
||||
...modProjects.filter((p) => p.id !== "submit").map((p) => ({ file: `mods/${p.id}.html`, path: `/mods/${p.id}`, title: p.name, description: p.summary || p.name, main: projectHtml(p) })),
|
||||
];
|
||||
await mkdir(join(dist, "mods"), { recursive: true });
|
||||
const modsData = JSON.stringify(modIndex && modProjects.length ? { schema: modIndex.schema, projects: modProjects } : null).replace(/</g, "\\u003c");
|
||||
@@ -412,7 +413,7 @@ for (const page of modPages) {
|
||||
MODS_TITLE: escape(page.title),
|
||||
MODS_DESCRIPTION: escape(page.description),
|
||||
MODS_PATH: page.path,
|
||||
MODS_JS: `/assets/${names["mods-page.js"]}`,
|
||||
MODS_JS: `/assets/${names[page.js || "mods-page.js"]}`,
|
||||
MODS_MAIN: page.main,
|
||||
MODS_DATA: modsData,
|
||||
MODS_BAKED_AT: escape(modIndex?.generated || ""),
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
// /mods/submit: signs in with GitHub through the registry's service, then sends the page and the file. The service
|
||||
// checks the file and answers with the pull request it opened, or with what to fix.
|
||||
import { API, entryFrom } from "./mods.js";
|
||||
import { setUpMenu, setUpTheme } from "./chrome.js";
|
||||
import { escape } from "./markdown.js";
|
||||
|
||||
const auth = document.getElementById("submit-auth");
|
||||
const form = document.getElementById("submit-form");
|
||||
const result = document.getElementById("submit-result");
|
||||
let csrf = "";
|
||||
// The form's own controls by name (form.id and form.name are the form's attributes).
|
||||
const control = (name) => form.elements.namedItem(name);
|
||||
|
||||
function signedOut(message) {
|
||||
auth.innerHTML = `<p class="meta">${message}</p><p class="mod-actions"><a class="button primary" href="${API}/auth/login">Sign in with GitHub</a></p><p class="meta">It only reads your public profile: your GitHub name goes on the pull request and in the project's owners.</p>`;
|
||||
form.hidden = true;
|
||||
}
|
||||
|
||||
async function start() {
|
||||
let me;
|
||||
try {
|
||||
const r = await fetch(`${API}/me`, { credentials: "same-origin" });
|
||||
if (r.status === 401) return signedOut("Sign in to submit: reviewers and updates go through your GitHub account.");
|
||||
if (!r.ok) throw new Error(String(r.status));
|
||||
me = await r.json();
|
||||
} catch {
|
||||
auth.innerHTML = `<p class="meta">The form isn't open right now. You can <a href="https://github.com/ludovic111/horizon-mods">open a pull request by hand</a>.</p>`;
|
||||
return;
|
||||
}
|
||||
csrf = me.csrf;
|
||||
auth.innerHTML = `<p class="meta">Signed in as <strong>${escape(me.login)}</strong>. <button class="button ghost small" type="button" id="sign-out">Sign out</button></p>`;
|
||||
document.getElementById("sign-out").addEventListener("click", async () => {
|
||||
await fetch(`${API}/auth/logout`, { method: "POST", credentials: "same-origin" });
|
||||
signedOut("Signed out.");
|
||||
});
|
||||
form.hidden = false;
|
||||
}
|
||||
|
||||
// A file named <id>-<version>.<extension> fills in the two fields and the kind.
|
||||
form.querySelector("#f-file").addEventListener("change", (e) => {
|
||||
const name = e.target.files[0]?.name || "";
|
||||
const m = name.match(/^([a-z0-9_]{1,64})-([A-Za-z0-9][A-Za-z0-9._-]*)\.(hmod|hpack|zip)$/);
|
||||
const kind = { hmod: "mod", hpack: "modpack", zip: "resourcepack" }[name.split(".").pop()];
|
||||
if (kind) control("kind").value = kind;
|
||||
if (m) {
|
||||
if (!control("id").value) control("id").value = m[1];
|
||||
if (!control("version").value) control("version").value = m[2];
|
||||
}
|
||||
});
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const send = form.querySelector("#f-send");
|
||||
const values = Object.fromEntries(["id", "kind", "name", "summary", "description", "authors", "license", "source", "icon", "key", "version", "game", "changelog"].map((k) => [k, control(k).value]));
|
||||
const sig = form.querySelector("#f-signature").files[0];
|
||||
values.signature = sig ? await sig.text() : "";
|
||||
const body = new FormData();
|
||||
body.append("entry", JSON.stringify(entryFrom(values)));
|
||||
body.append("file", form.querySelector("#f-file").files[0]);
|
||||
send.disabled = true;
|
||||
result.innerHTML = `<p class="meta">Checking the file and opening the pull request…</p>`;
|
||||
try {
|
||||
const r = await fetch(`${API}/submit`, { method: "POST", body, credentials: "same-origin", headers: { "X-CSRF-Token": csrf } });
|
||||
const json = await r.json().catch(() => ({}));
|
||||
if (r.ok && /^https:\/\/github\.com\//.test(json.pull_request || "")) {
|
||||
result.innerHTML = `<p class="lede">Submitted. Follow the review in <a href="${escape(json.pull_request)}">its pull request</a>: the checks' report is there, and reviewers answer there.</p>`;
|
||||
form.reset();
|
||||
} else {
|
||||
result.innerHTML = `<p class="mod-error">${escape(json.error || `The service answered ${r.status}.`)}</p>`;
|
||||
}
|
||||
} catch {
|
||||
result.innerHTML = `<p class="mod-error">The service didn't answer. Try again in a minute.</p>`;
|
||||
} finally {
|
||||
send.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
setUpTheme();
|
||||
setUpMenu();
|
||||
start();
|
||||
+66
-1
@@ -5,7 +5,9 @@ import { markdown, escape } from "./markdown.js";
|
||||
|
||||
export const INDEX_URL = "https://ludovic111.github.io/horizon-mods/index.json";
|
||||
const REGISTRY = "https://github.com/ludovic111/horizon-mods";
|
||||
export const SUBMIT = `${REGISTRY}#submit`;
|
||||
export const SUBMIT = "/mods/submit";
|
||||
// The submission form's service (crates/horizon-mod-registry), behind the site's own address.
|
||||
export const API = "/api/mods";
|
||||
export const SCHEMA = 1;
|
||||
|
||||
// The kinds the site shows, in the filter's order. Kinds a newer index adds are left out until the site knows them.
|
||||
@@ -108,3 +110,66 @@ export function projectHtml(p) {
|
||||
<a class="link-arrow" href="${REGISTRY}/issues/new?template=report.yml&title=${escape(p.id)}">Report it<span aria-hidden="true">→</span></a></p>
|
||||
</article>`;
|
||||
}
|
||||
|
||||
// /mods/submit: the form. Its script (mods-submit.js) signs in, then sends the page and the file to the service, which
|
||||
// checks the file and opens the pull request the reviewers read.
|
||||
const field = (name, label, input, hint = "") =>
|
||||
`<label class="mod-field" for="f-${name}"><span class="mod-label">${label}</span>${input}${hint ? `<span class="meta">${hint}</span>` : ""}</label>`;
|
||||
const text = (name, attrs = "") => `<input class="mod-search" id="f-${name}" name="${name}" ${attrs}>`;
|
||||
|
||||
export function submitHtml() {
|
||||
return `<p class="kicker"><span>Mods</span>Submit</p>
|
||||
<h1 class="display page-title">Submit to the registry</h1>
|
||||
<p class="lede">A mod, a modpack of registry mods, or a resource pack made for Horizon. The form checks the file and opens a pull request; a reviewer reads it, its source and the checks' report, and merging publishes it to this site and the launcher.</p>
|
||||
<div class="mod-auth" id="submit-auth" aria-live="polite">
|
||||
<p class="meta no-script">The form needs JavaScript. You can also <a href="${REGISTRY}">open a pull request by hand</a>.</p>
|
||||
</div>
|
||||
<form class="mod-form" id="submit-form" hidden>
|
||||
<fieldset><legend class="heading">The file</legend>
|
||||
${field("kind", "Kind", `<select class="mod-search" id="f-kind" name="kind">${KINDS.map(([k, label]) => `<option value="${k}"${k === "shader" ? " disabled" : ""}>${label.replace(/s$/, "")}${k === "shader" ? " (opens with Horizon's own shader format)" : ""}</option>`).join("")}</select>`)}
|
||||
${field("file", "File", `<input id="f-file" name="file" type="file" accept=".hmod,.hpack,.zip" required>`, "A .hmod, a .hpack or a resource pack .zip, at most 64 MB. Run <code>cargo horizon-mod check</code> on it first.")}
|
||||
${field("id", "Id", text("id", `required pattern="[a-z0-9_]{1,64}" placeholder="my_mod" autocomplete="off"`), "Its manifest's id: a-z, 0-9 and _. A resource pack's is yours to pick.")}
|
||||
${field("version", "Version", text("version", `required pattern="[A-Za-z0-9][A-Za-z0-9._\\-]{0,63}" placeholder="1.0.0"`))}
|
||||
${field("game", "For Minecraft", text("game", `required value="26.3"`))}
|
||||
${field("changelog", "What changed", `<textarea class="mod-search" id="f-changelog" name="changelog" rows="3"></textarea>`, "Markdown.")}
|
||||
</fieldset>
|
||||
<fieldset><legend class="heading">Its page</legend>
|
||||
${field("name", "Name", text("name", `required maxlength="64"`))}
|
||||
${field("summary", "Summary", text("summary", `required maxlength="160"`), "One line for the list.")}
|
||||
${field("description", "Description", `<textarea class="mod-search" id="f-description" name="description" rows="6"></textarea>`, "Markdown.")}
|
||||
${field("authors", "Authors", text("authors", `placeholder="Alice, Bob"`), "Separated by commas.")}
|
||||
${field("license", "Licence", text("license", `required placeholder="MIT"`), "An SPDX expression.")}
|
||||
${field("source", "Source code", text("source", `required type="url" pattern="https://.*" placeholder="https://github.com/you/your-mod"`), "Reviewers read it: the file must be built from it.")}
|
||||
${field("icon", "Icon", text("icon", `type="url" pattern="https://.*" placeholder="https://…/icon.png"`), "Optional, a square PNG.")}
|
||||
</fieldset>
|
||||
<fieldset><legend class="heading">Signature</legend>
|
||||
<p class="meta">Optional, and recommended: with your <a href="https://jedisct1.github.io/minisign/">minisign</a> key on the project, every later version must be signed with it, so nobody else can publish an update in your name.</p>
|
||||
${field("key", "Public key", text("key", `placeholder="RW…" autocomplete="off"`), "A new project's. Changing a published project's key is a pull request by hand.")}
|
||||
${field("signature", "Signature", `<input id="f-signature" name="signature" type="file" accept=".minisig">`, "The file's .minisig.")}
|
||||
</fieldset>
|
||||
<label class="mod-check"><input type="checkbox" id="f-mine" required> I made it, or I may publish it under this licence, and its source is at the address above.</label>
|
||||
<p class="mod-actions"><button class="button primary" type="submit" id="f-send">Submit for review</button></p>
|
||||
<div class="mod-result" id="submit-result" role="status" aria-live="polite"></div>
|
||||
</form>`;
|
||||
}
|
||||
|
||||
// The service's "entry" from the form's values (strings), as it reads it.
|
||||
export function entryFrom(v) {
|
||||
const optional = (x) => (x && x.trim() ? x.trim() : undefined);
|
||||
return {
|
||||
id: v.id.trim(),
|
||||
kind: v.kind,
|
||||
name: v.name.trim(),
|
||||
summary: v.summary.trim(),
|
||||
description: v.description || "",
|
||||
authors: (v.authors || "").split(",").map((a) => a.trim()).filter(Boolean),
|
||||
license: v.license.trim(),
|
||||
source: v.source.trim(),
|
||||
icon: optional(v.icon),
|
||||
key: optional(v.key),
|
||||
signature: optional(v.signature),
|
||||
version: v.version.trim(),
|
||||
game: v.game.trim(),
|
||||
changelog: v.changelog || "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { CAPABILITIES, listHtml, matches, projectHtml, readIndex } from "./mods.js";
|
||||
import { CAPABILITIES, entryFrom, listHtml, matches, projectHtml, readIndex, submitHtml } from "./mods.js";
|
||||
|
||||
const project = (over = {}) => ({
|
||||
id: "coords_hud", kind: "mod", name: "Coordinates HUD", summary: "Where you are.", authors: ["Horizon"],
|
||||
@@ -40,3 +40,16 @@ test("a mod's page says what it may do, as the game does", () => {
|
||||
assert.ok(projectHtml(project({ key: "RWT" })).includes("Signed"));
|
||||
assert.ok(html.includes("horizon-launcher mods install --source horizon coords_hud"));
|
||||
});
|
||||
|
||||
test("the submit form sends what the service reads", () => {
|
||||
const html = submitHtml();
|
||||
for (const name of ["kind", "file", "id", "version", "game", "name", "summary", "license", "source", "key", "signature"]) {
|
||||
assert.ok(html.includes(`id="f-${name}"`), name);
|
||||
}
|
||||
assert.match(html, /<option value="shader" disabled>/);
|
||||
const entry = entryFrom({ id: " my_mod ", kind: "mod", name: "My mod", summary: "s", description: "", authors: "Alice, , Bob", license: "MIT", source: "https://x.test", icon: " ", key: "", signature: "", version: "1.0.0", game: "26.3", changelog: "" });
|
||||
assert.deepEqual(entry.authors, ["Alice", "Bob"]);
|
||||
assert.equal(entry.id, "my_mod");
|
||||
assert.equal(entry.icon, undefined);
|
||||
assert.equal(JSON.parse(JSON.stringify(entry)).key, undefined, "an empty key isn't sent");
|
||||
});
|
||||
|
||||
@@ -783,6 +783,18 @@ code { border-radius: 0; background: var(--well); box-shadow: 0 0 0 1px var(--ou
|
||||
.mod-file dt { color: var(--muted); }
|
||||
.mod-file code, .mod-steps code { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
|
||||
.mod-links { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 24px; }
|
||||
/* /mods/submit */
|
||||
.mod-form { display: grid; gap: 24px; max-width: var(--measure); margin-top: 32px; }
|
||||
.mod-form fieldset { display: grid; gap: 16px; margin: 0; padding: 0; border: 0; }
|
||||
.mod-form legend { padding: 0; margin-bottom: 8px; }
|
||||
.mod-field { display: grid; gap: 6px; }
|
||||
.mod-label { font-size: var(--text-ui); font-weight: 500; }
|
||||
.mod-form .mod-search { width: 100%; }
|
||||
.mod-form textarea.mod-search { height: auto; padding: 10px 12px; line-height: 1.5; resize: vertical; }
|
||||
.mod-check { display: flex; gap: 10px; align-items: flex-start; font-size: var(--text-ui); }
|
||||
.mod-auth { margin-top: 24px; }
|
||||
.mod-error { color: var(--danger); font-size: var(--text-ui); }
|
||||
.js .no-script { display: none; }
|
||||
@media (max-width: 640px) {
|
||||
.mod-row { grid-template-columns: 40px minmax(0, 1fr); }
|
||||
.mod-side { grid-column: 2; justify-items: start; }
|
||||
|
||||
Reference in New Issue
Block a user