Regalamiunsorriso/www/faceai_return.php
MaddoScientisto bba8026b7c
All checks were successful
Publish FaceAI Container / publish (push) Successful in 4m43s
feat: Enhance FaceAI functionality and improve login process
- Added a retry mechanism for page navigation in `live-site-test-utils.js` to handle transient errors during login.
- Introduced a new function `performLiveLoginRequest` to handle login requests via API, improving the login flow.
- Updated the login process to utilize the new API request method, ensuring a more robust authentication.
- Implemented new utility functions in `rus-ecom-240621.js` for managing FaceAI state and filtering.
- Created `faceai_photo_lookup.jsp` to handle photo lookups, returning JSON responses for better integration with the frontend.
- Updated `faceai_return.php` to redirect users with appropriate parameters after FaceAI processing.
- Modified `fotoCR.jsp` and `fotoCR-en.jsp` to include FaceAI photo IDs in the image elements for better tracking.
- Enhanced the UI to display the number of matched photos dynamically based on FaceAI results.
2026-04-19 14:18:00 +02:00

65 lines
2 KiB
PHP

<?php
require_once __DIR__ . '/faceai_config.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);
$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;
}
header('Location: ' . faceai_build_url($returnUrl, array(
'faceaiMatchSource' => 'faceai',
'faceaiMatchCount' => count($photoIds),
'faceaiPhotoIds' => implode(',', array_keys($photoIds))
)), true, 302);
exit;
} catch (Throwable $error) {
faceai_render_message_page('Errore return FaceAI', $error->getMessage(), array(), 500);
}