/** Appels à la fonction serveur « admin », par le relais nginx du VPS (qui ajoute le secret). */ export class ApiError extends Error { constructor( public status: number, message: string, ) { super(message) } } const MESSAGES: Record = { session: 'Session expirée : reconnecte-toi.', mfa: 'Code de double authentification requis : reconnecte-toi.', interdit: "Ce compte n'est pas administrateur.", 'trop de requêtes': 'Trop de requêtes, patiente une minute.', } export async function call(token: string, action: string, params: Record = {}): Promise { let res: Response try { res = await fetch('/api/admin', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }, body: JSON.stringify({ action, ...params }), credentials: 'omit', cache: 'no-store', }) } catch { throw new ApiError(0, 'Serveur injoignable (VPN Tailscale activé ?).') } if (res.status === 404) throw new ApiError(404, 'La console n\'est pas reliée au serveur (secret du VPS absent ou différent).') const body = (await res.json().catch(() => ({}))) as { error?: string } if (!res.ok) throw new ApiError(res.status, MESSAGES[body.error ?? ''] ?? body.error ?? `Erreur ${res.status}`) return body as T } export interface Card { id: string username: string display_name: string avatar_url?: string | null suspended: boolean } export interface Overview { members: number members_week: number active_week: number suspended: number private: number items: number reviews: number comments: number follows: number shared_lists: number latest: (Card & { created_at: string })[] } export interface Member extends Card { email: string created_at: string last_sign_in_at?: string | null items: number mfa: boolean is_admin: boolean } export interface Review { user: Card item_id: string title: string rating?: number | null spoiler: boolean notes: string updated_at: string comments: number } export interface Comment { id: number body: string created_at: string user: Card author: Card title?: string | null } export interface JournalEntry { id: number at: string action: string target?: string | null details: Record admin?: string | null }