Regalamiunsorriso/www/faceai_return.php
MaddoScientisto 2218c9a84c
All checks were successful
Publish FaceAI Container / publish (push) Successful in 2m42s
End to end tests
2026-04-12 19:31:12 +02:00

69 lines
2.6 KiB
PHP

<?php
require_once __DIR__ . '/faceai_config.php';
require_once __DIR__ . '/faceai_simulator_view.php';
$config = faceai_config();
try {
$resultId = faceai_request_value('resultId');
$token = faceai_request_value('token');
if ($resultId === '' || $token === '') {
faceai_render_message_page(
'FaceAI return non disponibile',
'Mancano resultId o token nella chiamata di ritorno da FaceAI.',
array(),
400
);
}
$payload = faceai_verify_payload($token, $config['shared_secret']);
if (($payload['type'] ?? '') !== 'return') {
throw new RuntimeException('Wrong return token type.');
}
if ((string) ($payload['resultId'] ?? '') !== $resultId) {
throw new RuntimeException('Result id mismatch.');
}
if ($config['return_forward_url'] !== '') {
header('Location: ' . faceai_build_url($config['return_forward_url'], array(
'resultId' => $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);
$matches = is_array($result['matches'] ?? null) ? $result['matches'] : array();
$photos = array_map(static function ($match) {
$photoId = (string) ($match['photoId'] ?? ($match['id'] ?? ''));
return array(
'id' => $photoId,
'photoId' => $photoId,
'label' => (string) ($match['label'] ?? $photoId),
'checkpoint' => (string) ($match['checkpoint'] ?? '-'),
'previewUrl' => (string) ($match['previewUrl'] ?? ''),
'score' => $match['score'] ?? null,
);
}, $matches);
faceai_sim_render_page(array(
'raceId' => (string) ($result['raceId'] ?? ($payload['raceId'] ?? '')),
'lang' => (string) ($result['lang'] ?? 'it'),
'raceSlug' => (string) ($result['raceId'] ?? ($payload['raceId'] ?? '')),
'raceName' => (string) ($result['raceName'] ?? ('Race ' . ($payload['raceId'] ?? ''))),
'returnUrl' => (string) ($result['returnUrl'] ?? 'faceai_simulator.php'),
'banner' => 'Vista filtrata da FaceAI. Sono state trovate <strong>' . count($photos) . '</strong> foto corrispondenti per l utente corrente.',
'totalLabel' => count($photos) . ' foto da FaceAI',
'photos' => $photos,
'showSimulatorBootstrap' => false
));
} catch (Throwable $error) {
faceai_render_message_page('Errore return FaceAI', $error->getMessage(), array(), 500);
}