Wrapping up for the day. History field mostly works now. But has bugs!

This commit is contained in:
Scott Idem
2025-05-05 17:49:44 -04:00
parent 66b122dca5
commit a27fdd5fc4

View File

@@ -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) {
<!-- Only show this encryption toggle if entry is private. -->
<button
type="button"
onclick={() => {
onclick={async () => {
if (tmp_entry_obj?.private && decrypted_content) {
decrypted_content = '';
// tmp_entry_obj.content = null;
} else if (tmp_entry_obj?.private && tmp_entry_obj?.content_encrypted) {
if (confirm('Are you sure you want to decrypt the content to view/edit?')) {
// trigger_decrypt = true;
handle_decrypt_content();
// handle_decrypt_content();
// handle_decrypt_string(tmp_entry_obj?.content_encrypted, journal_key).then((result) => {
// decrypted_content = result;
// console.log('TEST: Decrypted content:', decrypted_content);
// });
decrypted_content = await handle_decrypt_string(tmp_entry_obj?.content_encrypted, journal_key);
tmp_entry_obj.content = decrypted_content;
console.log('TEST: Decrypted content:', decrypted_content);
} else {
return false;
}
@@ -1302,7 +1336,8 @@ tabindex={$ae_loc.edit_mode ? 0 : -1} -->
$journals_sess.show__content__journal_entry_history = 'view';
}
if (!tmp_entry_obj?.history && tmp_entry_obj?.history_encrypted) {
// !tmp_entry_obj?.history &&
if (tmp_entry_obj?.history_encrypted) {
decrypted_history = await handle_decrypt_string(tmp_entry_obj.history_encrypted, journal_key);
console.log('Decrypted history:', decrypted_history);
tmp_entry_obj.history = decrypted_history;
@@ -1319,12 +1354,18 @@ tabindex={$ae_loc.edit_mode ? 0 : -1} -->
<button
type="button"
class:hidden={!$journals_sess.show__content__journal_entry_history}
onclick={() => {
onclick={async () => {
if ($journals_sess.show__content__journal_entry_history == 'view') {
$journals_sess.show__content__journal_entry_history = 'edit';
} else if ($journals_sess.show__content__journal_entry_history == 'edit') {
$journals_sess.show__content__journal_entry_history = 'view';
}
if (tmp_entry_obj?.history_encrypted) {
decrypted_history = await handle_decrypt_string(tmp_entry_obj.history_encrypted, journal_key);
console.log('Decrypted history:', decrypted_history);
tmp_entry_obj.history = decrypted_history;
}
}}
class="btn btn-sm variant-soft-secondary hover:variant-filled-secondary *:hover:inline lg:text-xs"
title="Toggle edit mode for history of this journal entry"