Corriger les liens et la synchronisation i-CAD
This commit is contained in:
parent
7b89fd5dfa
commit
9ff26ad9be
10 changed files with 83 additions and 23 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue