| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- declare(strict_types=1);
- use AuditExpress\AdminNotifier;
- use AuditExpress\Http;
- use AuditExpress\OutboxStorage;
- use AuditExpress\RateLimiter;
- use AuditExpress\Security;
- ['root' => $root, 'config' => $config] = require __DIR__ . '/_bootstrap.php';
- if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
- Http::methodNotAllowed(['POST']);
- exit;
- }
- Security::validateCsrf();
- (new RateLimiter($root, $config, RateLimiter::clientIp()))->check('excel_complete');
- $maxBody = (int) ($config['max_body_bytes'] ?? 1_048_576);
- $body = Http::readJsonBody($maxBody > 0 ? $maxBody : null);
- $email = isset($body['email']) ? trim((string) $body['email']) : null;
- $raw = is_array($body['result'] ?? null) ? $body['result'] : null;
- if ($raw === null || !isset($raw['level'], $raw['title'], $raw['summary'], $raw['score'], $raw['total'], $raw['actions'])) {
- Http::json(['error' => 'Données du verdict manquantes ou invalides'], 400);
- exit;
- }
- // Email optionnel : si fourni, doit être valide
- if ($email !== null && $email !== '') {
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- Http::json(['error' => 'Email invalide'], 400);
- exit;
- }
- } else {
- $email = null;
- }
- $result = [
- 'level' => (string) $raw['level'],
- 'title' => (string) $raw['title'],
- 'summary' => (string) $raw['summary'],
- 'score' => (int) $raw['score'],
- 'total' => (int) $raw['total'],
- 'actions' => array_values(array_map('strval', (array) ($raw['actions'] ?? []))),
- 'qual' => is_array($raw['qual'] ?? null) ? $raw['qual'] : [],
- ];
- $outbox = new OutboxStorage($root . '/storage/outbox');
- $outbox->storeExcelComplete($result, $email);
- $webhookUrl = (string) ($config['admin_notify_webhook'] ?? '');
- if ($webhookUrl !== '' && filter_var($webhookUrl, FILTER_VALIDATE_URL)) {
- (new AdminNotifier($webhookUrl, $outbox))->notifyExcelComplete($result, $email);
- }
- Http::json(['status' => 'ok']);
|