I guess this is better than it was...
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { browser } from '$app/environment';
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
@@ -56,7 +57,26 @@ async function handle_load_ae_obj_id__site_domain({ api_cfg, fqdn, try_cache=fal
|
||||
}
|
||||
|
||||
// handle_load_ae_obj_code__data_store
|
||||
async function handle_load_ae_obj_code__data_store({ api_cfg, code=null, data_type='text' }) {
|
||||
async function handle_load_ae_obj_code__data_store(
|
||||
{
|
||||
api_cfg,
|
||||
code,
|
||||
data_type='text',
|
||||
for_type=null,
|
||||
for_id=null,
|
||||
try_cache=true,
|
||||
save_idb=false
|
||||
}: {
|
||||
api_cfg: any,
|
||||
code: string,
|
||||
data_type: string,
|
||||
for_type: string|null,
|
||||
for_id: string|null,
|
||||
try_cache: boolean,
|
||||
save_idb: boolean
|
||||
}
|
||||
) {
|
||||
|
||||
console.log(`*** handle_get_data_store_obj_w_code() *** code=${code}`);
|
||||
|
||||
if (!code) {
|
||||
@@ -75,16 +95,90 @@ async function handle_load_ae_obj_code__data_store({ api_cfg, code=null, data_ty
|
||||
data_type: data_type,
|
||||
log_lvl: 0
|
||||
})
|
||||
.then(function (get_data_store_result) {
|
||||
.then(function (get_ds_result) {
|
||||
let return_this = null;
|
||||
if (get_data_store_result) {
|
||||
if (get_ds_result) {
|
||||
console.log(`Got a result for code ${code}`);
|
||||
|
||||
if (data_type == 'text') {
|
||||
// console.log(get_data_store_result.text);
|
||||
return_this = get_data_store_result.text;
|
||||
if (!get_ds_result.data_store_id_random) {
|
||||
console.log('Something went wrong? No data store ID found.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// let ae_ds_tmp: key_val = {};
|
||||
let ds_code_obj =
|
||||
{
|
||||
id: null,
|
||||
account_id: null,
|
||||
code: code,
|
||||
name: null,
|
||||
type: data_type,
|
||||
for_type: null, // for_type
|
||||
for_id: null, // for_id
|
||||
access_read: null, // 'super', 'administrator', 'trusted', 'anonymous'
|
||||
access_write: null, // 'super', 'administrator', 'trusted', 'anonymous'
|
||||
access_delete: null, // 'super', 'administrator', 'trusted', 'anonymous'
|
||||
html: null,
|
||||
json: null,
|
||||
md: null,
|
||||
text: null,
|
||||
updated_on: null,
|
||||
chk_account_id: api_cfg.account_id,
|
||||
loaded_on: new Date().toISOString(),
|
||||
};
|
||||
let val_json: key_val;
|
||||
let val_html: key_val;
|
||||
let val_md: key_val;
|
||||
let val_sql: key_val;
|
||||
let val_text: string;
|
||||
|
||||
// Set the loaded_on datetime to the current time for reference later. This will be used to determine if the data store is stale.
|
||||
// ds_code_obj.loaded_on = new Date().toISOString();
|
||||
// Set the chk_account_id as a backup check to make sure the data store belongs to the account for the current site. This should not be needed, but here we are...
|
||||
// ds_code_obj.chk_account_id = api_cfg.account_id;
|
||||
|
||||
ds_code_obj.id = get_ds_result.data_store_id_random;
|
||||
ds_code_obj.account_id = get_ds_result.account_id_random;
|
||||
ds_code_obj.code = get_ds_result.code; // This will overwrite whatever was passed in.
|
||||
ds_code_obj.name = get_ds_result.name;
|
||||
ds_code_obj.type = get_ds_result.type; // This will overwrite whatever was passed in.
|
||||
if (data_type == 'html') {
|
||||
ds_code_obj.html = get_ds_result.text;
|
||||
val_html = get_ds_result.text;
|
||||
return_this = get_ds_result.html;
|
||||
} else if (data_type == 'json') {
|
||||
// console.log(get_data_store_result.json);
|
||||
return_this = get_data_store_result.json;
|
||||
ds_code_obj.json = get_ds_result.json;
|
||||
val_json = get_ds_result.json;
|
||||
return_this = get_ds_result.json;
|
||||
} else if (data_type == 'md') {
|
||||
ds_code_obj.text = get_ds_result.text;
|
||||
val_md = get_ds_result.text;
|
||||
return_this = get_ds_result.text;
|
||||
} else if (data_type == 'sql') {
|
||||
ds_code_obj.text = get_ds_result.text;
|
||||
val_sql = get_ds_result.text;
|
||||
return_this = get_ds_result.text;
|
||||
} else {
|
||||
ds_code_obj.text = get_ds_result.text;
|
||||
val_text = get_ds_result.text;
|
||||
return_this = get_ds_result.text;
|
||||
}
|
||||
|
||||
// if (data_type == 'text') {
|
||||
// // console.log(get_ds_result.text);
|
||||
// return_this = get_ds_result.text;
|
||||
// } else if (data_type == 'json') {
|
||||
// // console.log(get_ds_result.json);
|
||||
// return_this = get_ds_result.json;
|
||||
// }
|
||||
|
||||
if (save_idb) {
|
||||
if (browser) {
|
||||
console.log(`ae_ds__ key: ${code}, value:`, get_ds_result);
|
||||
localStorage.setItem(`ae_ds__${code}`, JSON.stringify(get_ds_result));
|
||||
} else {
|
||||
console.log('No browser!!!');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -91,7 +91,7 @@ console.log(`AE Stores - App Events Local Storage Data:`, events_local_data_stru
|
||||
// export let ae_loc = writable(events_local_data_struct);
|
||||
|
||||
// This works and uses *local* storage:
|
||||
export let events_loc: Writable<key_val> = localStorageStore('ae_ events_loc', events_local_data_struct);
|
||||
export let events_loc: Writable<key_val> = localStorageStore('ae_events_loc', events_local_data_struct);
|
||||
// console.log(`AE Stores - App Local Storage Data:`, get(ae_loc));
|
||||
|
||||
|
||||
|
||||
@@ -92,8 +92,10 @@ export let get_object = async function get_object({api_cfg, endpoint='', headers
|
||||
/* other custom settings */
|
||||
});
|
||||
axios_api.defaults.headers = api_cfg['headers'];
|
||||
console.log('axios_api.defaults.headers:', axios_api.defaults.headers);
|
||||
console.log('Additional headers:', headers);
|
||||
if (log_lvl) {
|
||||
console.log('axios_api.defaults.headers:', axios_api.defaults.headers);
|
||||
console.log('Additional headers:', headers);
|
||||
}
|
||||
|
||||
// console.log('Clean the headers. No _underscores_!')
|
||||
let headers_cleaned = {};
|
||||
@@ -113,12 +115,16 @@ export let get_object = async function get_object({api_cfg, endpoint='', headers
|
||||
}
|
||||
}
|
||||
headers = headers_cleaned;
|
||||
console.log('All headers cleaned:', headers);
|
||||
if (log_lvl) {
|
||||
console.log('All headers cleaned:', headers);
|
||||
}
|
||||
|
||||
console.log('URL params:');
|
||||
if (log_lvl) {
|
||||
console.log('URL params:');
|
||||
}
|
||||
for (const prop in params) {
|
||||
if (log_lvl) {
|
||||
console.log(`${prop}: ${params[prop]}`);
|
||||
console.log(`URL param: ${prop}: ${params[prop]}`);
|
||||
}
|
||||
if (params[prop] === null ) {
|
||||
params[prop] = 'null';
|
||||
|
||||
@@ -39,7 +39,7 @@ $: if (trigger && $ae_loc.access_type) {
|
||||
|
||||
|
||||
function handle_check_access_type_passcode() {
|
||||
// console.log('*** handle_check_access_type_passcode() ***');
|
||||
console.log(`*** handle_check_access_type_passcode() *** passcode list:`, $ae_loc.page_access_code_li);
|
||||
|
||||
if (entered_passcode && entered_passcode.length >= 5) {
|
||||
if ($ae_loc.page_access_code_li.administrator == entered_passcode) {
|
||||
|
||||
@@ -64,7 +64,8 @@ let ds_code_obj =
|
||||
};
|
||||
|
||||
let ae_ds_loc: Writable<key_val> = localStorageStore(`ae_ds__${ds_code}`, ds_code_obj);
|
||||
console.log(`ae_e_data_store cached: ${ds_code} = `, $ae_ds_loc);
|
||||
// console.log(`ae_e_data_store cached: ${ds_code} = `, $ae_ds_loc);
|
||||
console.log(`ae_e_data_store cached: ${ds_code} account_id=${$ae_loc.account_id}`);
|
||||
|
||||
if (!$ae_ds_loc.id) {
|
||||
ds_loading_status = '-- loading --';
|
||||
|
||||
Reference in New Issue
Block a user