www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -458,12 +458,168 @@ function stripFaceAiStateFromUrl(url) {
|
|||
cleanUrl.searchParams.delete("faceaiMatchCount");
|
||||
cleanUrl.searchParams.delete("faceaiPhotoIds");
|
||||
cleanUrl.searchParams.delete("faceaiMatchStorageKey");
|
||||
cleanUrl.searchParams.delete("faceaiResultId");
|
||||
cleanUrl.searchParams.delete("faceaiToken");
|
||||
return cleanUrl.toString();
|
||||
} catch (error) {
|
||||
return url || fallbackUrl;
|
||||
}
|
||||
}
|
||||
|
||||
function buildFaceAiBackendBaseUrl() {
|
||||
var configuredUrl = "";
|
||||
var parsedUrl;
|
||||
|
||||
if (window.faceAiConfig && window.faceAiConfig.backendBaseUrl) {
|
||||
configuredUrl = String(window.faceAiConfig.backendBaseUrl || "").trim();
|
||||
}
|
||||
|
||||
if (!configuredUrl && window.faceAiSimulator && window.faceAiSimulator.handoffUrl) {
|
||||
configuredUrl = String(window.faceAiSimulator.handoffUrl || "").trim();
|
||||
}
|
||||
|
||||
if (!configuredUrl) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
parsedUrl = new URL(configuredUrl, window.location.href);
|
||||
return parsedUrl.origin;
|
||||
} catch (error) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function getFaceAiDirectReturnState() {
|
||||
if (typeof URLSearchParams === "undefined") {
|
||||
return null;
|
||||
}
|
||||
|
||||
var params = new URLSearchParams(window.location.search || "");
|
||||
var resultId = String(params.get("faceaiResultId") || "").trim();
|
||||
var token = String(params.get("faceaiToken") || "").trim();
|
||||
var backendBaseUrl = buildFaceAiBackendBaseUrl();
|
||||
|
||||
if (!resultId || !token || !backendBaseUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
resultId: resultId,
|
||||
token: token,
|
||||
backendBaseUrl: backendBaseUrl,
|
||||
clearUrl: stripFaceAiStateFromUrl(window.location.href)
|
||||
};
|
||||
}
|
||||
|
||||
function persistFaceAiDirectReturnPayload(matchState, clearUrl) {
|
||||
var storageKey;
|
||||
var entryKey;
|
||||
var pendingEntryKey;
|
||||
var payload;
|
||||
var pendingPayload;
|
||||
var photoIdSet = {};
|
||||
var index;
|
||||
|
||||
if (!matchState || !matchState.photoIds || !matchState.photoIds.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
storageKey = "faceai-result-" + String(matchState.resultId || "").replace(/[^a-zA-Z0-9_-]/g, "");
|
||||
entryKey = getFaceAiMatchStorageEntryKey(storageKey);
|
||||
pendingEntryKey = getFaceAiPendingMatchEntryKey();
|
||||
payload = {
|
||||
photoIds: matchState.photoIds.slice(0),
|
||||
matchCount: matchState.matchCount,
|
||||
storedAt: new Date().toISOString()
|
||||
};
|
||||
pendingPayload = {
|
||||
storageKey: storageKey,
|
||||
raceId: String(matchState.raceId || getFaceAiCurrentRaceId() || "").trim(),
|
||||
targetPath: (function() {
|
||||
try {
|
||||
return String(new URL(clearUrl || window.location.href, window.location.href).pathname || "");
|
||||
} catch (error) {
|
||||
return window.location.pathname || "";
|
||||
}
|
||||
}()),
|
||||
payload: payload
|
||||
};
|
||||
|
||||
if (canUseFaceAiWebStorage(window.sessionStorage)) {
|
||||
window.sessionStorage.setItem(entryKey, JSON.stringify(payload));
|
||||
window.sessionStorage.setItem(pendingEntryKey, JSON.stringify(pendingPayload));
|
||||
}
|
||||
|
||||
if (canUseFaceAiWebStorage(window.localStorage)) {
|
||||
window.localStorage.setItem(entryKey, JSON.stringify(payload));
|
||||
window.localStorage.setItem(pendingEntryKey, JSON.stringify(pendingPayload));
|
||||
}
|
||||
|
||||
try {
|
||||
window.name = JSON.stringify({
|
||||
faceAiStorageKey: storageKey,
|
||||
faceAiMatchState: payload,
|
||||
faceAiPendingMatchState: pendingPayload
|
||||
});
|
||||
} catch (error) {}
|
||||
|
||||
for (index = 0; index < payload.photoIds.length; index += 1) {
|
||||
photoIdSet[payload.photoIds[index]] = true;
|
||||
}
|
||||
|
||||
window.faceAiMatchState = {
|
||||
photoIds: payload.photoIds,
|
||||
photoIdSet: photoIdSet,
|
||||
matchCount: payload.matchCount,
|
||||
storageKey: storageKey,
|
||||
clearUrl: clearUrl || stripFaceAiStateFromUrl(window.location.href),
|
||||
resultId: matchState.resultId,
|
||||
raceId: pendingPayload.raceId
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function hydrateFaceAiDirectReturn() {
|
||||
var directReturnState = getFaceAiDirectReturnState();
|
||||
|
||||
if (!directReturnState) {
|
||||
return $.Deferred().resolve(false).promise();
|
||||
}
|
||||
|
||||
return $.getJSON(directReturnState.backendBaseUrl + "/bridge/results/" + encodeURIComponent(directReturnState.resultId), {
|
||||
token: directReturnState.token
|
||||
}).then(function(payload) {
|
||||
var matches = payload && payload.matches ? payload.matches : [];
|
||||
var photoIds = [];
|
||||
var photoIdLookup = {};
|
||||
var index;
|
||||
var photoId;
|
||||
|
||||
for (index = 0; index < matches.length; index += 1) {
|
||||
photoId = String((matches[index] && (matches[index].photoId || matches[index].id)) || "").trim();
|
||||
if (!photoId || photoIdLookup[photoId]) {
|
||||
continue;
|
||||
}
|
||||
photoIdLookup[photoId] = true;
|
||||
photoIds.push(photoId);
|
||||
}
|
||||
|
||||
persistFaceAiDirectReturnPayload({
|
||||
resultId: directReturnState.resultId,
|
||||
raceId: String((payload && payload.raceId) || "").trim(),
|
||||
photoIds: photoIds,
|
||||
matchCount: photoIds.length
|
||||
}, directReturnState.clearUrl);
|
||||
|
||||
window.location.replace(directReturnState.clearUrl);
|
||||
return true;
|
||||
}, function() {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function getFaceAiMatchState() {
|
||||
if (typeof URLSearchParams === "undefined") {
|
||||
return null;
|
||||
|
|
@ -902,6 +1058,17 @@ function prepareFaceAiLegacyRacePage() {
|
|||
return matchState;
|
||||
}
|
||||
|
||||
function initFaceAiLegacyRacePage() {
|
||||
var directReturnState = getFaceAiDirectReturnState();
|
||||
|
||||
if (directReturnState) {
|
||||
hydrateFaceAiDirectReturn();
|
||||
return null;
|
||||
}
|
||||
|
||||
return prepareFaceAiLegacyRacePage();
|
||||
}
|
||||
|
||||
function buildFaceAiLaunchUrl() {
|
||||
var raceId = $("#id_gara").val() || "";
|
||||
var raceSlug = $("#garaDesc").val() || "";
|
||||
|
|
@ -1209,7 +1376,7 @@ function goPage()
|
|||
|
||||
$(function() {
|
||||
clearLegacyLoadingState();
|
||||
prepareFaceAiLegacyRacePage();
|
||||
initFaceAiLegacyRacePage();
|
||||
initFaceAiRaceSearchButton();
|
||||
initFaceAiErrorModal();
|
||||
logFaceAiDebug("Legacy race page ready");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue