More work on encryption related content and history.

This commit is contained in:
Scott Idem
2025-09-11 15:44:07 -04:00
parent db95ed88a3
commit bbf9411213

View File

@@ -350,7 +350,7 @@ async function update_journal_entry() {
let { left_over_string, cut_out_string } = handle_cut_string(data_kv.content);
data_kv.content = left_over_string;
console.log('TEST: data_kv.content:', data_kv.content);
// console.log('TEST: data_kv.content:', data_kv.content);
data_kv.content_encrypted = null;
@@ -362,14 +362,21 @@ async function update_journal_entry() {
// }
if (cut_out_string) {
let current_timestamp = new Date().toISOString();
cut_out_string = `## Cut on ${current_timestamp}\n` + cut_out_string;
// console.log(`${ae_util.iso_datetime_formatter(new Date().toISOString(), 'datetime_iso_12_no_seconds')}`);
let cut_prefix = `# Cut on ${ae_util.iso_datetime_formatter(new Date().toISOString(), 'datetime_iso_12_no_seconds')}\n`;
// let cut_prefix = `# Cut on ${new Date().toISOString()}\n`;
// let current_timestamp = new Date().toISOString();
// cut_out_string = `## Cut on ${current_timestamp}\n` + cut_out_string;
cut_out_string = cut_prefix + cut_out_string;
// console.log(`TEST: Cut out string with prefix: "${cut_out_string}"`);
}
if (tmp_entry_obj?.history) {
data_kv.history = tmp_entry_obj?.history ?? '' + '\n\n' + cut_out_string;
} else {
data_kv.history = cut_out_string;
if (tmp_entry_obj?.history?.length && cut_out_string) {
// console.log(`HERE 1`);
data_kv.history = tmp_entry_obj?.history + '\n' + cut_out_string + '\n';
} else if (cut_out_string) {
// console.log(`HERE 2`);
data_kv.history = cut_out_string + '\n';
}
console.log('TEST: data_kv.history:', data_kv.history);
@@ -395,14 +402,25 @@ async function update_journal_entry() {
if (log_lvl) {
console.log('TEST: Decrypting the history before saving it...');
}
decrypted_history = await ae_util.decrypt_wrapper(tmp_entry_obj?.history_encrypted, decrypt_key);
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;
if (tmp_entry_obj?.history_encrypted) {
decrypted_history = await ae_util.decrypt_wrapper(tmp_entry_obj?.history_encrypted, decrypt_key);
tmp_entry_obj.history = decrypted_history;
}
// data_kv.history = tmp_entry_obj?.history + '\n' + decrypted_history + '\n' + cut_out_string;
if (cut_out_string) {
let cut_prefix = `# Cut on ${ae_util.iso_datetime_formatter(new Date().toISOString(), 'datetime_iso_12_no_seconds')}\n`;
cut_out_string = cut_prefix + cut_out_string;
console.log(`TEST: Cut out string with prefix: "${cut_out_string}"`);
}
if (tmp_entry_obj?.history?.length && cut_out_string) {
console.log(`HERE 1`);
data_kv.history = tmp_entry_obj?.history + '\n' + cut_out_string + '\n';
} else {
console.log(`HERE 2`);
data_kv.history = cut_out_string + '\n';
}
console.log('TEST: data_kv.history:', data_kv.history);
if (log_lvl) {
console.log('TEST: Encrypting the history before saving it...');
@@ -729,7 +747,11 @@ async function handle_decrypt_string(encrypted_string: string, passcode: string)
// return new_string and cut_string
function handle_cut_string(old_string: string) {
function handle_cut_string(
old_string: string,
start_tag: string = '<cut>',
end_tag: string = '</cut>'
) {
// Check if the string contains a set of special "cut" XML tags or Markdown. Anything inside the tags or Markdown will be moved (appended) to the history field. Anything outside the tags should stay. The string may need to be merged back together if something was cut out of the middle. If no closing tag is found, then cut everything to the end of the string. Be sure to prefix the new history sting with a timestamp header in Markdown.
// Example: Hello <cut>Old</cut> World!
// Example header: # Cut on 2024-11-06T12:34:56Z
@@ -741,45 +763,24 @@ function handle_cut_string(old_string: string) {
let cut_out_string = ''; // Will be for the history field
if (old_string) {
let cut_tag = '<cut>';
let cut_end_tag = '</cut>';
let cut_index = old_string.indexOf(cut_tag);
let cut_end_index = old_string.indexOf(cut_end_tag);
let cut_prefix = `# Cut on ${new Date().toISOString()}\n`;
let start_tag = '<cut>';
let end_tag = '</cut>';
let cut_index = old_string.indexOf(start_tag);
let cut_end_index = old_string.indexOf(end_tag);
// let cut_prefix = `# Cut on ${new Date().toISOString()}\n`;
if (cut_index !== -1) {
if (cut_end_index !== -1) {
if (cut_end_index !== -1 && cut_end_index > cut_index) {
// Cut everything between the cut tags
const cut_content = old_string.substring(cut_index + cut_tag.length, cut_end_index);
cut_out_string = cut_prefix + cut_content;
left_over_string = old_string.replace(cut_tag + cut_content + cut_end_tag, '');
cut_out_string = old_string.substring(cut_index + start_tag.length, cut_end_index).trim();
left_over_string = (old_string.substring(0, cut_index) + ' ' + old_string.substring(cut_end_index + end_tag.length)).trim();
} else {
// Cut everything after the cut tag
const cut_content = old_string.substring(cut_index + cut_tag.length);
cut_out_string = cut_prefix + cut_content;
left_over_string = old_string.substring(0, cut_index);
cut_out_string = old_string.substring(cut_index + start_tag.length).trim();
left_over_string = old_string.substring(0, cut_index).trim();
}
}
cut_tag = '~~::';
cut_end_tag = '::~~';
cut_index = old_string.indexOf(cut_tag);
cut_end_index = old_string.indexOf(cut_end_tag);
cut_prefix = `# Cut on ${new Date().toISOString()}\n`;
if (cut_index !== -1) {
if (cut_end_index !== -1) {
// Cut everything between the cut tags
const cut_content = old_string.substring(cut_index + cut_tag.length, cut_end_index);
cut_out_string = cut_prefix + cut_content;
left_over_string = old_string.replace(cut_tag + cut_content + cut_end_tag, '');
} else {
// Cut everything after the cut tag
const cut_content = old_string.substring(cut_index + cut_tag.length);
cut_out_string = cut_prefix + cut_content;
left_over_string = old_string.substring(0, cut_index);
}
}
// console.log(`Cut out string: "${cut_out_string}"`);
}
return { left_over_string, cut_out_string };
}
@@ -2333,7 +2334,7 @@ tabindex={$ae_loc.edit_mode ? 0 : -1} -->
"
>
{#if $journals_sess?.show__content__journal_entry_history == 'view'}
<article
<!-- <article
class="
grow
space-y-1
@@ -2356,9 +2357,24 @@ tabindex={$ae_loc.edit_mode ? 0 : -1} -->
"
>
{@html tmp_entry_obj?.history_md_html}
</article>
</article> -->
<E_app_codemirror_v5
editable={false}
readonly={true}
content={tmp_entry_obj?.history ?? ''}
bind:new_content={tmp_entry_obj.history}
bind:theme_mode={$ae_loc.theme_mode}
placeholder="Write using Markdown here..."
class="
p-2
preset-outlined-success-400-600
hover:preset-tonal-surface
shadow-lg rounded-lg
"
/>
{:else if $journals_sess?.show__content__journal_entry_history == 'edit'}
<textarea
<!-- <textarea
bind:value={tmp_entry_obj.history}
class="
space-y-1
@@ -2375,7 +2391,21 @@ tabindex={$ae_loc.edit_mode ? 0 : -1} -->
hover:border-orange-500 dark:hover:border-orange-500
"
placeholder="Edit journal entry content here..."
></textarea>
></textarea> -->
<E_app_codemirror_v5
content={tmp_entry_obj?.history ?? ''}
bind:new_content={tmp_entry_obj.history}
bind:theme_mode={$ae_loc.theme_mode}
placeholder="Write using Markdown here..."
class="
p-2
preset-outlined-warning-300-700
shadow-lg rounded-lg
bg-gray-100 text-gray-950
dark:bg-gray-800 dark:text-gray-100
"
/>
{/if}
</div>