Trying to optimize the initial fetch calls when loading.
This commit is contained in:
@@ -46,6 +46,12 @@ import {
|
||||
db_update_ae_obj_id__hosted_file
|
||||
} from "$lib/ae_core/core__hosted_files";
|
||||
|
||||
import {
|
||||
add_url_params,
|
||||
clean_headers,
|
||||
} from "$lib/ae_core/core__api_helpers";
|
||||
|
||||
|
||||
let ae_promises: key_val = {}; // Promise<any>;
|
||||
|
||||
|
||||
@@ -412,6 +418,8 @@ let export_obj = {
|
||||
delete_ae_obj_id__hosted_file: delete_ae_obj_id__hosted_file,
|
||||
db_save_ae_obj_li__hosted_file: db_save_ae_obj_li__hosted_file,
|
||||
db_update_ae_obj_id__hosted_file: db_update_ae_obj_id__hosted_file,
|
||||
add_url_params: add_url_params,
|
||||
clean_headers: clean_headers,
|
||||
handle_load_ae_obj_id__site_domain: handle_load_ae_obj_id__site_domain,
|
||||
handle_load_ae_obj_code__data_store: handle_load_ae_obj_code__data_store,
|
||||
load_ae_obj_id__activity_log: load_ae_obj_id__activity_log,
|
||||
|
||||
70
src/lib/ae_core/core__api_helpers.ts
Normal file
70
src/lib/ae_core/core__api_helpers.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
|
||||
|
||||
// Updated 2025-01-28
|
||||
export function add_url_params(
|
||||
{
|
||||
base_url = '',
|
||||
endpoint,
|
||||
params,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
base_url?: string,
|
||||
endpoint: string,
|
||||
params: key_val,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
// console.log(`*** add_url_params() ***`);
|
||||
console.log(`*** add_url_params() *** base_url=${base_url} endpoint=${endpoint}`, params);
|
||||
}
|
||||
|
||||
const url_obj = new URL(endpoint, base_url);
|
||||
|
||||
Object.keys(params).forEach(key => url_obj.searchParams.append(key, params[key]));
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('New URL:', url_obj.toString());
|
||||
}
|
||||
|
||||
return url_obj.toString();
|
||||
// return 'test';
|
||||
}
|
||||
|
||||
|
||||
// This is used to clean the header property names. Not underscores allowed in the header names.
|
||||
// Updated 2025-01-28
|
||||
export function clean_headers(
|
||||
{
|
||||
headers,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
headers: any,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** clean_headers() ***`);
|
||||
}
|
||||
|
||||
let headers_cleaned: key_val = {};
|
||||
for (const prop in headers) {
|
||||
let prop_cleaned = prop.replaceAll('_', '-');
|
||||
if (typeof headers[prop] != 'string') {
|
||||
headers[prop] = JSON.stringify(headers[prop]);
|
||||
}
|
||||
headers_cleaned[prop_cleaned] = headers[prop];
|
||||
if (log_lvl > 1) {
|
||||
console.log(`${prop_cleaned}: ${headers_cleaned[prop_cleaned]}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Object.keys(headers).forEach(key => {
|
||||
// if (headers[key]) {
|
||||
// headers_cleaned[key] = headers[key];
|
||||
// }
|
||||
// });
|
||||
|
||||
return headers_cleaned;
|
||||
}
|
||||
Reference in New Issue
Block a user