feat(journals): extract decryption logic to helper and improve Quick Add behavior
- Extracted journal entry decryption workflow to 'ae_journals_decryption.ts' to decouple it from Svelte reactivity and address loop issues. - Updated 'ae_comp__journal_entry_obj_id_view.svelte' to use the new decryption helper. - Refactored 'Quick Add' to use the first line as the title and remove it from the content before saving.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
import { ae_loc, ae_api } from '$lib/stores/ae_stores';
|
||||
import { journals_loc, journals_sess, journals_slct } from '$lib/ae_journals/ae_journals_stores';
|
||||
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
import { decrypt_journal_entry } from '$lib/ae_journals/ae_journals_decryption';
|
||||
|
||||
import JournalEntry_Editor from './JournalEntry_Editor.svelte';
|
||||
import JournalEntry_Header from './JournalEntry_Header.svelte';
|
||||
@@ -125,9 +126,7 @@
|
||||
if (!journal?.id) return;
|
||||
|
||||
let journal_key = $journals_sess.journal_kv[journal.id]?.typed_journal_passcode;
|
||||
if (!journal_key?.length) journal_key = journal.private_passcode;
|
||||
if (!journal_key) return;
|
||||
|
||||
|
||||
is_processing = true;
|
||||
decryption_error = null;
|
||||
|
||||
@@ -137,11 +136,10 @@
|
||||
return s;
|
||||
});
|
||||
|
||||
const decrypt_key = `${journal.passcode ?? ''}:${journal_key}`;
|
||||
const result = await ae_util.decrypt_wrapper($lq__journal_entry_obj?.content_encrypted, decrypt_key);
|
||||
const result = await decrypt_journal_entry($lq__journal_entry_obj, journal, journal_key);
|
||||
|
||||
if (result === false) {
|
||||
decryption_error = 'Decryption failed. Incorrect passcode or corrupted data.';
|
||||
if (!result.success) {
|
||||
decryption_error = result.error || 'Decryption failed.';
|
||||
journals_sess.update(s => {
|
||||
s.journal_kv[journal.id].journal_passcode_verified = false;
|
||||
s.journal_kv[journal.id].journal_passcode_decrypted = false;
|
||||
@@ -152,18 +150,13 @@
|
||||
}
|
||||
|
||||
// SUCCESS
|
||||
const decrypted_text = typeof result === 'string' ? result : '';
|
||||
tmp_entry_obj.content = decrypted_text;
|
||||
tmp_entry_obj.content_md_html = handle_marked(decrypted_text);
|
||||
if (orig_entry_obj) orig_entry_obj.content = decrypted_text;
|
||||
tmp_entry_obj.content = result.content;
|
||||
tmp_entry_obj.content_md_html = handle_marked(result.content || '');
|
||||
if (orig_entry_obj) orig_entry_obj.content = result.content;
|
||||
|
||||
// Decrypt History
|
||||
if ($lq__journal_entry_obj?.history_encrypted) {
|
||||
const h_res = await ae_util.decrypt_wrapper($lq__journal_entry_obj.history_encrypted, decrypt_key);
|
||||
if (h_res !== false) {
|
||||
tmp_entry_obj.history = h_res;
|
||||
if (orig_entry_obj) orig_entry_obj.history = h_res;
|
||||
}
|
||||
if (result.history) {
|
||||
tmp_entry_obj.history = result.history;
|
||||
if (orig_entry_obj) orig_entry_obj.history = result.history;
|
||||
}
|
||||
|
||||
journals_sess.update(s => {
|
||||
|
||||
@@ -36,9 +36,12 @@
|
||||
let name = lines[0].substring(0, 100);
|
||||
if (lines[0].length > 100) name += "...";
|
||||
|
||||
// Remove the first line (title) from the content
|
||||
const entry_content = lines.slice(1).join('\n').trim();
|
||||
|
||||
const data_kv = {
|
||||
name: name,
|
||||
content: note_content,
|
||||
content: entry_content,
|
||||
type_code: 'note',
|
||||
private: false, // Ensure notes are public/decrypted by default
|
||||
enable: true,
|
||||
|
||||
Reference in New Issue
Block a user