@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
97 lines • 4.43 kB
JavaScript
import { AnalyticsWebAbsolute, SecureCDNalyticsWebAbsolute } from "../../../../restAPIs/logging/interfaces/constants";
import { getCurrentFPSDigest } from "./getCurrentFPSDigest";
import { msPer30Min, } from "../../../../logic/Time/constants";
// import { CurrentSiteAbsolute } from "../../../../logic/Strings/getSiteCollectionUrlFromLink";
import { getSiteCollectionUrlFromLink } from "../../../../logic/Strings/getSiteCollectionUrlFromLink";
import { CurrentSiteAbsolute } from "../../source-props/WindowLocationConstants";
export function check4ThisFPSDigestValue(absoluteUrl) {
const digest = check4ThisFPSDigest(absoluteUrl);
return digest.digestValue;
}
/**
* If you need to use digestValues, such as in SE or certain calls,
* It's best to call this during the onInit because you have the context.
*
* Then later on, you can pass in null for the context because the digestValue will already be updated
*
* @param classContext
* @param absoluteUrl
* @returns
*/
export function check4ThisFPSDigest(absoluteUrl) {
const startTime = Date.now();
let fpsWindowProps = getCurrentFPSDigest();
let returnDigest = null;
absoluteUrl = getSiteCollectionUrlFromLink(absoluteUrl);
/**
* CHANGE: https://github.com/mikezimm/pivottiles7/issues/421
* was if ( absoluteUrl === AnalyticsWebAbsolute ) {
* Original was not setting the main props on FPSDigest
*/
if (AnalyticsWebAbsolute.indexOf(absoluteUrl) > -1) {
// fpsWindowProps.AnalyticsWeb.queries ++;
// clear and get again of > 30 minutes old
if (startTime - fpsWindowProps.AnalyticsWeb.time > msPer30Min) {
fpsWindowProps.AnalyticsWeb.digestValue = '';
fpsWindowProps.AnalyticsWeb.time = 0;
}
returnDigest = fpsWindowProps.AnalyticsWeb;
/**
* CHANGE: https://github.com/mikezimm/pivottiles7/issues/421
* was else if ( absoluteUrl === SecureCDNalyticsWebAbsolute ) {
* Original was not setting the main props on FPSDigest
*/
}
else if (SecureCDNalyticsWebAbsolute.indexOf(absoluteUrl) > -1) {
// fpsWindowProps.SecureCDNAlyticsWeb.queries ++;
// clear and get again of > 30 minutes old
if (startTime - fpsWindowProps.SecureCDNAlyticsWeb.time > msPer30Min) {
fpsWindowProps.SecureCDNAlyticsWeb.digestValue = '';
fpsWindowProps.SecureCDNAlyticsWeb.time = 0;
}
returnDigest = fpsWindowProps.SecureCDNAlyticsWeb;
/**
* CHANGE: https://github.com/mikezimm/pivottiles7/issues/421
* was else if ( absoluteUrl === CurrentSiteAbsolute ) {
* Original was not setting the main props on FPSDigest
*/
}
else if (CurrentSiteAbsolute.indexOf(absoluteUrl) > -1) {
// fpsWindowProps.CurrentSite.queries ++;
// clear and get again of > 30 minutes old
if (startTime - fpsWindowProps.CurrentSite.time > msPer30Min) {
fpsWindowProps.CurrentSite.digestValue = '';
fpsWindowProps.CurrentSite.time = 0;
}
returnDigest = fpsWindowProps.CurrentSite;
}
else {
// See if it was already saved
if (fpsWindowProps.sites.length > 0) {
// remove expired values
fpsWindowProps.sites.map((site) => {
if (startTime - site.time > msPer30Min) {
site.digestValue = '';
site.time = 0;
}
});
// Check to see if there is a current digestValue available
fpsWindowProps.sites.map((site) => {
if (!returnDigest && site.url === absoluteUrl) {
returnDigest = site;
// site.queries ++;
}
});
}
/**
* 2024-12-15: Moved this check outside of last curley for the first site.
* Prior to this, it was always getting skipped because the length was 0 and caused an error
*/
if (!returnDigest) {
returnDigest = { url: absoluteUrl, digestValue: '', time: startTime, new: 0, queries: 0, idx: fpsWindowProps.sites.length };
fpsWindowProps.sites.push(returnDigest);
}
}
return returnDigest;
}
//# sourceMappingURL=check4ThisFPSDigestValue.js.map