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 {
|
||||
|
||||
Reference in New Issue
Block a user