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

@ -31,7 +31,7 @@ function getLibraryUrl() {
return `${window.location.origin}${window.location.pathname}#/library`;
}
export function useToolboxActions({ store, notify, creationTemplate, importContent, setConfirmModal, setCreateModal, setLinkModalGameId, setDrawerGameId, setImage }) {
export function useToolboxActions({ store, notify, creationTemplate, importContent, setConfirmModal, setCreateModal, setLinkModalGameId, setDrawerGameId, setImage, sharesConfig = null, setShareToolboxId = null }) {
const importText = {
replaceLinksTitle: importContent?.replaceLinksTitle || "Réattribuer des associations de jeu ?",
replaceLinksMessage: importContent?.replaceLinksMessage || "Des associations de jeu existantes ({count}) seront réattribuées aux copies importées. Les toolboxes déjà présentes seront conservées.",
@ -329,6 +329,15 @@ export function useToolboxActions({ store, notify, creationTemplate, importConte
return normalizedImport;
}
// Instantané cohérent d'une toolbox au format d'export v2, commun à l'export en fichier et à l'envoi.
async function buildToolboxExportPayload(id) {
const snapshot = await store.getExportSnapshot(id);
if (!snapshot) return null;
const toolbox = normalizeToolbox(snapshot.toolboxes.find((item) => item.id === id));
if (!toolbox) return null;
return { toolbox, payload: createToolboxExportPayload(toolbox, snapshot.moduleData) };
}
async function importAllToolboxesPayload(payload) {
const toolboxIdMap = new Map();
const moduleIdMap = new Map();
@ -456,13 +465,23 @@ export function useToolboxActions({ store, notify, creationTemplate, importConte
},
exportToolbox: async (id) => {
if (!store.ready) return false;
const snapshot = await store.getExportSnapshot(id);
if (!snapshot) return false;
const toolbox = normalizeToolbox(snapshot.toolboxes.find((item) => item.id === id));
if (!toolbox) return;
downloadJson(createToolboxExportPayload(toolbox, snapshot.moduleData), `${toolbox.name.toLowerCase().replace(/[^a-z0-9]+/gi, "-")}.sokkog.json`);
const built = await buildToolboxExportPayload(id);
if (!built) return false;
downloadJson(built.payload, `${built.toolbox.name.toLowerCase().replace(/[^a-z0-9]+/gi, "-")}.sokkog.json`);
notify("Export de la toolbox lancé.");
},
sharingEnabled: Boolean(sharesConfig?.enabled && setShareToolboxId),
sharesMaxBytes: sharesConfig?.maxBytes || 0,
openShareToolbox: (id) => setShareToolboxId?.(id),
buildToolboxExportPayload: (id) => (store.ready ? buildToolboxExportPayload(id) : Promise.resolve(null)),
// Une toolbox reçue suit le même contrat que l'import de fichier : validée, copiée avec de nouveaux identifiants, sans association de jeu.
importReceivedToolbox: async (payload) => {
if (!store.ready) throw new Error("Le stockage local n'est pas prêt.");
const toolbox = await importToolboxPayload(validateToolboxImportPayload(payload, "single"));
if (!toolbox) throw new Error("La toolbox reçue n'a pas pu être enregistrée dans ce navigateur.");
notify("Toolbox importée.");
return toolbox;
},
exportAllToolboxes: async () => {
if (!store.ready) return false;
const snapshot = await store.getExportSnapshot();