Fix IDAA Recovery Meetings loading and optimize API retry logic

- Implemented workaround for 'conference' field search restriction in V3 by using local filtering
- Optimized post_object to stop retrying on 4xx client errors (400, 401, 403)
- Migrated Archives and Event/Recovery Meeting modules to Aether API CRUD V3
- Added editable_fields definitions for Archive and Archive Content objects
This commit is contained in:
Scott Idem
2026-01-06 17:22:19 -05:00
parent e1f97d5154
commit bfa1943889
7 changed files with 471 additions and 1769 deletions

View File

@@ -6,26 +6,18 @@ import { db_archives } from '$lib/ae_archives/db_archives';
const ae_promises: key_val = {};
// TESTING NOTE: I changed these to all use async and await. Not sure if this helps or hurts things. Mainly this is related to the Dexie DB changes. 2024-11-08
// Updated 2024-09-25
// Updated 2026-01-06
export async function load_ae_obj_id__archive_content({
api_cfg,
archive_content_id,
// enabled = 'enabled',
// hidden = 'not_hidden',
// limit = 99,
// offset = 0,
view = 'default',
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
archive_content_id: string;
// enabled?: "enabled" | "all" | "not_enabled" | undefined,
// hidden?: "hidden" | "all" | "not_hidden" | undefined,
// limit?: number,
// offset?: number,
view?: string;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
@@ -37,30 +29,21 @@ export async function load_ae_obj_id__archive_content({
}
ae_promises.load__archive_content_obj = await api
.get_ae_obj_id_crud({
.get_ae_obj_v3({
api_cfg: api_cfg,
obj_type: 'archive_content',
obj_id: archive_content_id,
use_alt_table: false,
use_alt_base: false,
params: params,
view,
params,
log_lvl: log_lvl
})
.then(async function (archive_content_obj_get_result) {
if (archive_content_obj_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__archive_content_props({
obj_li: [archive_content_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'content',
@@ -68,16 +51,6 @@ export async function load_ae_obj_id__archive_content({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list
// await db_save_ae_obj_li__archive_content({
// obj_type: 'archive_content',
// obj_li: [archive_content_obj_get_result]
// });
}
return archive_content_obj_get_result;
} else {
@@ -92,13 +65,14 @@ export async function load_ae_obj_id__archive_content({
return ae_promises.load__archive_content_obj;
}
// Updated 2024-11-20
// Updated 2026-01-06
export async function load_ae_obj_li__archive_content({
api_cfg,
for_obj_type = 'archive',
for_obj_id,
enabled = 'enabled',
hidden = 'not_hidden',
view = 'default',
limit = 99,
offset = 0,
order_by_li = {
@@ -118,9 +92,10 @@ export async function load_ae_obj_li__archive_content({
for_obj_id: string;
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
view?: string;
limit?: number;
offset?: number;
order_by_li?: key_val;
order_by_li?: Record<string, 'ASC' | 'DESC'>;
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
@@ -131,43 +106,27 @@ export async function load_ae_obj_li__archive_content({
);
}
const params_json: key_val = {};
// console('params_json:', params_json);
ae_promises.load__archive_content_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
.get_ae_obj_li_v3({
api_cfg: api_cfg,
obj_type: 'archive_content',
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: false,
use_alt_mdl: false,
use_alt_exp: false,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
for_obj_type,
for_obj_id,
enabled,
hidden,
view,
limit,
offset,
order_by_li,
log_lvl: log_lvl
})
.then(async function (archive_content_obj_li_get_result) {
if (archive_content_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__archive_content_props({
obj_li: archive_content_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'content',
@@ -175,34 +134,17 @@ export async function load_ae_obj_li__archive_content({
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__archive_content({
// obj_type: 'archive_content', obj_li: archive_content_obj_li_get_result
// });
}
return archive_content_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log(
'ae_promises.load__archive_content_obj_li:',
ae_promises.load__archive_content_obj_li
);
}
return ae_promises.load__archive_content_obj_li;
}
// Updated 2025-06-23
// Updated 2026-01-06
export async function create_ae_obj__archive_content({
api_cfg,
archive_id,
@@ -227,78 +169,46 @@ export async function create_ae_obj__archive_content({
return false;
}
ae_promises.create__archive_content = await api
.create_ae_obj_crud({
api_cfg: api_cfg,
obj_type: 'archive_content',
fields: {
archive_id_random: archive_id,
...data_kv
},
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
const result = await api.create_ae_obj_v3({
api_cfg,
obj_type: 'archive_content',
fields: {
archive_id_random: archive_id,
...data_kv
},
params,
log_lvl
});
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__archive_content_props({
obj_li: [result],
log_lvl: log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'content',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
})
.then(async function (archive_content_obj_create_result) {
if (archive_content_obj_create_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__archive_content_props({
obj_li: [archive_content_obj_create_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'content',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__archive_content(
// {
// obj_type: 'archive_content',
// obj_li: [archive_content_obj_create_result]
// });
}
return archive_content_obj_create_result;
} else {
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log('ae_promises.create__archive_content:', ae_promises.create__archive_content);
}
return ae_promises.create__archive_content;
return result;
}
// Updated 2024-11-08
// Updated 2026-01-06
export async function delete_ae_obj_id__archive_content({
api_cfg,
archive_content_id,
method = 'delete', // 'delete', 'disable', 'hide'
method = 'delete',
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any;
archive_content_id: string;
method?: string;
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
params?: key_val;
try_cache?: boolean;
log_lvl?: number;
@@ -309,41 +219,23 @@ export async function delete_ae_obj_id__archive_content({
);
}
ae_promises.delete__archive_content_obj = await api
.delete_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'archive_content',
obj_id: archive_content_id,
key: api_cfg.api_crud_super_key,
params: params,
method: method,
log_lvl: log_lvl
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {
if (try_cache) {
if (log_lvl) {
console.log(
`Attempting to remove IDB entry for archive_content_id=${archive_content_id}`
);
}
db_archives.content.delete(archive_content_id); // Delete from the DB no matter what.
}
});
const result = await api.delete_ae_obj_v3({
api_cfg,
obj_type: 'archive_content',
obj_id: archive_content_id,
method,
params,
log_lvl
});
if (log_lvl) {
console.log(
'ae_promises.delete__archive_content_obj:',
ae_promises.delete__archive_content_obj
);
if (try_cache) {
await db_archives.content.delete(archive_content_id);
}
return ae_promises.delete__archive_content_obj;
return result;
}
// Updated 2025-06-23
// Updated 2026-01-06
export async function update_ae_obj__archive_content({
api_cfg,
archive_content_id,
@@ -366,95 +258,56 @@ export async function update_ae_obj__archive_content({
);
}
// Perform the API update
const result = await api.update_ae_obj_id_crud({
api_cfg: api_cfg,
const result = await api.update_ae_obj_v3({
api_cfg,
obj_type: 'archive_content',
obj_id: archive_content_id,
fields: data_kv,
key: api_cfg.api_crud_super_key,
params: params,
return_obj: true,
log_lvl: log_lvl
params,
log_lvl
});
// Handle the result
if (result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__archive_content_props({
obj_li: [result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'content',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// await db_save_ae_obj_li__archive_content({
// obj_type: 'archive_content',
// obj_li: [result],
// log_lvl: log_lvl,
// });
}
return result;
} else {
console.error('Failed to update archive content.');
return null;
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__archive_content_props({
obj_li: [result],
log_lvl: log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_archives,
table_name: 'content',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
return result;
}
// Updated 2025-06-04
export const properties_to_save = [
'id',
'archive_content_id',
// 'archive_content_id_random',
'archive_id',
// 'archive_id_random',
'archive_content_type',
'name',
'description',
'content_html',
'content_json',
'url',
'url_text',
'hosted_file_id',
'hosted_file_id_random',
'file_path',
'filename',
'file_extension',
'original_datetime',
'original_timezone',
'original_location',
'original_url',
'original_url_text',
'enable_for_public',
'cfg_json',
'enable',
'hide',
'priority',
@@ -463,24 +316,13 @@ export const properties_to_save = [
'notes',
'created_on',
'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1',
'tmp_sort_2',
// 'tmp_sort_a',
// 'tmp_sort_b',
// From SQL view
'archive_code',
'archive_name',
'hash_sha256'
];
/**
* NON-EXPORTED LOCAL HELPER
* Processes a list of Aether objects by applying common and specific transformations.
*/
async function _process_generic_props<T extends Record<string, any>>({
obj_li,
obj_type,
@@ -492,39 +334,24 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> {
if (log_lvl > 0) {
console.log(
`*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***`
);
}
if (!obj_li || obj_li.length === 0) {
if (log_lvl > 0) console.log('No objects to process.');
return [];
}
if (!obj_li || obj_li.length === 0) return [];
const processed_obj_li: T[] = [];
for (const original_obj of obj_li) {
let processed_obj = { ...original_obj };
// --- Common Transformations ---
// 1. Standardize ID and other '_random' fields
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
for (const key in processed_obj) {
if (key.endsWith('_random')) {
const newKey = key.slice(0, -7); // Remove '_random' suffix
processed_obj[newKey] = processed_obj[key];
const newKey = key.slice(0, -7);
(processed_obj as any)[newKey] = processed_obj[key];
}
}
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) {
(processed_obj as any).id = processed_obj[randomIdKey];
}
// 2. Create common computed properties for client-side sorting.
const group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0';
@@ -534,7 +361,6 @@ async function _process_generic_props<T extends Record<string, any>>({
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj));
}
@@ -558,7 +384,6 @@ export async function process_ae_obj__archive_content_props({
obj_type: 'archive_content',
log_lvl,
specific_processor: (obj) => {
// Archive content-specific computed sort fields, overriding generic ones if needed
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.original_datetime ?? ''}`;
@@ -574,4 +399,4 @@ export async function process_ae_obj__archive_content_props({
return obj;
}
});
}
}