General clean up the _random appends. About to work on a new Hosted File Download Svelte component.
This commit is contained in:
@@ -565,215 +565,213 @@ export async function update_ae_obj__journal_entry({
|
||||
}
|
||||
}
|
||||
|
||||
// This function will loop through the journal_entry_obj_li and save each one to the DB.
|
||||
// Updated 2025-05-09
|
||||
export async function db_save_ae_obj_li__journal_entry({
|
||||
obj_type,
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_type: string;
|
||||
obj_li: any;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
// log_lvl = 1;
|
||||
if (log_lvl) {
|
||||
console.log(`*** db_save_ae_obj_li__journal_entry() *** obj_type=${obj_type}`, obj_li);
|
||||
}
|
||||
// // This function will loop through the journal_entry_obj_li and save each one to the DB.
|
||||
// // Updated 2025-05-09
|
||||
// export async function db_save_ae_obj_li__journal_entry({
|
||||
// obj_type,
|
||||
// obj_li,
|
||||
// log_lvl = 0
|
||||
// }: {
|
||||
// obj_type: string;
|
||||
// obj_li: any;
|
||||
// log_lvl?: number;
|
||||
// }) {
|
||||
// // log_lvl = 1;
|
||||
// if (log_lvl) {
|
||||
// console.log(`*** db_save_ae_obj_li__journal_entry() *** obj_type=${obj_type}`, obj_li);
|
||||
// }
|
||||
|
||||
if (obj_li && obj_li.length) {
|
||||
// let obj_li_id = obj_li.map((obj: any) => obj.journal_entry_id_random);
|
||||
const obj_li_id: string[] = [];
|
||||
// if (obj_li && obj_li.length) {
|
||||
// // let obj_li_id = obj_li.map((obj: any) => obj.journal_entry_id_random);
|
||||
// const obj_li_id: string[] = [];
|
||||
|
||||
for (const obj of obj_li) {
|
||||
// obj_li.forEach(async function (obj: any) {
|
||||
if (log_lvl) {
|
||||
console.log(`Processing ae_obj ${obj_type}:`, obj);
|
||||
}
|
||||
// for (const obj of obj_li) {
|
||||
// // obj_li.forEach(async function (obj: any) {
|
||||
// if (log_lvl) {
|
||||
// console.log(`Processing ae_obj ${obj_type}:`, obj);
|
||||
// }
|
||||
|
||||
let content = obj.content ?? '';
|
||||
// remove the most common zerowidth characters from the start of the file
|
||||
let content_cleaned: null | string = null;
|
||||
let content_md_html: null | string = null; // await marked.parse(content_cleaned ?? '') ?? null;
|
||||
// let content_md_html_alt: null|string = await marked.parse(content_cleaned ?? '', { gfm: false }) ?? null;
|
||||
// let content = obj.content ?? '';
|
||||
// // remove the most common zerowidth characters from the start of the file
|
||||
// let content_cleaned: null | string = null;
|
||||
// let content_md_html: null | string = null; // await marked.parse(content_cleaned ?? '') ?? null;
|
||||
// // let content_md_html_alt: null|string = await marked.parse(content_cleaned ?? '', { gfm: false }) ?? null;
|
||||
|
||||
if (obj.content_encrypted) {
|
||||
// In theory "content" should be null if "content_encrypted" has a value.
|
||||
content = null; // obj.content_encrypted;
|
||||
content_cleaned = null;
|
||||
content_md_html = null;
|
||||
} else {
|
||||
content_cleaned = content.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/, '');
|
||||
content_md_html = (await marked.parse(content_cleaned ?? '')) ?? null;
|
||||
}
|
||||
// if (obj.content_encrypted) {
|
||||
// // In theory "content" should be null if "content_encrypted" has a value.
|
||||
// content = null; // obj.content_encrypted;
|
||||
// content_cleaned = null;
|
||||
// content_md_html = null;
|
||||
// } else {
|
||||
// content_cleaned = content.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/, '');
|
||||
// content_md_html = (await marked.parse(content_cleaned ?? '')) ?? null;
|
||||
// }
|
||||
|
||||
let history = obj.history ?? '';
|
||||
let history_cleaned: null | string = null;
|
||||
let history_md_html: null | string = null; // await marked.parse(history_cleaned ?? '') ?? null;
|
||||
// let history = obj.history ?? '';
|
||||
// let history_cleaned: null | string = null;
|
||||
// let history_md_html: null | string = null; // await marked.parse(history_cleaned ?? '') ?? null;
|
||||
|
||||
if (obj.history_encrypted) {
|
||||
// In theory "history" should be null if "history_encrypted" has a value.
|
||||
history = null; // obj.history_encrypted;
|
||||
history_cleaned = null;
|
||||
history_md_html = null;
|
||||
} else {
|
||||
history_cleaned = history.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/, '');
|
||||
history_md_html = (await marked.parse(history_cleaned ?? '')) ?? null;
|
||||
}
|
||||
// if (obj.history_encrypted) {
|
||||
// // In theory "history" should be null if "history_encrypted" has a value.
|
||||
// history = null; // obj.history_encrypted;
|
||||
// history_cleaned = null;
|
||||
// history_md_html = null;
|
||||
// } else {
|
||||
// history_cleaned = history.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/, '');
|
||||
// history_md_html = (await marked.parse(history_cleaned ?? '')) ?? null;
|
||||
// }
|
||||
|
||||
const obj_record = {
|
||||
id: obj.journal_entry_id_random,
|
||||
journal_entry_id: obj.journal_entry_id_random,
|
||||
journal_entry_id_random: obj.journal_entry_id_random,
|
||||
// const obj_record = {
|
||||
// id: obj.journal_entry_id,
|
||||
// journal_entry_id: obj.journal_entry_id,
|
||||
|
||||
journal_id: obj.journal_id_random,
|
||||
journal_id_random: obj.journal_id_random,
|
||||
// journal_id: obj.journal_id,
|
||||
|
||||
code: obj.code,
|
||||
// code: obj.code,
|
||||
|
||||
for_type: obj.for_type,
|
||||
for_id: obj.for_id,
|
||||
// for_type: obj.for_type,
|
||||
// for_id: obj.for_id,
|
||||
|
||||
journal_entry_type: obj.journal_entry_type,
|
||||
// journal_entry_type: obj.journal_entry_type,
|
||||
|
||||
person_id: obj.person_id_random,
|
||||
// person_id: obj.person_id,
|
||||
|
||||
template: obj.template ?? null, // Allow for a template to be used, otherwise null
|
||||
// template: obj.template ?? null, // Allow for a template to be used, otherwise null
|
||||
|
||||
activity_code: obj.activity_code,
|
||||
category_code: obj.category_code,
|
||||
type_code: obj.type_code,
|
||||
topic_code: obj.topic_code,
|
||||
tags: obj.tags,
|
||||
// activity_code: obj.activity_code,
|
||||
// category_code: obj.category_code,
|
||||
// type_code: obj.type_code,
|
||||
// topic_code: obj.topic_code,
|
||||
// tags: obj.tags,
|
||||
|
||||
public: obj.public,
|
||||
private: obj.private,
|
||||
personal: obj.personal,
|
||||
professional: obj.professional,
|
||||
// public: obj.public,
|
||||
// private: obj.private,
|
||||
// personal: obj.personal,
|
||||
// professional: obj.professional,
|
||||
|
||||
name: obj.name,
|
||||
short_name: obj.short_name ?? null,
|
||||
summary: obj.summary,
|
||||
outline: obj.outline,
|
||||
// description: obj.description,
|
||||
// name: obj.name,
|
||||
// short_name: obj.short_name ?? null,
|
||||
// summary: obj.summary,
|
||||
// outline: obj.outline,
|
||||
// // description: obj.description,
|
||||
|
||||
content: obj.content,
|
||||
content_md_html: content_md_html ?? undefined,
|
||||
// content_md_html_alt: content_md_html_alt,
|
||||
content_html: obj.content_html,
|
||||
content_json: obj.content_json,
|
||||
content_encrypted: obj.content_encrypted,
|
||||
// content: obj.content,
|
||||
// content_md_html: content_md_html ?? undefined,
|
||||
// // content_md_html_alt: content_md_html_alt,
|
||||
// content_html: obj.content_html,
|
||||
// content_json: obj.content_json,
|
||||
// content_encrypted: obj.content_encrypted,
|
||||
|
||||
history: obj.history,
|
||||
history_md_html: history_md_html ?? undefined,
|
||||
history_encrypted: obj.history_encrypted,
|
||||
// history: obj.history,
|
||||
// history_md_html: history_md_html ?? undefined,
|
||||
// history_encrypted: obj.history_encrypted,
|
||||
|
||||
passcode_hash: obj.passcode_hash,
|
||||
// passcode_hash: obj.passcode_hash,
|
||||
|
||||
// url: obj.url,
|
||||
// url_text: obj.url_text,
|
||||
// // url: obj.url,
|
||||
// // url_text: obj.url_text,
|
||||
|
||||
// hosted_file_id: obj.hosted_file_id_random,
|
||||
// // hosted_file_id: obj.hosted_file_id,
|
||||
|
||||
// file_path: obj.file_path,
|
||||
// // file_path: obj.file_path,
|
||||
|
||||
// filename: obj.filename,
|
||||
// file_extension: obj.file_extension,
|
||||
// // filename: obj.filename,
|
||||
// // file_extension: obj.file_extension,
|
||||
|
||||
// start_datetime: obj.start_datetime,
|
||||
// end_datetime: obj.end_datetime,
|
||||
// timezone: obj.timezone,
|
||||
// // start_datetime: obj.start_datetime,
|
||||
// // end_datetime: obj.end_datetime,
|
||||
// // timezone: obj.timezone,
|
||||
|
||||
// original_datetime: obj.original_datetime,
|
||||
// original_timezone: obj.original_timezone,
|
||||
// original_location: obj.original_location,
|
||||
// original_url: obj.original_url,
|
||||
// original_url_text: obj.original_url_text,
|
||||
// // original_datetime: obj.original_datetime,
|
||||
// // original_timezone: obj.original_timezone,
|
||||
// // original_location: obj.original_location,
|
||||
// // original_url: obj.original_url,
|
||||
// // original_url_text: obj.original_url_text,
|
||||
|
||||
// enable_for_public: obj.enable_for_public,
|
||||
// // enable_for_public: obj.enable_for_public,
|
||||
|
||||
alert: obj.alert,
|
||||
alert_msg: obj.alert_msg,
|
||||
// alert: obj.alert,
|
||||
// alert_msg: obj.alert_msg,
|
||||
|
||||
// cfg_json: obj.cfg_json ?? {},
|
||||
data_json: obj.data_json ?? {},
|
||||
// // cfg_json: obj.cfg_json ?? {},
|
||||
// data_json: obj.data_json ?? {},
|
||||
|
||||
// This only allows for basic access to the data.
|
||||
// passcode_read: obj.passcode_read, // For LLM (AI) generated summary...???
|
||||
// passcode_read_expire: obj.passcode_read_expire,
|
||||
// passcode_write: obj.passcode_write,
|
||||
// passcode_write_expire: obj.passcode_write_expire,
|
||||
// // This only allows for basic access to the data.
|
||||
// // passcode_read: obj.passcode_read, // For LLM (AI) generated summary...???
|
||||
// // passcode_read_expire: obj.passcode_read_expire,
|
||||
// // passcode_write: obj.passcode_write,
|
||||
// // passcode_write_expire: obj.passcode_write_expire,
|
||||
|
||||
enable: obj.enable,
|
||||
hide: obj.hide,
|
||||
archive: obj.archive,
|
||||
archive_on: obj.archive_on,
|
||||
priority: obj.priority,
|
||||
sort: obj.sort,
|
||||
group: obj.group,
|
||||
notes: obj.notes,
|
||||
created_on: obj.created_on,
|
||||
updated_on: obj.updated_on,
|
||||
// enable: obj.enable,
|
||||
// hide: obj.hide,
|
||||
// archive: obj.archive,
|
||||
// archive_on: obj.archive_on,
|
||||
// priority: obj.priority,
|
||||
// sort: obj.sort,
|
||||
// group: obj.group,
|
||||
// notes: obj.notes,
|
||||
// created_on: obj.created_on,
|
||||
// updated_on: obj.updated_on,
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
tmp_sort_1: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on}_${obj.created_on}`,
|
||||
tmp_sort_2: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on ?? obj.created_on}`,
|
||||
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
// // Generated fields for sorting locally only
|
||||
// tmp_sort_1: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on}_${obj.created_on}`,
|
||||
// tmp_sort_2: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on ?? obj.created_on}`,
|
||||
// // tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// // tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
// // Generated fields for sorting locally only
|
||||
// // tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// // tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
|
||||
// From SQL view
|
||||
journal_code: obj.journal_code,
|
||||
journal_name: obj.journal_name
|
||||
// // From SQL view
|
||||
// journal_code: obj.journal_code,
|
||||
// journal_name: obj.journal_name
|
||||
|
||||
// A key value list of the others
|
||||
// journal_other_kv: obj.journal_other_kv,
|
||||
// journal_other_li: obj.journal_other_li,
|
||||
};
|
||||
// // A key value list of the others
|
||||
// // journal_other_kv: obj.journal_other_kv,
|
||||
// // journal_other_li: obj.journal_other_li,
|
||||
// };
|
||||
|
||||
let id_random = null;
|
||||
// let id_random = null;
|
||||
|
||||
try {
|
||||
id_random = await db_journals.journal_entry.update(obj_record.id, obj_record);
|
||||
} catch (error) {
|
||||
console.log(`Error: Failed to update ${obj_record.id}: ${error}`);
|
||||
}
|
||||
if (!id_random) {
|
||||
if (log_lvl) {
|
||||
console.log(`Failed to update record with ID: ${obj_record.id}. Trying put...`);
|
||||
}
|
||||
try {
|
||||
id_random = await db_journals.journal_entry.put(obj_record);
|
||||
} catch (error) {
|
||||
console.log(`Error: Failed to put ${obj.journal_entry_id_random}: ${error}`);
|
||||
}
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(`Updated record with ID: ${obj_record.id}`);
|
||||
}
|
||||
obj_li_id.push(obj_record.id);
|
||||
}
|
||||
if (!id_random) {
|
||||
console.log(`Failed to save record with ID: ${obj_record.id}`);
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(`Saved record with ID: ${obj_record.id}`);
|
||||
}
|
||||
}
|
||||
// });
|
||||
}
|
||||
// try {
|
||||
// id_random = await db_journals.journal_entry.update(obj_record.id, obj_record);
|
||||
// } catch (error) {
|
||||
// console.log(`Error: Failed to update ${obj_record.id}: ${error}`);
|
||||
// }
|
||||
// if (!id_random) {
|
||||
// if (log_lvl) {
|
||||
// console.log(`Failed to update record with ID: ${obj_record.id}. Trying put...`);
|
||||
// }
|
||||
// try {
|
||||
// id_random = await db_journals.journal_entry.put(obj_record);
|
||||
// } catch (error) {
|
||||
// console.log(`Error: Failed to put ${obj.journal_entry_id_random}: ${error}`);
|
||||
// }
|
||||
// } else {
|
||||
// if (log_lvl) {
|
||||
// console.log(`Updated record with ID: ${obj_record.id}`);
|
||||
// }
|
||||
// obj_li_id.push(obj_record.id);
|
||||
// }
|
||||
// if (!id_random) {
|
||||
// console.log(`Failed to save record with ID: ${obj_record.id}`);
|
||||
// } else {
|
||||
// if (log_lvl) {
|
||||
// console.log(`Saved record with ID: ${obj_record.id}`);
|
||||
// }
|
||||
// }
|
||||
// // });
|
||||
// }
|
||||
|
||||
return obj_li_id;
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log('No objects to save.');
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
// return obj_li_id;
|
||||
// } else {
|
||||
// if (log_lvl) {
|
||||
// console.log('No objects to save.');
|
||||
// }
|
||||
// return [];
|
||||
// }
|
||||
// }
|
||||
|
||||
// Updated 2025-05-09
|
||||
const properties_to_save = [
|
||||
|
||||
Reference in New Issue
Block a user