feat(web): serve the dashboard and its interface

The front-end is plain JavaScript served as is: no build step to run before
the bot starts, and no second toolchain to keep alive. A simple/advanced
switch hides the technical panels without ever standing in for a permission.

`npm run setup` starts the wizard alone, because the bot refuses to boot
without a token and the `.env` has to be writable from somewhere. When the
webhook and the dashboard share a port, a single HTTP server is started.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
nocodeandClaude Opus 5 committed 2026-09-23 20:09:14 +02:00
1 parent bf92badb05
commit 06a9be0cba
23 files changed
+5850 -2

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
import { api } from '../core/api.js';
import { h, mount } from '../core/dom.js';
import { button, field, input, notice, toast } from '../core/ui.js';
/** Sign-in page: Discord OAuth2, or the bootstrap token when nothing is configured yet. */
const ERRORS = {
'oauth-not-configured':
'La connexion Discord n’est pas configurée. Renseigne `DISCORD_CLIENT_SECRET` et `WEB_PUBLIC_URL`, puis redémarre le bot.',
'state-mismatch': 'La session de connexion a expiré. Réessaie.',
'exchange-failed':
'Discord a refusé l’échange du code. Vérifie l’URL de redirection déclarée dans le portail.',
'not-a-member': 'Ton compte Discord n’est pas membre du serveur FWS.',
'insufficient-level': 'Ton compte n’a pas le rôle Staff, Dev ou Owner sur le serveur.',
'missing-code': 'Discord n’a pas renvoyé de code d’autorisation.',
access_denied: 'Connexion annulée.',
};
export function render(host, { state }) {
const params = new URLSearchParams(window.location.hash.split('?')[1] ?? '');
const failure = params.get('error');
const config = state.config ?? {};
const tokenInput = input({ type: 'password', placeholder: 'Jeton d’amorçage', autocomplete: 'off' });
const submitSetupToken = async () => {
try {
await api.post('/api/auth/setup', { token: tokenInput.value.trim() });
window.location.hash = '#/setup';
window.location.reload();
} catch (error) {
toast(error.message, 'error');
}
};
mount(
host,
h(
'div',
{ class: 'centered' },
h(
'div',
{ class: 'panel' },
h('img', { src: 'favicon.svg', alt: '', width: 56, height: 56, style: { margin: '0 auto' } }),
h('h1', { text: 'FWS-Bot' }),
h('p', { class: 'muted', text: 'Administration du bot, de l’organisation et des déploiements.' }),
failure && notice(ERRORS[failure] ?? `Connexion refusée (${failure}).`, 'error'),
config.oauthConfigured
? h('a', { class: 'btn btn-primary', href: '/auth/login', text: 'Se connecter avec Discord' })
: notice(
'La connexion Discord n’est pas encore disponible. Utilise le jeton d’amorçage pour ouvrir l’assistant de configuration.',
'warning',
),
config.setupAvailable &&
h(
'div',
{ class: 'stack' },
h('hr', { style: { border: 'none', borderTop: '1px solid var(--border)', width: '100%' } }),
field('Jeton d’amorçage', tokenInput, {
help: 'Affiché par `npm run setup`, ou défini dans `WEB_SETUP_TOKEN`. Il ne donne accès qu’à la configuration.',
}),
button('Ouvrir l’assistant de configuration', submitSetupToken, { tone: 'ghost' }),
),
),
),
);
tokenInput.addEventListener('keydown', (event) => {
if (event.key === 'Enter') submitSetupToken();
});
}