$resultId, 'token' => $token )), true, 302); exit; } $bridgeUrl = faceai_build_url($config['backend_internal_url'] . '/bridge/results/' . rawurlencode($resultId), array( 'token' => $token )); $result = faceai_fetch_json($bridgeUrl); $returnUrl = (string) ($result['returnUrl'] ?? ''); $matches = is_array($result['matches'] ?? null) ? $result['matches'] : array(); if ($returnUrl === '') { throw new RuntimeException('Missing legacy return URL.'); } $photoIds = array(); foreach ($matches as $match) { $photoId = trim((string) ($match['photoId'] ?? ($match['id'] ?? ''))); if ($photoId === '') { continue; } $photoIds[$photoId] = true; } $matchCount = count($photoIds); if ($matchCount === 0) { header('Location: ' . faceai_build_url($returnUrl, array( 'faceaiMatchSource' => 'faceai', 'faceaiMatchCount' => 0 )), true, 302); exit; } $storageKey = 'faceai-result-' . preg_replace('/[^a-zA-Z0-9_-]/', '', $resultId); $redirectUrl = faceai_build_url($returnUrl, array( 'faceaiMatchSource' => 'faceai', 'faceaiMatchCount' => $matchCount, 'faceaiMatchStorageKey' => $storageKey )); faceai_render_storage_redirect_page($redirectUrl, $storageKey, array_keys($photoIds), $matchCount, (string) ($result['raceId'] ?? ($payload['raceId'] ?? ''))); } catch (Throwable $error) { faceai_render_message_page('Errore return FaceAI', $error->getMessage(), array(), 500); }