<?php
// Sert les illustrations (et leur liste) uniquement si on est connectée.
require_once __DIR__ . '/auth.php';

if (!douceur_connectee()) {
    http_response_code(403);
    exit;
}

$f = $_GET['f'] ?? '';
if (!is_string($f) || !preg_match('/^[a-z0-9][a-z0-9_-]*\.(svg|js)$/', $f)) {
    http_response_code(404);
    exit;
}
$chemin = __DIR__ . '/illustrations/' . $f;
if (!is_file($chemin)) {
    http_response_code(404);
    exit;
}

$types = ['svg' => 'image/svg+xml', 'js' => 'text/javascript; charset=utf-8'];
header('Content-Type: ' . $types[pathinfo($f, PATHINFO_EXTENSION)]);
header('Cache-Control: private, max-age=300');
header('X-Content-Type-Options: nosniff');
readfile($chemin);
