From f88e6cef894844ba4986e2fb0a60b78fa722eb9f Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Fri, 16 May 2025 17:29:33 -0400 Subject: [PATCH] Fixed and improved encryption handling. Also wrapping up for the day. --- src/lib/ae_journals/ae_journals__journal.ts | 2 +- src/lib/ae_utils/ae_utils__crypto.ts | 4 +- .../journals/[journal_id]/+layout.svelte | 197 ++++++++++-------- .../ae_comp__journal_entry_obj_id_view.svelte | 34 ++- .../ae_comp__journal_obj_id_view.svelte | 13 +- 5 files changed, 154 insertions(+), 96 deletions(-) diff --git a/src/lib/ae_journals/ae_journals__journal.ts b/src/lib/ae_journals/ae_journals__journal.ts index b9cd3dd0..c37cd4d0 100644 --- a/src/lib/ae_journals/ae_journals__journal.ts +++ b/src/lib/ae_journals/ae_journals__journal.ts @@ -740,7 +740,7 @@ export async function db_save_ae_obj_li__journal( // tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`, // tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`, - combined_passcode: `${obj.passcode}:${obj.private_passcode}`, // Combined Journal passcode and Journal private passcode to encrypt and decrypt Entries + combined_passcode: `${obj.passcode}:${obj.private_passcode ?? ''}`, // Combined Journal passcode and Journal private passcode to encrypt and decrypt Entries // From SQL view journal_entry_count: obj.journal_entry_count, diff --git a/src/lib/ae_utils/ae_utils__crypto.ts b/src/lib/ae_utils/ae_utils__crypto.ts index 547b6be9..7da5c314 100644 --- a/src/lib/ae_utils/ae_utils__crypto.ts +++ b/src/lib/ae_utils/ae_utils__crypto.ts @@ -101,7 +101,7 @@ export let decrypt_wrapper = async function decrypt_wrapper( ) { if (!combined) { console.error('No combined string provided. Returning empty string.'); - return ''; + return false; } const { iv, base64 } = split_iv_and_base64(combined); let decrypted; @@ -114,7 +114,7 @@ export let decrypt_wrapper = async function decrypt_wrapper( } } catch (error) { console.error('Decryption failed:', error); - return ''; + return false; } return decrypted; } \ No newline at end of file diff --git a/src/routes/journals/[journal_id]/+layout.svelte b/src/routes/journals/[journal_id]/+layout.svelte index c98e8835..fe68492d 100644 --- a/src/routes/journals/[journal_id]/+layout.svelte +++ b/src/routes/journals/[journal_id]/+layout.svelte @@ -59,6 +59,7 @@ let lq__journal_obj = $derived(liveQuery(async () => { .get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does $journals_slct.journal_obj = results; + tmp_journal_obj = { ...results }; if (log_lvl) { console.log(`lq__journal_obj: results = `, results); } @@ -66,11 +67,12 @@ let lq__journal_obj = $derived(liveQuery(async () => { return results; })); -$effect(() => { - if ($lq__journal_obj) { - tmp_journal_obj = { ...$lq__journal_obj }; - } -}); +// $effect(() => { +// if ($lq__journal_obj) { +// tmp_journal_obj = { ...$lq__journal_obj }; +// console.log('tmp_journal_obj:', tmp_journal_obj); +// } +// }); $effect(() => { if (tmp_journal_obj) { @@ -79,18 +81,19 @@ $effect(() => { }); async function handle_update_journal() { - if ($journals_slct.tmp_journal_obj.name && $journals_slct.tmp_journal_obj.type_code) { + if (tmp_journal_obj.name && tmp_journal_obj.type_code) { try { let data_kv = { // account: $slct.account_id, - name: $journals_slct.tmp_journal_obj.name, - description: $journals_slct.tmp_journal_obj.description ?? '', // Ensure description is at least an empty string - type_code: $journals_slct.tmp_journal_obj.type_code, - passcode: $journals_slct.tmp_journal_obj.passcode, - passcode_timeout: $journals_slct.tmp_journal_obj.passcode_timeout, - auth_key: $journals_slct.tmp_journal_obj.auth_key, // The Journal Entry encryption password + name: tmp_journal_obj.name, + description: tmp_journal_obj.description ?? '', // Ensure description is at least an empty string + type_code: tmp_journal_obj.type_code, + passcode: tmp_journal_obj.passcode, + private_passcode: tmp_journal_obj.private_passcode, + passcode_timeout: tmp_journal_obj.passcode_timeout, + auth_key: tmp_journal_obj.auth_key, // The Journal Entry encryption password - cfg_json: $journals_slct.tmp_journal_obj.cfg_json + cfg_json: tmp_journal_obj.cfg_json }; journals_func.update_ae_obj__journal({ @@ -199,7 +202,7 @@ async function handle_update_journal() { @@ -398,7 +401,7 @@ async function handle_update_journal() { Journal Description: @@ -406,31 +409,47 @@ async function handle_update_journal() {
- - @@ -445,11 +464,11 @@ async function handle_update_journal() { transition text-xs " - bind:value={$journals_slct.tmp_journal_obj.type_code} + bind:value={tmp_journal_obj.type_code} onchange={(event) => { // Update the cfg_json with the selected journal type. Example cate - $journals_slct.tmp_journal_obj.type_code = event.target.value; - console.log('Selected journal type:', $journals_slct.tmp_journal_obj.type_code); + tmp_journal_obj.type_code = event.target.value; + console.log('Selected journal type:', tmp_journal_obj.type_code); }} title="Select a journal type" > @@ -460,23 +479,23 @@ async function handle_update_journal() {
-
+
- {#each $journals_slct.tmp_journal_obj.cfg_json.category_li as category, index} + {#each tmp_journal_obj?.cfg_json?.category_li as category, index}
- - + +