Trying to clean up the initial loading... Checking the local storage and indexes and site keys.

This commit is contained in:
Scott Idem
2024-11-21 16:45:13 -05:00
parent 2ef3c8bab5
commit d1f04e4dc3

View File

@@ -97,70 +97,70 @@ $slct = {
// IDB caches - Check if the last reload timestamp for $ae_loc.last_idb_reload is no more than 15 minutes ago.
let default_idb_reload_time = 120 * 60 * 1000; // 15 minutes?
let trusted_idb_reload_time = 4 * 60 * 60 * 1000; // 4 hours or 120 minutes?
if (!$ae_loc.last_idb_reload) {
console.log(`Last reload not found. Need to reset.`);
// if (!$ae_loc.last_idb_reload) {
// console.log(`Last reload not found. Need to reset.`);
// $ae_loc.last_idb_reload = Date.now();
if (browser) {
$ae_loc.last_idb_reload = Date.now();
// // $ae_loc.last_idb_reload = Date.now();
// if (browser) {
// $ae_loc.last_idb_reload = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db');
indexedDB.deleteDatabase('ae_notes_db');
indexedDB.deleteDatabase('ae_posts_db');
// // Clear Indexed DB as well
// indexedDB.deleteDatabase('ae_archives_db');
// indexedDB.deleteDatabase('ae_core_db');
// indexedDB.deleteDatabase('ae_events_db');
// indexedDB.deleteDatabase('ae_notes_db');
// indexedDB.deleteDatabase('ae_posts_db');
// localStorage.removeItem('ae_loc');
// localStorage.removeItem('events_loc');
// // localStorage.removeItem('ae_loc');
// // localStorage.removeItem('events_loc');
// window.location.reload();
}
// // window.location.reload();
// }
} else if ($ae_loc.last_idb_reload && $ae_loc.trusted_access && (Date.now() - $ae_loc.last_idb_reload) > trusted_idb_reload_time) {
console.log(`Last reload too old:`, $ae_loc.last_idb_reload);
// } else if ($ae_loc.last_idb_reload && $ae_loc.trusted_access && (Date.now() - $ae_loc.last_idb_reload) > trusted_idb_reload_time) {
// console.log(`Last reload too old:`, $ae_loc.last_idb_reload);
if (browser) {
$ae_loc.last_idb_reload = Date.now();
// if (browser) {
// $ae_loc.last_idb_reload = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db');
indexedDB.deleteDatabase('ae_notes_db');
indexedDB.deleteDatabase('ae_posts_db');
// // Clear Indexed DB as well
// indexedDB.deleteDatabase('ae_archives_db');
// indexedDB.deleteDatabase('ae_core_db');
// indexedDB.deleteDatabase('ae_events_db');
// indexedDB.deleteDatabase('ae_notes_db');
// indexedDB.deleteDatabase('ae_posts_db');
// localStorage.removeItem('ae_loc');
// localStorage.removeItem('events_loc');
// // localStorage.removeItem('ae_loc');
// // localStorage.removeItem('events_loc');
window.location.reload();
}
} else if ($ae_loc.last_idb_reload && (Date.now() - $ae_loc.last_idb_reload) > default_idb_reload_time) {
console.log(`Last reload too old:`, $ae_loc.last_idb_reload);
// window.location.reload();
// }
// } else if ($ae_loc.last_idb_reload && (Date.now() - $ae_loc.last_idb_reload) > default_idb_reload_time) {
// console.log(`Last reload too old:`, $ae_loc.last_idb_reload);
if (browser) {
$ae_loc.last_idb_reload = Date.now();
// if (browser) {
// $ae_loc.last_idb_reload = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db');
// // Clear Indexed DB as well
// indexedDB.deleteDatabase('ae_core_db');
// indexedDB.deleteDatabase('ae_events_db');
// localStorage.removeItem('ae_loc');
// localStorage.removeItem('events_loc');
// // localStorage.removeItem('ae_loc');
// // localStorage.removeItem('events_loc');
window.location.reload();
}
} else if (browser) {
console.log(`Last reload is recent: ${$ae_loc.last_idb_reload}`);
// Clear Indexed DB as well
// indexedDB.deleteDatabase('ae_core_db');
// indexedDB.deleteDatabase('ae_events_db');
// window.location.reload();
// }
// } else if (browser) {
// console.log(`Last reload is recent: ${$ae_loc.last_idb_reload}`);
// // Clear Indexed DB as well
// // indexedDB.deleteDatabase('ae_core_db');
// // indexedDB.deleteDatabase('ae_events_db');
// localStorage.removeItem('ae_loc');
// localStorage.removeItem('events_loc');
// // localStorage.removeItem('ae_loc');
// // localStorage.removeItem('events_loc');
// window.location.reload();
}
// // window.location.reload();
// }
// There should almost always be an event_id set.
if ($ae_loc?.site_cfg_json.slct__event_id) {
@@ -189,11 +189,7 @@ if ($ae_loc.site_cfg_json.slct__sponsorship_cfg_id) {
}
// This needs to be re-worked ASAP! 2024-11-21
// Is most of this even needed? Just check every time. Why do we care if we checked recently or ever.
// Instead: Check if the access key is set and if it is the same as the site or domain access key.
// What happens if the access key is set and it is not the same as the site or domain access key? I guess the restriction was removed so it can be used without the key.
// Updated 2024-11-21
if ($ae_loc.site_access_key || $ae_loc.site_domain_access_key) {
console.log(`We need to do a current check against the allow_access value.`);
@@ -214,69 +210,79 @@ if ($ae_loc.site_access_key || $ae_loc.site_domain_access_key) {
}
// if ($ae_loc.iframe) {
// $ae_loc.allow_access = true;
// } else {
// if ($ae_loc.allow_access && !$ae_loc.key_checked) {
// console.log(`PASS: The access key was checked earlier.`);
// // allow_access should equal true or the access key.
// if ($ae_loc.site_access_key || $ae_loc.site_domain_access_key) {
// console.log(`We need to do a current check against the allow_access value.`);
// if ($ae_loc.site_access_key == $ae_loc.allow_access || $ae_loc.site_domain_access_key == $ae_loc.allow_access) {
// console.log(`PASS: The access key was checked earlier and we just now checked the key.`);
// } else {
// console.log(`FAIL: The access key was checked earlier, but just now failed.`);
// if ($ae_loc.trusted_access) {
// console.log(`FAIL: The access key was checked earlier and failed, but we have trusted access.`);
// $ae_loc.allow_access = true;
// } else {
// $ae_loc.allow_access = false;
// }
// }
// } else {
// // This means this site and domain do not require an access key.
// // Do nothing to change the allow_access here at this time.
// }
// } else if ($ae_loc.allow_access && $ae_loc.key_checked) {
// console.log(`PASS: The access key was checked earlier and we just now checked the key.`);
// } else if (!$ae_loc.allow_access && $ae_loc.key_checked) {
// console.log(`FAIL: The access key was checked earlier and failed.`);
// if ($ae_loc.trusted_access) {
// console.log(`FAIL: The access key was checked earlier and failed, but we have trusted access.`);
// $ae_loc.allow_access = true;
// }
// } else {
// console.log(`FAIL: The access key was not checked earlier.`);
// // $ae_loc.key_checked = true;
// }
// }
// $: access_key = data.url.searchParams.get('key');
// console.log(`access_key = `, access_key);
if (browser) {
// Waiting until the browser exists.
if ($ae_loc && $ae_sess && $ae_loc.ver_idb != $ae_sess.ver_idb) {
console.log('New version of the IDB available!!!');
console.log(`$ae_loc.ver_idb: ${$ae_loc.ver_idb} != $ae_sess.ver_idb: ${$ae_sess.ver_idb}`);
if (!$ae_loc.last_idb_reload) {
if (log_lvl) {
console.log(`Last reload not found. Need to set!`);
}
$ae_loc.last_idb_reload = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db');
indexedDB.deleteDatabase('ae_notes_db');
indexedDB.deleteDatabase('ae_posts_db');
} else if ($ae_loc.last_idb_reload && $ae_loc.trusted_access && (Date.now() - $ae_loc.last_idb_reload) > trusted_idb_reload_time) {
if (log_lvl) {
console.log(`Last (trusted) reload too old: ${$ae_loc.last_idb_reload}`);
}
$ae_loc.ver_idb = $ae_sess.ver_idb;
$ae_loc.last_idb_reload = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db');
indexedDB.deleteDatabase('ae_notes_db');
indexedDB.deleteDatabase('ae_posts_db');
// localStorage.removeItem('ae_loc');
// localStorage.removeItem('events_loc');
window.location.reload();
} else if ($ae_loc.last_idb_reload && (Date.now() - $ae_loc.last_idb_reload) > default_idb_reload_time) {
if (log_lvl) {
console.log(`Last (default) reload too old: ${$ae_loc.last_idb_reload}`);
}
$ae_loc.last_idb_reload = Date.now();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_archives_db');
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db');
indexedDB.deleteDatabase('ae_notes_db');
indexedDB.deleteDatabase('ae_posts_db');
// localStorage.removeItem('ae_loc');
// localStorage.removeItem('events_loc');
window.location.reload();
} else {
if (log_lvl > 1) {
console.log(`Last reload is recent: ${$ae_loc.last_idb_reload}`);
}
}
// Waiting until the browser exists.
// if ($ae_loc && $ae_sess && $ae_loc.ver_idb != $ae_sess.ver_idb) {
// console.log('New version of the IDB available!!!');
// console.log(`$ae_loc.ver_idb: ${$ae_loc.ver_idb} != $ae_sess.ver_idb: ${$ae_sess.ver_idb}`);
// // Clear Indexed DB as well
// indexedDB.deleteDatabase('ae_archives_db');
// indexedDB.deleteDatabase('ae_core_db');
// indexedDB.deleteDatabase('ae_events_db');
// indexedDB.deleteDatabase('ae_notes_db');
// indexedDB.deleteDatabase('ae_posts_db');
// $ae_loc.ver_idb = $ae_sess.ver_idb;
// window.location.reload();
// }
if ($ae_loc && $ae_sess && ($ae_loc.ver != $ae_sess.ver)) {
console.log('New version of the data store available!!!');
console.log(`$ae_loc.ver: ${$ae_loc.ver} != $ae_sess.ver: ${$ae_sess.ver}`);