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 83ebfa95..08f721ee 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 @@ -176,29 +176,55 @@ async function update_journal_entry() { if (tmp_entry_obj?.content) { - let { left_over_string, cut_out_string } = handle_cut_string(tmp_entry_obj?.content); + if (!tmp_entry_obj?.private) { + let { left_over_string, cut_out_string } = handle_cut_string(tmp_entry_obj?.content); + // let new_content_string = ''; // let cut_content_string = ''; // {new_content_string, cut_content_string} data_kv.content = left_over_string; - data_kv.history = data_kv.history + '\n\n' + cut_out_string; + + if (tmp_entry_obj?.history_encrypted) { + console.log('TEST: Decrypting the history before saving it...'); + decrypted_history = await handle_decrypt_string(tmp_entry_obj?.history_encrypted, journal_key); + } else { + decrypted_history = tmp_entry_obj?.history; + } + + data_kv.history = decrypted_history + '\n' + cut_out_string; + data_kv.history_encrypted = null; + decrypted_history = ''; } else if (tmp_entry_obj?.private) { + let { left_over_string, cut_out_string } = handle_cut_string(tmp_entry_obj?.content); // Need to decrypt the current content and current history. Assume the history has not been decrypted yet. + let content_enc_combined_data = await handle_encrypt_string(left_over_string, journal_key) + data_kv.content_encrypted = content_enc_combined_data; + data_kv.content = null; + decrypted_content = ''; + if (log_lvl) { console.log('TEST: Decrypting the history before saving it...'); } decrypted_history = await handle_decrypt_string(tmp_entry_obj?.history_encrypted, journal_key); - data_kv.history = decrypted_history + '\n\n' + cut_out_string; + + 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; + } + // data_kv.history = tmp_entry_obj?.history + '\n' + decrypted_history + '\n' + cut_out_string; if (log_lvl) { console.log('TEST: Encrypting the history before saving it...'); } - let encrypted_combined_data = await handle_encrypt_string(data_kv.history, journal_key); - data_kv.history_encrypted = encrypted_combined_data; + let history_enc_combined_data = await handle_encrypt_string(data_kv.history, journal_key); + + data_kv.history_encrypted = history_enc_combined_data; data_kv.history = null; + decrypted_history = ''; } } @@ -252,24 +278,24 @@ async function update_journal_entry() { // } if (tmp_entry_obj?.content && tmp_entry_obj?.private) { - // console.log('TEST: Saving encrypted content', tmp_entry_obj?.content); - content = tmp_entry_obj?.content; - // console.log('TEST: journal_key', journal_key); + // // console.log('TEST: Saving encrypted content', tmp_entry_obj?.content); + // content = tmp_entry_obj?.content; + // // console.log('TEST: journal_key', journal_key); - // // Encrypt the content - // let encrypted_base64 = await ae_util.encrypt_content(content, journal_key); - // encrypted_base64_content = encrypted_base64.base64; - // encryption_iv = encrypted_base64.iv; - // console.log(`IV: ${encryption_iv}; Encrypted: ${encrypted_base64_content}`); + // // // Encrypt the content + // // let encrypted_base64 = await ae_util.encrypt_content(content, journal_key); + // // encrypted_base64_content = encrypted_base64.base64; + // // encryption_iv = encrypted_base64.iv; + // // console.log(`IV: ${encryption_iv}; Encrypted: ${encrypted_base64_content}`); - // // Combine the IV and encrypted content - // const combined_data = Array.from(encryption_iv).map(byte => byte.toString(16).padStart(2, '0')).join('') + ':' + encrypted_base64_content; + // // // Combine the IV and encrypted content + // // const combined_data = Array.from(encryption_iv).map(byte => byte.toString(16).padStart(2, '0')).join('') + ':' + encrypted_base64_content; - let combined_data = await handle_encrypt_string(content, journal_key); + // let combined_data = await handle_encrypt_string(content, journal_key); - data_kv.content_encrypted = combined_data; - data_kv.content = null; - decrypted_content = ''; + // data_kv.content_encrypted = combined_data; + // data_kv.content = null; + // decrypted_content = ''; } else if (decrypted_content && !tmp_entry_obj?.private) { // console.log('TEST: Saving decrypted content', decrypted_content); content = decrypted_content; @@ -961,14 +987,22 @@ function handle_cut_string(old_string: string) {