fix(journals): resolve decryption toggle issues and component errors

- Added diagnostic logging to decryption helper to track passcode source.
- Refactored 'handle_content_decryption' to prioritize unlocking content.
- Fixed 'updated_obj' reference error in main view.
This commit is contained in:
Scott Idem
2026-01-14 16:00:05 -05:00
parent 6562d4ba04
commit 05bf348e0f
2 changed files with 22 additions and 5 deletions

View File

@@ -36,13 +36,16 @@ export async function decrypt_journal_entry(
// Determine which key to use
let journal_key = typed_passcode;
let key_source = 'user_typed';
// If no override, try the private passcode stored on the journal object
if (!journal_key?.length) {
journal_key = journal.private_passcode;
key_source = 'journal_private_passcode';
}
if (!journal_key) {
console.warn('decrypt_journal_entry: No key available. Source:', key_source);
return {
success: false,
error: 'No passcode provided or available for decryption.'
@@ -51,12 +54,16 @@ export async function decrypt_journal_entry(
// Aether standard: combine the journal's public passcode with the private key
const decrypt_key = `${journal.passcode ?? ''}:${journal_key}`;
console.log(`decrypt_journal_entry: Attempting decryption. Source: ${key_source}`);
// console.log(`decrypt_journal_entry: Key: ${decrypt_key}`); // Log ONLY for deep debugging
try {
// Decrypt Primary Content
const result = await ae_util.decrypt_wrapper(entry.content_encrypted, decrypt_key);
if (result === false) {
console.error('decrypt_journal_entry: Decryption wrapper returned false.');
return {
success: false,
error: 'Decryption failed. Incorrect passcode or corrupted data.'
@@ -74,6 +81,7 @@ export async function decrypt_journal_entry(
}
}
console.log('decrypt_journal_entry: SUCCESS');
return {
success: true,
content: decrypted_text,

View File

@@ -226,15 +226,24 @@
}
async function handle_content_decryption() {
if (!tmp_entry_obj.content) {
const journal = $lq__journal_obj;
const entry = $lq__journal_entry_obj;
if (!journal?.id || !entry) return;
// If encrypted and not currently decrypted, run the decryption workflow
if (entry.content_encrypted && !tmp_entry_obj.content) {
await run_decryption_workflow();
} else {
// Re-lock logic
// Toggle logic: if already decrypted, "lock" it by clearing local state
is_processing = true;
tmp_entry_obj.content = null;
if (orig_entry_obj) orig_entry_obj.content = null;
tmp_entry_obj.history = null;
if (orig_entry_obj) {
orig_entry_obj.content = null;
orig_entry_obj.history = null;
}
journals_sess.update(s => {
s.journal_kv[$lq__journal_obj.id].journal_passcode_decrypted = false;
s.journal_kv[journal.id].journal_passcode_decrypted = false;
return s;
});
is_processing = false;
@@ -322,7 +331,7 @@
journal_config={$lq__journal_obj?.cfg_json}
mode={modal_mode}
onClose={() => (show_append_modal = false)}
onUpdate={() => { show_append_modal = false; updated_obj = true; }}
onUpdate={() => { show_append_modal = false; }}
{log_lvl}
/>
{:else}