/** * Public status page, rendered on the server (M19). * * Same reasoning as the wiki: a page that needs JavaScript to say whether the * service is up is a page that reads as blank to a monitor, a crawler, or * anyone on a connection bad enough to be checking the status in the first * place. There is no script tag here, and the refresh is a meta tag. */ const escape = (text) => String(text ?? '') .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"'); const REFRESH_SECONDS = 60; const STATE_LABELS = { ok: 'Opérationnel', down: 'Hors ligne', busy: 'En cours', unknown: 'Inconnu', }; const DEPLOY_LABELS = { success: 'Déployé', failed: 'Échec', running: 'En cours', pending: 'En attente', }; function duration(ms) { const seconds = Math.floor(Number(ms) / 1000); if (!Number.isFinite(seconds) || seconds < 0) return '—'; const days = Math.floor(seconds / 86_400); const hours = Math.floor((seconds % 86_400) / 3600); const minutes = Math.floor((seconds % 3600) / 60); if (days > 0) return `${days} j ${hours} h`; if (hours > 0) return `${hours} h ${minutes} min`; if (minutes > 0) return `${minutes} min`; return `${seconds} s`; } function moment(value) { if (!value) return '—'; const date = new Date(String(value).includes('T') ? value : `${value}Z`); if (Number.isNaN(date.getTime())) return '—'; return date.toLocaleString('fr-FR', { dateStyle: 'medium', timeStyle: 'short' }); } const pill = (tone, label) => `${escape(label)}`; const tile = (label, value, hint) => `
${escape(label)} ${escape(value)} ${hint ? `${escape(hint)}` : ''}
`; function environmentRows(environments) { if (environments.length === 0) { return '

Aucun déploiement enregistré pour l’instant.

'; } return ` ${environments .map( (entry) => ``, ) .join('\n ')}
EnvironnementDépôtVersionÉtatLe
${escape(entry.environment)} ${entry.repository ? escape(entry.repository) : 'privé'} ${entry.releaseTag ? `${escape(entry.releaseTag)}` : '—'} ${pill(entry.tone, DEPLOY_LABELS[entry.status] ?? entry.status)} ${escape(moment(entry.finishedAt))}
`; } function releaseList(releases) { if (releases.length === 0) { return '

Aucune release publiée pour l’instant.

'; } return ``; } function footer(links) { const entries = [ ['/wiki', 'Documentation'], ['/terms-of-service', 'Conditions d’utilisation'], ['/privacy-policy', 'Politique de confidentialité'], links.website && [links.website, 'Site'], links.forge && [links.forge, 'Forge'], links.discordInvite && [links.discordInvite, 'Discord'], ].filter(Boolean); return ``; } /** Turns a snapshot from `status-service.js` into the finished page. */ export function renderStatus(snapshot) { const { bot } = snapshot; const failing = snapshot.environments.filter((entry) => entry.status === 'failed'); // The banner states the worst true thing: a green headline above a failed // deployment is how a status page loses the only thing it has. const headline = !bot.online ? { tone: 'down', title: 'Le bot est hors ligne', detail: 'Le service ne répond pas à Discord.' } : failing.length > 0 ? { tone: 'busy', title: 'Service opérationnel, déploiement en échec', detail: `Le bot répond, mais ${failing.length} environnement(s) n’ont pas reçu leur dernière mise à jour.`, } : { tone: 'ok', title: 'Tous les services fonctionnent', detail: 'Le bot répond à Discord.' }; return ` État des services · FWS
FWSÉtat des services
Actualisé automatiquement toutes les ${REFRESH_SECONDS} secondes

${escape(headline.title)}

${escape(headline.detail)}

Bot Discord

${tile('État', STATE_LABELS[bot.state] ?? bot.state)} ${tile('En ligne depuis', duration(bot.uptimeMs), `Démarré le ${moment(bot.startedAt)}`)} ${tile('Latence Discord', bot.pingMs === null ? '—' : `${bot.pingMs} ms`)} ${tile('Version', bot.version)}

Déploiements

${environmentRows(snapshot.environments)}

Dernières releases

${releaseList(snapshot.releases)}

Relevé du . Version lisible par une machine : /api/status.

${footer(snapshot.links)}
`; }