feat: Enhance FaceAI functionality with storage management and update deployment instructions
All checks were successful
Publish FaceAI Container / publish (push) Successful in 5m45s
All checks were successful
Publish FaceAI Container / publish (push) Successful in 5m45s
This commit is contained in:
parent
c0d072c6ea
commit
23f811e465
14 changed files with 500 additions and 22 deletions
|
|
@ -233,6 +233,63 @@ function faceai_render_message_page($title, $message, array $details = array(),
|
|||
exit;
|
||||
}
|
||||
|
||||
function faceai_render_storage_redirect_page($targetUrl, $storageKey, array $photoIds, $matchCount, $raceId = '')
|
||||
{
|
||||
http_response_code(200);
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||
header('Pragma: no-cache');
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
$payload = array(
|
||||
'photoIds' => array_values($photoIds),
|
||||
'matchCount' => (int) $matchCount,
|
||||
'storedAt' => gmdate('c')
|
||||
);
|
||||
$pendingPayload = array(
|
||||
'storageKey' => (string) $storageKey,
|
||||
'raceId' => trim((string) $raceId),
|
||||
'targetPath' => (string) (parse_url((string) $targetUrl, PHP_URL_PATH) ?: ''),
|
||||
'payload' => $payload
|
||||
);
|
||||
|
||||
echo '<!doctype html><html lang="it"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">';
|
||||
echo '<title>FaceAI redirect</title>';
|
||||
echo '<style>body{font-family:Georgia,serif;background:#f7f1e8;color:#2a231b;margin:0;padding:32px}main{max-width:900px;margin:0 auto;background:#fff;border:1px solid #ddcbb5;padding:24px}p{margin:0 0 12px}</style>';
|
||||
echo '</head><body><main><h1>Reindirizzamento FaceAI in corso</h1><p>Sto preparando i risultati e torno alla galleria della gara.</p><noscript><p>JavaScript e richiesto per completare il reindirizzamento FaceAI.</p></noscript>';
|
||||
echo '<script>';
|
||||
echo '(function () {';
|
||||
echo 'var targetUrl = ' . json_encode((string) $targetUrl) . ';';
|
||||
echo 'var storageKey = ' . json_encode((string) $storageKey) . ';';
|
||||
echo 'var payload = ' . json_encode($payload) . ';';
|
||||
echo 'var pendingPayload = ' . json_encode($pendingPayload) . ';';
|
||||
echo 'var entryKey = "faceai-match-state:" + storageKey;';
|
||||
echo 'var pendingEntryKey = "faceai-pending-match-state";';
|
||||
echo 'var stored = false;';
|
||||
echo 'function persist(storageName, key, value) {';
|
||||
echo ' try {';
|
||||
echo ' var storage = window[storageName];';
|
||||
echo ' if (!storage) { return false; }';
|
||||
echo ' storage.setItem(key, JSON.stringify(value));';
|
||||
echo ' return storage.getItem(key) !== null;';
|
||||
echo ' } catch (error) {';
|
||||
echo ' return false;';
|
||||
echo ' }';
|
||||
echo '}';
|
||||
echo 'stored = persist("sessionStorage", entryKey, payload) || persist("localStorage", entryKey, payload);';
|
||||
echo 'stored = persist("sessionStorage", pendingEntryKey, pendingPayload) || persist("localStorage", pendingEntryKey, pendingPayload) || stored;';
|
||||
echo 'try {';
|
||||
echo ' window.name = JSON.stringify({ faceAiStorageKey: storageKey, faceAiMatchState: payload, faceAiPendingMatchState: pendingPayload });';
|
||||
echo '} catch (error) {}';
|
||||
echo 'if (!stored && !window.name) {';
|
||||
echo ' document.body.innerHTML = "<main><h1>FaceAI non disponibile</h1><p>Il browser non permette di trasferire i risultati FaceAI verso la galleria.</p></main>";';
|
||||
echo ' return;';
|
||||
echo '}';
|
||||
echo 'window.location.replace(targetUrl);';
|
||||
echo '}());';
|
||||
echo '</script></main></body></html>';
|
||||
exit;
|
||||
}
|
||||
|
||||
function faceai_fetch_json($url)
|
||||
{
|
||||
$context = stream_context_create(array(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue