Share uploads now reserve their slot, bytes and per-IP count before the disk check, so simultaneous uploads can no longer exceed the limits. Writes to a share's metadata run one after another, and a revocation can no longer be undone by a pending read count. The TCG page ignores a state reload that started before or during a mutation, the last mutation wins, and returning to the page triggers a single reload. The card cache confirms writes only once the IndexedDB transaction completes and shows only the current player's copy. The administration panel loads on demand, which shrinks the TCG chunk from 311.6 to 191.8 kB. A new /api/health route answers 503 when the cards or shares API failed to start. The deploy script ships the commit's production dependencies with the build, waits up to 30 s for a healthy server instead of trusting systemctl is-active, and restores node_modules on rollback. Both Forgejo workflows check the route on the public site. The updated script applies once reinstalled on the server. Unused helpers, the ignored join role and duplicate button selectors are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2.3 KiB
JavaScript
55 lines
2.3 KiB
JavaScript
// Rôle : garde une copie locale remplaçable de la collection pour la consultation hors connexion.
|
|
const DB_NAME = "sokkog-nebula-cards";
|
|
const STORE = "snapshots";
|
|
// Format de l'état mis en cache : une copie d'un autre format est ignorée (l'état serveur a changé de forme).
|
|
const SNAPSHOT_FORMAT = 2;
|
|
|
|
function openCache() {
|
|
return new Promise((resolve, reject) => {
|
|
const request = indexedDB.open(DB_NAME, 1);
|
|
request.onupgradeneeded = () => request.result.createObjectStore(STORE, { keyPath: "playerId" });
|
|
request.onsuccess = () => resolve(request.result);
|
|
request.onerror = () => reject(request.error);
|
|
});
|
|
}
|
|
|
|
// La promesse ne se résout qu'une fois la transaction validée : une transaction annulée après sa requête la fait échouer.
|
|
async function transact(mode, callback) {
|
|
const database = await openCache();
|
|
try {
|
|
return await new Promise((resolve, reject) => {
|
|
const transaction = database.transaction(STORE, mode);
|
|
let result;
|
|
transaction.oncomplete = () => resolve(result);
|
|
transaction.onerror = () => reject(transaction.error);
|
|
transaction.onabort = () => reject(transaction.error);
|
|
try {
|
|
const request = callback(transaction.objectStore(STORE));
|
|
request.onsuccess = () => { result = request.result; };
|
|
} catch (error) {
|
|
transaction.abort();
|
|
reject(error);
|
|
}
|
|
});
|
|
} finally {
|
|
database.close();
|
|
}
|
|
}
|
|
|
|
export function writeCardsCache(state, catalog) {
|
|
if (!state?.player?.id) return Promise.resolve();
|
|
return transact("readwrite", (store) => store.put({ playerId: state.player.id, format: SNAPSHOT_FORMAT, savedAt: Date.now(), state, catalog }));
|
|
}
|
|
|
|
// La copie locale n'appartient qu'au joueur connecté : un autre utilisateur du navigateur ne doit pas la retrouver.
|
|
export function clearCardsCache() {
|
|
return transact("readwrite", (store) => store.clear());
|
|
}
|
|
|
|
// Avec un joueur connu, seule sa propre copie peut servir ; sans lui (serveur injoignable), la plus récente.
|
|
export async function readLatestCardsCache(playerId = null) {
|
|
const entries = await transact("readonly", (store) => store.getAll());
|
|
return entries
|
|
.filter((entry) => entry.format === SNAPSHOT_FORMAT && (playerId == null || entry.playerId === playerId))
|
|
.sort((left, right) => right.savedAt - left.savedAt)[0] || null;
|
|
}
|