Send a toolbox through an encrypted link
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 20m39s
Validate and deploy Sokko G / deploy (push) Successful in 12s

Sharing a toolbox meant exporting a JSON file and passing it around by
hand. A toolbox can now be sent from the site while staying local first:
the browser compresses and encrypts the v2 export with AES-GCM, and the
key lives only in the link fragment, so the server keeps for at most
24 hours a copy it cannot read.

- Add the /api/shares service: upload, metadata, download and revoke,
  with files in SHARES_DIR, a purge every 10 minutes, and single-use
  links (the default) deleted only once fully downloaded.
- Cap the server load: 50 MiB per share, total storage, free disk
  space, daily volume, concurrent and stalled uploads, reads per link,
  plus a wide per-connection cap kept in memory without storing IPs.
- Limit each browser to 2 shares and 100 MiB per day and 2 active
  links, and show the existing link of a toolbox already shared.
- Add the send dialog (card and game drawer) and the /receive page,
  which previews or directly imports through the existing import path.
- Move shared HTTP helpers to services/http.js for both APIs.
- Document the format, delivery, server layout and privacy wording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-11 16:26:05 +01:00
parent 957bfdc86f
commit bec9ea5b2f
43 changed files with 2349 additions and 59 deletions

View file

@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
import { createReadStream, existsSync, readFileSync, statSync } from "node:fs";
import { loadProjectEnv } from "./scripts/load-project-env.mjs";
import { createCardsApiHandler } from "./services/cards/api.js";
import { createSharesApiHandler } from "./services/shares/api.js";
import { createServer } from "node:http";
import { extname, join, relative, resolve } from "node:path";
import { fileURLToPath } from "node:url";
@ -104,11 +105,12 @@ function securityHeaders(root) {
};
}
export function createStaticServer({ root = defaultRoot, publicRoot = defaultPublicRoot, cardsApi = null } = {}) {
export function createStaticServer({ root = defaultRoot, publicRoot = defaultPublicRoot, cardsApi = null, sharesApi = null } = {}) {
const headers = securityHeaders(root);
async function handleRequest(req, res) {
for (const [name, value] of Object.entries(headers)) res.setHeader(name, value);
if (sharesApi && await sharesApi(req, res)) return;
if (cardsApi && await cardsApi(req, res)) return;
const file = resolvePath(req.url || "/", root, publicRoot);
if (!file || !existsSync(file)) {
@ -150,6 +152,7 @@ export function createStaticServer({ root = defaultRoot, publicRoot = defaultPub
});
});
if (cardsApi?.close) server.once("close", cardsApi.close);
if (sharesApi?.close) server.once("close", sharesApi.close);
return server;
}
@ -163,13 +166,24 @@ export function createCardsApi(options = {}) {
}
}
export function startServer({ cardsApiOptions = {} } = {}) {
// Une configuration d'envoi invalide désactive seulement l'envoi de toolbox.
export function createSharesApi(options = {}) {
try {
return createSharesApiHandler({ projectRoot, ...options });
} catch (error) {
console.error("Toolbox sharing is disabled because its configuration is invalid:", error);
return createSharesApiHandler({ projectRoot, ...options, enabled: false });
}
}
export function startServer({ cardsApiOptions = {}, sharesApiOptions = {} } = {}) {
loadProjectEnv();
const port = Number(process.env.PORT || 5173);
// En production, limite l'écoute au réseau privé : seul le proxy doit pouvoir joindre le serveur.
const host = process.env.HOST || undefined;
const cardsApi = createCardsApi(cardsApiOptions);
const server = createStaticServer({ cardsApi });
const sharesApi = createSharesApi(sharesApiOptions);
const server = createStaticServer({ cardsApi, sharesApi });
server.on("error", (error) => {
if (error.code === "EADDRINUSE") {