Initialized Activity Log IndexedDB infrastructure and refactored Jitsi reports.
Added 'activity_log' table to Dexie 'ae_core_db' (v4) to support local caching of tracking data. Implemented 'process_ae_obj__activity_log_props' with robust timestamp fallbacks. Refactored 'qry__jitsi_report' to follow the Frontier module pattern, ensuring consistent V3 search and local cache synchronization.
This commit is contained in:
@@ -1,61 +1,91 @@
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
import { api } from '$lib/api/api';
|
||||
import { process_ae_obj__activity_log_props, properties_to_save } from '$lib/ae_core/ae_core__activity_log';
|
||||
import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
|
||||
import { db_core } from '$lib/ae_core/db_core';
|
||||
|
||||
/**
|
||||
* @description Queries all Jitsi-related activity logs and processes them into a structured report,
|
||||
* grouped by meeting ID.
|
||||
* @param api_cfg The API configuration object.
|
||||
* @param account_id The account ID to query against.
|
||||
* @param enabled Filter by enabled status.
|
||||
* @param hidden Filter by hidden status.
|
||||
* @param limit Maximum number of logs to fetch.
|
||||
* @param try_cache Whether to sync the raw logs to the local activity_log table.
|
||||
* @param log_lvl The logging level.
|
||||
* @returns A structured array of meeting report objects.
|
||||
*/
|
||||
export async function load_jitsi_report({
|
||||
export async function qry__jitsi_report({
|
||||
api_cfg,
|
||||
account_id,
|
||||
enabled = 'all',
|
||||
hidden = 'all',
|
||||
limit = 500,
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
account_id: string;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
||||
limit?: number;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) console.log('*** load_jitsi_report() ***');
|
||||
if (log_lvl) console.log('*** qry__jitsi_report() ***');
|
||||
|
||||
// Step 1: Query all relevant activity logs from the API.
|
||||
const params_json = {
|
||||
or_qry: [
|
||||
{
|
||||
field: 'name',
|
||||
operator: '=',
|
||||
value: 'jitsi_meeting_stats_update'
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
operator: '=',
|
||||
value: 'jitsi_meeting_event'
|
||||
}
|
||||
const search_query = {
|
||||
or: [
|
||||
{ field: 'name', op: 'eq', value: 'jitsi_meeting_stats_update' },
|
||||
{ field: 'name', op: 'eq', value: 'jitsi_meeting_event' },
|
||||
{ field: 'name', op: 'eq', value: 'jitsi_meeting_stats' }
|
||||
],
|
||||
and: [
|
||||
{ field: 'account_id_random', op: 'eq', value: account_id }
|
||||
]
|
||||
};
|
||||
|
||||
const flat_log_list = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
const result = await api.search_ae_obj_v3({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
for_obj_type: 'account',
|
||||
for_obj_id: account_id,
|
||||
// use_alt_tbl: true,
|
||||
// use_alt_mdl: true,
|
||||
enabled: 'all',
|
||||
hidden: 'all',
|
||||
limit: 500, // Fetch a reasonable number of recent logs
|
||||
params_json: params_json,
|
||||
search_query,
|
||||
headers: { 'x-account-id': account_id },
|
||||
log_lvl: 2
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
|
||||
// Handle potential V3 API envelope
|
||||
let flat_log_list: any[] = [];
|
||||
if (Array.isArray(result)) {
|
||||
flat_log_list = result;
|
||||
} else if (result && typeof result === 'object' && Array.isArray((result as any).data)) {
|
||||
flat_log_list = (result as any).data;
|
||||
}
|
||||
|
||||
if (!flat_log_list || !Array.isArray(flat_log_list) || flat_log_list.length === 0) {
|
||||
if (log_lvl) console.log('No Jitsi activity logs found or error occurred.');
|
||||
return [];
|
||||
}
|
||||
|
||||
// Frontier Standard: Process and Save to local cache
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__activity_log_props({
|
||||
obj_li: flat_log_list,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_core,
|
||||
table_name: 'activity_log',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save: properties_to_save,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
// Step 2: Process the flat list into a structured report.
|
||||
const meetings = new Map<string, any>();
|
||||
|
||||
@@ -112,3 +142,5 @@ export async function load_jitsi_report({
|
||||
|
||||
return final_report;
|
||||
}
|
||||
|
||||
export const load_jitsi_report = qry__jitsi_report;
|
||||
|
||||
Reference in New Issue
Block a user