Split dailyShare.js and document the shared exported functions with JSDoc

dailyShare.js held fillTemplate and formatCountdown, used across the whole TCG,
under a Daily Card name. They now live in textFormat.js at the root, and the
Daily Card helpers in daily/dailyFormat.js.

173 exported functions that other files call now explain what they return and
how they treat missing values: the server game rules, the toolbox storage chain,
the shared hooks and utilities, and the TCG display helpers. website/AGENTS.md
asks the same of new shared functions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-12-01 13:32:20 +01:00
parent 166790245f
commit aa8bb1ebaa
71 changed files with 339 additions and 57 deletions

View file

@ -4,14 +4,17 @@
const MIB = 1024 * 1024;
/** Remplace chaque `{clé}` connue ; une clé absente de `values` reste écrite telle quelle. */
export function fillTemplate(text, values = {}) {
return String(text || "").replace(/\{(\w+)\}/g, (match, key) => (key in values ? String(values[key]) : match));
}
/** Date et heure en français, format moyen (« 3 déc. 2026, 14:05 »). */
export function formatShareDate(value) {
return new Intl.DateTimeFormat("fr-FR", { dateStyle: "medium", timeStyle: "short" }).format(new Date(value));
}
/** Taille en Mio, avec une décimale au plus. */
export function formatMiB(bytes) {
return new Intl.NumberFormat("fr-FR", { maximumFractionDigits: 1 }).format(bytes / MIB);
}

View file

@ -12,6 +12,7 @@ async function failedResponse(response) {
return apiError(response.status, await response.json().catch(() => null));
}
/** Réglages publics des partages : `enabled`, taille maximale (`maxBytes`) et durée de vie (`ttlMs`). */
export async function loadSharesConfig() {
const response = await fetch("/api/shares/config", { headers: { Accept: "application/json" } });
if (!response.ok) throw await failedResponse(response);
@ -39,12 +40,14 @@ export function uploadShare(bytes, { singleUse = true, onProgress } = {}) {
});
}
/** Taille et date d'expiration d'un partage, sans le télécharger. */
export async function loadShareMeta(id) {
const response = await fetch(`/api/shares/${encodeURIComponent(id)}/meta`, { headers: { Accept: "application/json" } });
if (!response.ok) throw await failedResponse(response);
return response.json();
}
/** Télécharge le contenu chiffré d'un partage ; `onProgress` reçoit l'avancement. Un partage à usage unique n'est plus lisible ensuite. */
export async function downloadShare(id, { onProgress } = {}) {
const response = await fetch(`/api/shares/${encodeURIComponent(id)}`);
if (!response.ok) throw await failedResponse(response);

View file

@ -22,10 +22,15 @@ export class ShareLimitError extends Error {
}
}
/** Lien de réception d'un partage. La clé est après le second `#` : le navigateur ne l'envoie jamais au serveur. */
export function shareLink(id, key, origin = globalThis.location?.origin || "") {
return `${origin}/#/receive/${id}#${key}`;
}
/**
* Chiffre et envoie une toolbox, puis enregistre le partage dans le quota local. Renvoie le partage actif existant de cette
* toolbox s'il y en a un. Lève `ShareLimitError` (quota, taille) ; `onStage` suit la préparation et l'envoi.
*/
export async function createToolboxShare({ toolboxId, buildPayload, maxBytes, singleUse = true, onStage, quota = createShareQuota() }) {
const existing = quota.activeShareFor(toolboxId);
if (existing) return existing;
@ -53,6 +58,7 @@ export async function createToolboxShare({ toolboxId, buildPayload, maxBytes, si
}, bytes.length);
}
/** Supprime un partage sur le serveur (avec son jeton de suppression) et l'oublie localement. */
export async function revokeToolboxShare(shareId, quota = createShareQuota()) {
const entry = quota.activeShares().find((item) => item.id === shareId);
if (!entry) return;