From ac8b5acc0c9aa6ebd4527bdeaa315379b5cad89d Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Tue, 19 May 2026 17:26:06 +0000 Subject: [PATCH] fix: restore Bring! health check; token warning only when truly invalid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Restore the if($bringEnabled) block that was accidentally removed in fa0442e - Check is skipped entirely when SHOPPING_MODE != bring or credentials not set - Missing token file = first launch, auto-created on next shopping open → ok:true - Warning shown only if token file exists but access_token field is missing (corrupt) - Expired tokens are OK (refreshed automatically) Fixes spurious 'Token Bring!' warning on installs without Bring! configured --- api/index.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/api/index.php b/api/index.php index 7a66a67..f948b8e 100644 --- a/api/index.php +++ b/api/index.php @@ -510,8 +510,29 @@ if (($_GET['action'] ?? '') === 'health_check') { // Se non configurata, l'utente ha scelto di non usarla → nessun check, nessun warning. $bringEmail = $envGet('BRING_EMAIL'); $bringPassword = $envGet('BRING_PASSWORD'); - $bringEnabled = !empty($bringEmail) && !empty($bringPassword); - // If Bring! not configured, skip entirely — not a warning, it's a user choice + $shoppingMode = $envGet('SHOPPING_MODE') ?: 'native'; + $bringEnabled = !empty($bringEmail) && !empty($bringPassword) && $shoppingMode === 'bring'; + if ($bringEnabled) { + $checks['bring_credentials'] = ['ok' => true, 'optional' => true]; + // Token file is created automatically on first shopping list access — not an error if missing + $bringTokenFile = $dataDir . '/bring_token.json'; + $bringTokenOk = true; // default: fine (missing = not yet obtained, will auto-create) + $bringTokenHint = null; + if (file_exists($bringTokenFile)) { + $bringData = @json_decode(@file_get_contents($bringTokenFile), true); + $hasToken = !empty($bringData['access_token'] ?? ($bringData['accessToken'] ?? '')); + $expired = isset($bringData['expires']) && $bringData['expires'] < time(); + if (!$hasToken && !$expired) { + // File exists but token field missing — corrupt + $bringTokenOk = false; + $bringTokenHint = 'Bring! token file present but appears invalid — delete data/bring_token.json to regenerate'; + } + // Expired token is OK: it will be refreshed automatically + } + // Missing token file = first launch, will be created automatically → no warning + $checks['bring_token'] = ['ok' => $bringTokenOk, 'optional' => true, 'hint' => $bringTokenHint]; + } + // If Bring! not configured or SHOPPING_MODE != bring, skip entirely — not a warning, it is a deliberate user choice // ── 12. TTS — solo se TTS_ENABLED ──────────────────────────────────────── if ($envGet('TTS_ENABLED') === 'true') {