From bbf9411213d4422ad8a95a6835f3bc34e174f29e Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 11 Sep 2025 15:44:07 -0400 Subject: [PATCH] More work on encryption related content and history. --- .../ae_comp__journal_entry_obj_id_view.svelte | 132 +++++++++++------- 1 file changed, 81 insertions(+), 51 deletions(-) diff --git a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte index ece8eb5d..a6158533 100644 --- a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte +++ b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte @@ -350,7 +350,7 @@ async function update_journal_entry() { let { left_over_string, cut_out_string } = handle_cut_string(data_kv.content); data_kv.content = left_over_string; - console.log('TEST: data_kv.content:', data_kv.content); + // console.log('TEST: data_kv.content:', data_kv.content); data_kv.content_encrypted = null; @@ -362,14 +362,21 @@ async function update_journal_entry() { // } if (cut_out_string) { - let current_timestamp = new Date().toISOString(); - cut_out_string = `## Cut on ${current_timestamp}\n` + cut_out_string; + // console.log(`${ae_util.iso_datetime_formatter(new Date().toISOString(), 'datetime_iso_12_no_seconds')}`); + let cut_prefix = `# Cut on ${ae_util.iso_datetime_formatter(new Date().toISOString(), 'datetime_iso_12_no_seconds')}\n`; + // let cut_prefix = `# Cut on ${new Date().toISOString()}\n`; + // let current_timestamp = new Date().toISOString(); + // cut_out_string = `## Cut on ${current_timestamp}\n` + cut_out_string; + cut_out_string = cut_prefix + cut_out_string; + // console.log(`TEST: Cut out string with prefix: "${cut_out_string}"`); } - if (tmp_entry_obj?.history) { - data_kv.history = tmp_entry_obj?.history ?? '' + '\n\n' + cut_out_string; - } else { - data_kv.history = cut_out_string; + if (tmp_entry_obj?.history?.length && cut_out_string) { + // console.log(`HERE 1`); + data_kv.history = tmp_entry_obj?.history + '\n' + cut_out_string + '\n'; + } else if (cut_out_string) { + // console.log(`HERE 2`); + data_kv.history = cut_out_string + '\n'; } console.log('TEST: data_kv.history:', data_kv.history); @@ -395,14 +402,25 @@ async function update_journal_entry() { if (log_lvl) { console.log('TEST: Decrypting the history before saving it...'); } - decrypted_history = await ae_util.decrypt_wrapper(tmp_entry_obj?.history_encrypted, decrypt_key); - - if (tmp_entry_obj?.history) { - data_kv.history = tmp_entry_obj?.history ?? '' + '\n' + decrypted_history + '\n' + cut_out_string; - } else { - data_kv.history = decrypted_history + '\n' + cut_out_string; + if (tmp_entry_obj?.history_encrypted) { + decrypted_history = await ae_util.decrypt_wrapper(tmp_entry_obj?.history_encrypted, decrypt_key); + tmp_entry_obj.history = decrypted_history; } - // data_kv.history = tmp_entry_obj?.history + '\n' + decrypted_history + '\n' + cut_out_string; + + if (cut_out_string) { + let cut_prefix = `# Cut on ${ae_util.iso_datetime_formatter(new Date().toISOString(), 'datetime_iso_12_no_seconds')}\n`; + cut_out_string = cut_prefix + cut_out_string; + console.log(`TEST: Cut out string with prefix: "${cut_out_string}"`); + } + + if (tmp_entry_obj?.history?.length && cut_out_string) { + console.log(`HERE 1`); + data_kv.history = tmp_entry_obj?.history + '\n' + cut_out_string + '\n'; + } else { + console.log(`HERE 2`); + data_kv.history = cut_out_string + '\n'; + } + console.log('TEST: data_kv.history:', data_kv.history); if (log_lvl) { console.log('TEST: Encrypting the history before saving it...'); @@ -729,7 +747,11 @@ async function handle_decrypt_string(encrypted_string: string, passcode: string) // return new_string and cut_string -function handle_cut_string(old_string: string) { +function handle_cut_string( + old_string: string, + start_tag: string = '', + end_tag: string = '' + ) { // Check if the string contains a set of special "cut" XML tags or Markdown. Anything inside the tags or Markdown will be moved (appended) to the history field. Anything outside the tags should stay. The string may need to be merged back together if something was cut out of the middle. If no closing tag is found, then cut everything to the end of the string. Be sure to prefix the new history sting with a timestamp header in Markdown. // Example: Hello Old World! // Example header: # Cut on 2024-11-06T12:34:56Z @@ -741,45 +763,24 @@ function handle_cut_string(old_string: string) { let cut_out_string = ''; // Will be for the history field if (old_string) { - let cut_tag = ''; - let cut_end_tag = ''; - let cut_index = old_string.indexOf(cut_tag); - let cut_end_index = old_string.indexOf(cut_end_tag); - let cut_prefix = `# Cut on ${new Date().toISOString()}\n`; + let start_tag = ''; + let end_tag = ''; + let cut_index = old_string.indexOf(start_tag); + let cut_end_index = old_string.indexOf(end_tag); + // let cut_prefix = `# Cut on ${new Date().toISOString()}\n`; if (cut_index !== -1) { - if (cut_end_index !== -1) { + if (cut_end_index !== -1 && cut_end_index > cut_index) { // Cut everything between the cut tags - const cut_content = old_string.substring(cut_index + cut_tag.length, cut_end_index); - cut_out_string = cut_prefix + cut_content; - left_over_string = old_string.replace(cut_tag + cut_content + cut_end_tag, ''); + cut_out_string = old_string.substring(cut_index + start_tag.length, cut_end_index).trim(); + left_over_string = (old_string.substring(0, cut_index) + ' ' + old_string.substring(cut_end_index + end_tag.length)).trim(); } else { // Cut everything after the cut tag - const cut_content = old_string.substring(cut_index + cut_tag.length); - cut_out_string = cut_prefix + cut_content; - left_over_string = old_string.substring(0, cut_index); + cut_out_string = old_string.substring(cut_index + start_tag.length).trim(); + left_over_string = old_string.substring(0, cut_index).trim(); } } - - cut_tag = '~~::'; - cut_end_tag = '::~~'; - cut_index = old_string.indexOf(cut_tag); - cut_end_index = old_string.indexOf(cut_end_tag); - cut_prefix = `# Cut on ${new Date().toISOString()}\n`; - if (cut_index !== -1) { - if (cut_end_index !== -1) { - // Cut everything between the cut tags - const cut_content = old_string.substring(cut_index + cut_tag.length, cut_end_index); - cut_out_string = cut_prefix + cut_content; - left_over_string = old_string.replace(cut_tag + cut_content + cut_end_tag, ''); - } else { - // Cut everything after the cut tag - const cut_content = old_string.substring(cut_index + cut_tag.length); - cut_out_string = cut_prefix + cut_content; - left_over_string = old_string.substring(0, cut_index); - } - } - + // console.log(`Cut out string: "${cut_out_string}"`); } return { left_over_string, cut_out_string }; } @@ -2333,7 +2334,7 @@ tabindex={$ae_loc.edit_mode ? 0 : -1} --> " > {#if $journals_sess?.show__content__journal_entry_history == 'view'} -
{@html tmp_entry_obj?.history_md_html} -
+ --> + + {:else if $journals_sess?.show__content__journal_entry_history == 'edit'} - + > --> + + {/if}