feat: Add FaceAI integration with handoff and return functionality
- Introduced a new workspace for FaceAI in package.json. - Implemented FaceAI handoff logic in faceai_handoff.php, including identity verification and token signing. - Created faceai_return.php to handle return requests from FaceAI, validating tokens and forwarding results. - Developed faceai_simulator.php and faceai_simulator_view.php for simulating the FaceAI interface with demo photos. - Enhanced rus-ecom-240621.js to support new FaceAI features, including dynamic URL building and button integration. - Added faceai_config.php for configuration management, including environment variable handling and utility functions. - Updated HTML structure and styles in simulator view for better user experience.
This commit is contained in:
parent
f65a85dcc9
commit
da362c201f
31 changed files with 4511 additions and 60 deletions
56
www/faceai_return.php
Normal file
56
www/faceai_return.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?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);
|
||||
|
||||
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($result['matches'] ?? array()) . '</strong> foto corrispondenti per l utente corrente.',
|
||||
'totalLabel' => count($result['matches'] ?? array()) . ' foto da FaceAI',
|
||||
'photos' => is_array($result['matches'] ?? null) ? $result['matches'] : array(),
|
||||
'showSimulatorBootstrap' => false
|
||||
));
|
||||
} catch (Throwable $error) {
|
||||
faceai_render_message_page('Errore return FaceAI', $error->getMessage(), array(), 500);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue