Corriger les liens et la synchronisation i-CAD

This commit is contained in:
Alexandre NOEL 2026-10-01 22:33:41 +02:00
commit 9ff26ad9be
10 changed files with 83 additions and 23 deletions

View file

@ -448,6 +448,7 @@ final class AnimalsController
}
$db = DB::pdo();
$id = (int) ($_POST['id'] ?? 0);
$wantsJson = str_contains(strtolower((string) ($_SERVER['HTTP_ACCEPT'] ?? '')), 'application/json');
if ($id <= 0) {
http_response_code(400);
echo h(t('error.bad_request'));
@ -468,6 +469,10 @@ final class AnimalsController
$chipId = preg_replace('/\D+/', '', (string) ($animal['chip_id'] ?? ''));
if ($chipId === '') {
if (!$wantsJson) {
header('Location: /animal?id=' . $id . '#tab-ident');
return;
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['cached' => null, 'stale' => true, 'error' => 'chip_id vide'], JSON_UNESCAPED_UNICODE);
return;
@ -489,6 +494,10 @@ final class AnimalsController
$stale = $svc->isStale($cached, 86400);
}
if (!$wantsJson) {
header('Location: /animal?id=' . $id . '#tab-ident');
return;
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['cached' => $cached, 'stale' => $stale], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}