refactor: stabilize event file management and ID synchronization

- Updated 'process_ae_obj__event_file_props' to synchronize generic 'for_id' with specific object IDs (e.g., 'event_presenter_id').
- Standardized 'element_manage_event_file_li_direct.svelte' to use specific ID filtering.
- Fixed missing 'prevent_default' in 'ae_comp__hosted_files_clip_video.svelte'.
- Resolved miscellaneous type and syntax errors identified by svelte-check.
This commit is contained in:
Scott Idem
2026-02-06 16:41:44 -05:00
parent 2e8e4c7a7b
commit df9d3ad3d2
5 changed files with 575 additions and 166 deletions

View File

@@ -22,31 +22,66 @@ export async function load_ae_obj_id__event_file({
log_lvl?: number;
}): Promise<ae_EventFile | null> {
if (log_lvl) {
console.log(`*** load_ae_obj_id__event_file() *** [V3] id=${event_file_id} (SWR)`);
console.log(
`*** load_ae_obj_id__event_file() *** [V3] id=${event_file_id} (SWR)`
);
}
if (try_cache) {
try {
const cached = await db_events.file.get(event_file_id);
if (cached) {
_refresh_file_id_background({ api_cfg, event_file_id, view, try_cache, log_lvl: 0 });
_refresh_file_id_background({
api_cfg,
event_file_id,
view,
try_cache,
log_lvl: 0
});
return cached;
}
} catch (e) {}
}
return await _refresh_file_id_background({ api_cfg, event_file_id, view, try_cache, log_lvl });
return await _refresh_file_id_background({
api_cfg,
event_file_id,
view,
try_cache,
log_lvl
});
}
async function _refresh_file_id_background({ api_cfg, event_file_id, view, try_cache, log_lvl }: any) {
async function _refresh_file_id_background({
api_cfg,
event_file_id,
view,
try_cache,
log_lvl
}: any) {
if (typeof navigator !== 'undefined' && !navigator.onLine) return null;
try {
const result = await api.get_ae_obj_v3({ api_cfg, obj_type: 'event_file', obj_id: event_file_id, view, log_lvl });
const result = await api.get_ae_obj_v3({
api_cfg,
obj_type: 'event_file',
obj_id: event_file_id,
view,
log_lvl
});
if (result) {
const processed = await process_ae_obj__event_file_props({ obj_li: [result], log_lvl });
const processed = await process_ae_obj__event_file_props({
obj_li: [result],
log_lvl
});
const processed_obj = processed[0];
if (try_cache) {
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'file', obj_li: [processed_obj], properties_to_save, log_lvl });
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: [processed_obj],
properties_to_save,
log_lvl
});
}
return processed_obj;
}
@@ -84,30 +119,92 @@ export async function load_ae_obj_li__event_file({
log_lvl?: number;
}): Promise<ae_EventFile[]> {
if (log_lvl) {
console.log(`*** load_ae_obj_li__event_file() *** [V3] for=${for_obj_type}:${for_obj_id} (SWR)`);
console.log(
`*** load_ae_obj_li__event_file() *** [V3] for=${for_obj_type}:${for_obj_id} (SWR)`
);
}
if (try_cache) {
try {
const cached_li = await db_events.file.where('for_id').equals(for_obj_id).toArray();
const cached_li = await db_events.file
.where('for_id')
.equals(for_obj_id)
.toArray();
if (cached_li && cached_li.length > 0) {
_refresh_file_li_background({ api_cfg, for_obj_type, for_obj_id, enabled, hidden, view, limit, offset, order_by_li, try_cache, log_lvl: 0 });
_refresh_file_li_background({
api_cfg,
for_obj_type,
for_obj_id,
enabled,
hidden,
view,
limit,
offset,
order_by_li,
try_cache,
log_lvl: 0
});
return cached_li;
}
} catch (e) {}
}
return await _refresh_file_li_background({ api_cfg, for_obj_type, for_obj_id, enabled, hidden, view, limit, offset, order_by_li, try_cache, log_lvl });
return await _refresh_file_li_background({
api_cfg,
for_obj_type,
for_obj_id,
enabled,
hidden,
view,
limit,
offset,
order_by_li,
try_cache,
log_lvl
});
}
async function _refresh_file_li_background({ api_cfg, for_obj_type, for_obj_id, enabled, hidden, view, limit, offset, order_by_li, try_cache, log_lvl }: any) {
async function _refresh_file_li_background({
api_cfg,
for_obj_type,
for_obj_id,
enabled,
hidden,
view,
limit,
offset,
order_by_li,
try_cache,
log_lvl
}: any) {
if (typeof navigator !== 'undefined' && !navigator.onLine) return [];
try {
const result_li = await api.get_ae_obj_li_v3({ api_cfg, obj_type: 'event_file', for_obj_type, for_obj_id, enabled, hidden, view, limit, offset, order_by_li, log_lvl });
const result_li = await api.get_ae_obj_li_v3({
api_cfg,
obj_type: 'event_file',
for_obj_type,
for_obj_id,
enabled,
hidden,
view,
limit,
offset,
order_by_li,
log_lvl
});
if (result_li) {
const processed = await process_ae_obj__event_file_props({ obj_li: result_li, log_lvl });
const processed = await process_ae_obj__event_file_props({
obj_li: result_li,
log_lvl
});
if (try_cache) {
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'file', obj_li: processed, properties_to_save, log_lvl });
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed,
properties_to_save,
log_lvl
});
}
return processed;
}
@@ -165,7 +262,13 @@ export async function delete_ae_obj_id__event_file({
try_cache?: boolean;
log_lvl?: number;
}) {
const result = await api.delete_ae_obj_v3({ api_cfg, obj_type: 'event_file', obj_id: event_file_id, params: { ...params, delete_hosted_file: true, rm_orphan: true }, log_lvl });
const result = await api.delete_ae_obj_v3({
api_cfg,
obj_type: 'event_file',
obj_id: event_file_id,
params: { ...params, delete_hosted_file: true, rm_orphan: true },
log_lvl
});
if (try_cache) await db_events.file.delete(event_file_id);
return result;
}
@@ -185,27 +288,111 @@ export async function update_ae_obj__event_file({
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventFile | null> {
const result = await api.update_ae_obj_v3({ api_cfg, obj_type: 'event_file', obj_id: event_file_id, fields: data_kv, params, log_lvl });
const result = await api.update_ae_obj_v3({
api_cfg,
obj_type: 'event_file',
obj_id: event_file_id,
fields: data_kv,
params,
log_lvl
});
if (result && try_cache) {
const processed = await process_ae_obj__event_file_props({ obj_li: [result], log_lvl });
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'file', obj_li: processed, properties_to_save, log_lvl });
const processed = await process_ae_obj__event_file_props({
obj_li: [result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed,
properties_to_save,
log_lvl
});
}
return result;
}
export async function search__event_file({
api_cfg, event_id, qry_str = '', qry_created_on = null, qry_min_file_size = null, qry_file_purpose = null, enabled = 'enabled', hidden = 'not_hidden', view = 'default', limit = 25, offset = 0, order_by_li = [{ priority: 'DESC' }, { sort: 'DESC' }, { updated_on: 'DESC' }], try_cache = true, log_lvl = 0
api_cfg,
event_id,
qry_str = '',
qry_created_on = null,
qry_min_file_size = null,
qry_file_purpose = null,
enabled = 'enabled',
hidden = 'not_hidden',
view = 'default',
limit = 25,
offset = 0,
order_by_li = [
{ priority: 'DESC' },
{ sort: 'DESC' },
{ updated_on: 'DESC' }
],
try_cache = true,
log_lvl = 0
}: {
api_cfg: any; event_id: string; qry_str?: string; qry_created_on?: string | null; qry_min_file_size?: null | number; qry_file_purpose?: string | null; enabled?: 'enabled' | 'all' | 'not_enabled'; hidden?: 'hidden' | 'all' | 'not_hidden'; view?: string; limit?: number; offset?: number; order_by_li?: any; try_cache?: boolean; log_lvl?: number;
api_cfg: any;
event_id: string;
qry_str?: string;
qry_created_on?: string | null;
qry_min_file_size?: null | number;
qry_file_purpose?: string | null;
enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden';
view?: string;
limit?: number;
offset?: number;
order_by_li?: any;
try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventFile[]> {
const search_query: any = { q: qry_str, and: [{ field: 'event_id', op: 'eq', value: event_id }] };
if (qry_min_file_size) search_query.and.push({ field: 'hosted_file_size', op: 'gt', value: qry_min_file_size });
if (qry_created_on) search_query.and.push({ field: 'created_on', op: 'gte', value: qry_created_on });
if (qry_file_purpose) search_query.and.push({ field: 'file_purpose', op: 'eq', value: qry_file_purpose });
const result_li = await api.search_ae_obj_v3({ api_cfg, obj_type: 'event_file', search_query, enabled, hidden, view, order_by_li, limit, offset, log_lvl });
const search_query: any = {
q: qry_str,
and: [{ field: 'event_id', op: 'eq', value: event_id }]
};
if (qry_min_file_size)
search_query.and.push({
field: 'hosted_file_size',
op: 'gt',
value: qry_min_file_size
});
if (qry_created_on)
search_query.and.push({
field: 'created_on',
op: 'gte',
value: qry_created_on
});
if (qry_file_purpose)
search_query.and.push({
field: 'file_purpose',
op: 'eq',
value: qry_file_purpose
});
const result_li = await api.search_ae_obj_v3({
api_cfg,
obj_type: 'event_file',
search_query,
enabled,
hidden,
view,
order_by_li,
limit,
offset,
log_lvl
});
if (result_li && try_cache) {
const processed = await process_ae_obj__event_file_props({ obj_li: result_li, log_lvl });
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'file', obj_li: processed, properties_to_save, log_lvl });
const processed = await process_ae_obj__event_file_props({
obj_li: result_li,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed,
properties_to_save,
log_lvl
});
}
return result_li || [];
}
@@ -213,10 +400,71 @@ export async function search__event_file({
export const qry__event_file = search__event_file;
export const properties_to_save = [
'id', 'event_file_id', 'event_file_id_random', 'hosted_file_id', 'hosted_file_id_random', 'hash_sha256', 'for_type', 'for_id', 'for_id_random', 'event_id', 'event_id_random', 'event_session_id', 'event_presentation_id', 'event_presenter_id', 'event_location_id', 'filename', 'extension', 'open_in_os', 'lu_file_purpose_id', 'lu_event_file_purpose_name', 'file_purpose', 'enable', 'hide', 'priority', 'sort', 'group', 'notes', 'created_on', 'updated_on', 'tmp_sort_1', 'tmp_sort_2', 'filename_no_ext', 'filename_w_ext', 'hosted_file_content_type', 'file_size', 'hosted_file_size', 'event_location_code', 'event_location_name', 'event_session_code', 'event_session_type_code', 'event_session_name', 'event_session_start_datetime', 'event_session_end_datetime', 'event_presentation_code', 'event_presentation_type_code', 'event_presentation_name', 'event_presentation_start_datetime', 'event_presentation_end_datetime', 'event_presenter_given_name', 'event_presenter_family_name', 'event_presenter_full_name', 'event_presenter_email'
'id',
'event_file_id',
'event_file_id_random',
'hosted_file_id',
'hosted_file_id_random',
'hash_sha256',
'for_type',
'for_id',
'for_id_random',
'event_id',
'event_id_random',
'event_session_id',
'event_presentation_id',
'event_presenter_id',
'event_location_id',
'filename',
'extension',
'open_in_os',
'lu_file_purpose_id',
'lu_event_file_purpose_name',
'file_purpose',
'enable',
'hide',
'priority',
'sort',
'group',
'notes',
'created_on',
'updated_on',
'tmp_sort_1',
'tmp_sort_2',
'filename_no_ext',
'filename_w_ext',
'hosted_file_content_type',
'file_size',
'hosted_file_size',
'event_location_code',
'event_location_name',
'event_session_code',
'event_session_type_code',
'event_session_name',
'event_session_start_datetime',
'event_session_end_datetime',
'event_presentation_code',
'event_presentation_type_code',
'event_presentation_name',
'event_presentation_start_datetime',
'event_presentation_end_datetime',
'event_presenter_given_name',
'event_presenter_family_name',
'event_presenter_full_name',
'event_presenter_email'
];
async function _process_generic_props<T extends Record<string, any>>({ obj_li, obj_type, log_lvl = 0, specific_processor }: { obj_li: T[]; obj_type: string; log_lvl?: number; specific_processor?: (obj: T) => Promise<T> | T; }): Promise<T[]> {
async function _process_generic_props<T extends Record<string, any>>({
obj_li,
obj_type,
log_lvl = 0,
specific_processor
}: {
obj_li: T[];
obj_type: string;
log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> {
if (!obj_li || obj_li.length === 0) return [];
const processed_obj_li: T[] = [];
for (const original_obj of obj_li) {
@@ -228,20 +476,53 @@ async function _process_generic_props<T extends Record<string, any>>({ obj_li, o
}
}
const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) (processed_obj as any).id = processed_obj[randomIdKey];
if (processed_obj[randomIdKey])
(processed_obj as any).id = processed_obj[randomIdKey];
const group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0';
const updated = processed_obj.updated_on ?? processed_obj.created_on;
const name = processed_obj.name ?? '';
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
if (specific_processor) processed_obj = await Promise.resolve(specific_processor(processed_obj));
(processed_obj as any).tmp_sort_1 =
`${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 =
`${group}_${priority}_${sort}_${name}_${updated}`;
if (specific_processor)
processed_obj = await Promise.resolve(
specific_processor(processed_obj)
);
processed_obj_li.push(processed_obj as T);
}
return processed_obj_li;
}
export async function process_ae_obj__event_file_props({ obj_li, log_lvl = 0 }: { obj_li: any[]; log_lvl?: number; }) {
return _process_generic_props({ obj_li, obj_type: 'event_file', log_lvl });
}
export async function process_ae_obj__event_file_props({
obj_li,
log_lvl = 0
}: {
obj_li: any[];
log_lvl?: number;
}) {
return _process_generic_props({
obj_li,
obj_type: 'event_file',
log_lvl,
specific_processor: (obj) => {
// SYNC: Ensure for_id matches the specific object ID it was linked to
if (obj.for_type && !obj.for_id) {
const specific_id_key = `${obj.for_type}_id`;
if (obj[specific_id_key]) {
obj.for_id = obj[specific_id_key];
}
}
// SYNC: Ensure specific object ID is populated if for_id is present
if (obj.for_type && obj.for_id) {
const specific_id_key = `${obj.for_type}_id`;
if (!obj[specific_id_key]) {
obj[specific_id_key] = obj.for_id;
}
}
return obj;
}
});
}