Files
bobinoo/admin/src/api.ts
T
Claude 5e9994091f
deploy / deploy (push) Successful in 54s
Console d'administration : sur https://admin.bobinoo.org, sans VPN
- nginx : serveur admin.bobinoo.org (derrière le proxy HTTPS en façade, comme le site) au lieu de la boucle
  locale + Tailscale. Limite globale de 60 appels/min (rafale 30) sur /api/admin, HSTS, robots.txt fermé.
- Relais vers Supabase en HTTP/1.1 : en HTTP/1.0 (défaut de nginx), Supabase répondait 426.
- Guide (docs/admin.md) : DNS admin → IP du VPS, proxy en façade + certificat, secret, alertes e-mail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
2026-11-30 20:38:17 +00:00

91 lines
2.3 KiB
TypeScript

/** 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<string, string> = {
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<T>(token: string, action: string, params: Record<string, unknown> = {}): Promise<T> {
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. Vérifie ta connexion.')
}
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<string, unknown>
admin?: string | null
}