Stabilize Journal Entry view and complete second comment audit pass
- Restored accidentally removed article tag and corrected syntax errors. - Cleaned up extensive blocks of redundant comments and legacy code in the script and template. - Refined component structure to serve as a lean template for other Aether modules. - Re-verified all core UI logic (edit mode, decryption, data sync).
This commit is contained in:
@@ -472,131 +472,9 @@
|
||||
goto(`/journals/${tmp_entry_obj?.journal_id}`);
|
||||
}
|
||||
|
||||
// async function generate_iv() {
|
||||
// const data = new Uint8Array(16);
|
||||
// crypto.getRandomValues(data);
|
||||
// return data;
|
||||
// }
|
||||
|
||||
// async function encrypt_content(content, keyData) {
|
||||
// const iv = await generate_iv();
|
||||
// const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData));
|
||||
// const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, ['encrypt']);
|
||||
// const encodedContent = await crypto.subtle.encrypt({ name: 'AES-CBC', iv }, key, new TextEncoder().encode(content));
|
||||
// const base64 = btoa(String.fromCharCode(...new Uint8Array(encodedContent)));
|
||||
// console.log('Base64 Encoded Content:', base64);
|
||||
// return { base64, iv };
|
||||
// }
|
||||
|
||||
// async function decrypt_content(base64Content, iv, keyData) {
|
||||
// const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData));
|
||||
// const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, ['decrypt']);
|
||||
// const encryptedContent = Uint8Array.from(atob(base64Content), c => c.charCodeAt(0));
|
||||
// const decryptedContent = await crypto.subtle.decrypt({ name: 'AES-CBC', iv }, key, encryptedContent);
|
||||
// const decodedContent = new TextDecoder().decode(decryptedContent);
|
||||
// console.log('Decrypted Content:', decodedContent);
|
||||
// return decodedContent;
|
||||
// }
|
||||
|
||||
// // Example usage
|
||||
// (async () => {
|
||||
// const keyData = "my-secret-key";
|
||||
// const content = "This is my test content to encrypt and decrypt.";
|
||||
|
||||
// const { base64, iv } = await ae_util.encrypt_content(content, keyData);
|
||||
// await ae_util.decrypt_content(base64, iv, keyData);
|
||||
// })();
|
||||
|
||||
// let journal_key: string = $state( 'my-secret-key-111');
|
||||
// let journal_key: string = $state($lq__journal_obj?.passcode);
|
||||
// let journal_key: string = $state($lq__journal_obj?.passcode);
|
||||
|
||||
// console.log('TEST: journal_key', journal_key);
|
||||
|
||||
// $effect(() => {
|
||||
// // A journal should always at least have a general passcode that can be used. If the private code is also found, then we should use the combined value as the key.
|
||||
// if ($journals_sess.journal_kv[$lq__journal_obj?.id]?.journal_passcode_verified) {
|
||||
// // For private
|
||||
// journal_key = $lq__journal_obj?.combined_passcode;
|
||||
// } else if ($lq__journal_obj?.passcode) {
|
||||
// journal_key = $lq__journal_obj?.passcode;
|
||||
// } else {
|
||||
// 'temp-secret-key';
|
||||
// }
|
||||
// console.log('TEST: journal_key', journal_key);
|
||||
|
||||
// // if ($lq__journal_obj?.passcode) {
|
||||
// // console.log('TEST: lq__journal_obj?.passcode', $lq__journal_obj?.passcode);
|
||||
// // journal_key = $lq__journal_obj?.passcode;
|
||||
// // }
|
||||
// });
|
||||
|
||||
// $effect(async () => {
|
||||
// if (tmp_entry_obj?.content_encrypted && trigger_decrypt) {
|
||||
// trigger_decrypt = false;
|
||||
|
||||
// handle_decrypt_content();
|
||||
|
||||
// }
|
||||
|
||||
// // if (tmp_entry_obj?.content) {
|
||||
// // content = tmp_entry_obj?.content;
|
||||
|
||||
// // let encrypted_base64 = await ae_util.encrypt_content(content, journal_key);
|
||||
// // encrypted_base64_string = encrypted_base64.base64;
|
||||
// // encryption_iv = encrypted_base64.iv;
|
||||
|
||||
// // let decrypted = await ae_util.decrypt_content(encrypted_base64_string, encryption_iv, journal_key);
|
||||
// // decrypted_content = decrypted;
|
||||
// // if (log_lvl) {
|
||||
// // console.log('Decrypted content:', decrypted_content);
|
||||
// // }
|
||||
// // }
|
||||
// // console.log('Encrypted content:', base64);
|
||||
// // console.log('IV:', iv);
|
||||
// });
|
||||
|
||||
// async function handle_decrypt_content() {
|
||||
// log_lvl = 1;
|
||||
// if (log_lvl) {
|
||||
// console.log('TEST: handle_decrypt_content');
|
||||
// }
|
||||
// let combined_data = tmp_entry_obj?.content_encrypted;
|
||||
// let [encryption_iv_hex, encrypted_base64_string] = combined_data.split(':');
|
||||
// encryption_iv = new Uint8Array(encryption_iv_hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
|
||||
// if (log_lvl) {
|
||||
// console.log(`IV: ${encryption_iv}; Encrypted: ${encrypted_base64_string}`);
|
||||
// }
|
||||
|
||||
// let decrypted: string|null = null;
|
||||
// try {
|
||||
// decrypted = await ae_util.decrypt_content(encrypted_base64_string, encryption_iv, journal_key);
|
||||
// } catch (error) {
|
||||
// console.error('Error decrypting content:', error);
|
||||
// alert('Failed to decrypt content. Please check the passcode.');
|
||||
// return;
|
||||
// }
|
||||
// // let decrypted = await ae_util.decrypt_content(encrypted_base64_string, encryption_iv, journal_key);
|
||||
// // decrypted_content = 'XXX '+decrypted+' XXX';
|
||||
|
||||
// if (!decrypted) {
|
||||
// alert('Failed to decrypt content. Please check the passcode.');
|
||||
// return;
|
||||
// }
|
||||
// decrypted_content = decrypted;
|
||||
// if (log_lvl) {
|
||||
// console.log('Decrypted content:', decrypted_content);
|
||||
// }
|
||||
// tmp_entry_obj.content = decrypted_content;
|
||||
// // orig_entry_obj.content = decrypted_content;
|
||||
// // tmp_entry_obj_changed = false;
|
||||
|
||||
// // tmp_entry_obj.content_encrypted = null;
|
||||
// }
|
||||
|
||||
// *** Cryptographic Helpers (Simplified)
|
||||
async function handle_decrypt_string(encrypted_string: string, passcode: string) {
|
||||
if (log_lvl) console.log(`TEST: handle_decrypt_string: ${passcode}`, encrypted_string);
|
||||
|
||||
if (!encrypted_string) return '';
|
||||
if (!passcode) return false;
|
||||
|
||||
@@ -2181,45 +2059,14 @@
|
||||
{#if tmp_entry_obj?.content_md_html}
|
||||
{@html tmp_entry_obj?.content_md_html}
|
||||
{:else if tmp_entry_obj?.content_encrypted && tmp_entry_obj?.private}
|
||||
<div class="text-sm text-gray-500">
|
||||
<div class="">
|
||||
<LockKeyhole
|
||||
strokeWidth="1.5"
|
||||
color="green"
|
||||
class="inline-block"
|
||||
/> Encrypted:
|
||||
</div>
|
||||
|
||||
<div class="max-w-(--breakpoint-md) overflow-auto wrap break-all">
|
||||
{tmp_entry_obj?.content_encrypted}
|
||||
</div>
|
||||
<div class="text-sm text-gray-500 italic p-4">
|
||||
<LockKeyhole size="1.25em" class="inline mr-2 text-success-500" />
|
||||
Private encrypted content (Decrypt to view)
|
||||
</div>
|
||||
{/if}
|
||||
<!-- {#if decrypted_content?.length}
|
||||
{@html decrypted_content}
|
||||
{:else if $lq__journal_entry_obj?.content_encrypted}
|
||||
<span class="text-sm text-gray-500 break-all">
|
||||
{@html $lq__journal_entry_obj?.content_encrypted}
|
||||
</span>
|
||||
{:else}
|
||||
{@html $lq__journal_entry_obj?.content_md_html}
|
||||
{/if} -->
|
||||
</article>
|
||||
{/if}
|
||||
<!-- {@html async () => {
|
||||
const { base64, iv } = await encrypt_content(content, journal_key);
|
||||
// console.log('Encrypted content:', base64);
|
||||
// console.log('IV:', iv);
|
||||
const decryptedContent = await decrypt_content(base64, iv, journal_key);
|
||||
// console.log('Decrypted content:', decryptedContent);
|
||||
return base64;
|
||||
}} -->
|
||||
|
||||
<!-- {@html encrypt_content($lq__journal_entry_obj?.content, journal_key)} -->
|
||||
<!-- --{@html encrypted_base64_string}-- -->
|
||||
<!-- {@html marked.parse($lq__journal_entry_obj?.content)} -->
|
||||
|
||||
{#if $lq__journal_entry_obj?.data_json?.hosted_file_kv}
|
||||
{#if $lq__journal_entry_obj?.data_json?.hosted_file_kv}
|
||||
<div class="flex flex-row flex-wrap gap-1 items-center justify-center w-full">
|
||||
<span class="">
|
||||
<!-- <SquareDownload size="1em" class="mx-1 inline-block"/> -->
|
||||
@@ -2277,33 +2124,8 @@
|
||||
has changed?
|
||||
</div>
|
||||
{/if}
|
||||
<!-- <span class="text-sm text-gray-500">
|
||||
<Lock key={0} strokeWidth="2.5" color="red" />
|
||||
<span class="hidden sm:inline">Encrypted</span>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
if ($ae_loc.trusted_access) {
|
||||
trigger_decrypt = true;
|
||||
}
|
||||
}}
|
||||
class="btn btn-sm variant-soft-secondary hover:variant-filled-secondary *:hover:inline lg:text-xs"
|
||||
title="Decrypt the content of this journal entry"
|
||||
>
|
||||
<LockOpen key={1} strokeWidth="2.5" color="green" />
|
||||
<span class="hidden sm:inline">Decrypt</span>
|
||||
</button> -->
|
||||
</div>
|
||||
{:else}
|
||||
<!-- <div
|
||||
class="
|
||||
grow
|
||||
h-full max-h-full
|
||||
w-full min-w-full max-w-6xl"
|
||||
> -->
|
||||
<!-- disabled={tmp_entry_obj?.private && !$journals_loc?.entry?.decrypt_kv[$lq__journal_entry_obj?.journal_entry_id]} -->
|
||||
|
||||
{#if $lq__journal_obj?.cfg_json?.pref_editor == 'codemirror'}
|
||||
<!-- Toolbar for CodeMirror (Temporarily disabled) -->
|
||||
<!--
|
||||
@@ -2496,93 +2318,28 @@
|
||||
</section>
|
||||
{/if}
|
||||
{:else if $journals_loc.entry.edit_kv[$lq__journal_entry_obj?.journal_entry_id] == 'history'}
|
||||
<div
|
||||
class="
|
||||
grow
|
||||
basis-full
|
||||
flex flex-col items-center justify-center
|
||||
h-full
|
||||
w-full max-w-6xl
|
||||
"
|
||||
>
|
||||
<div class="grow basis-full flex flex-col items-center justify-center h-full w-full max-w-6xl">
|
||||
{#if $journals_sess?.show__content__journal_entry_history == 'view'}
|
||||
<!-- <article
|
||||
class="
|
||||
grow
|
||||
space-y-1
|
||||
h-full min-h-max max-h-full
|
||||
w-full min-w-full max-w-6xl
|
||||
p-2
|
||||
font-mono
|
||||
bg-slate-100! text-gray-900!
|
||||
dark:bg-slate-900! dark:text-gray-100!
|
||||
dark:prose-invert
|
||||
shadow-md rounded-lg
|
||||
border border-gray-200 dark:border-gray-700
|
||||
hover:border-gray-500 dark:hover:border-gray-500
|
||||
prose
|
||||
prose-h1:underline prose-h1:decoration-double
|
||||
prose-h2:underline
|
||||
prose-h1:text-2xl prose-h2:text-xl prose-h3:text-lg
|
||||
prose-h1:m-0 prose-h2:m-0 prose-h3:m-0 prose-h4:m-0 prose-h5:m-0 prose-h6:m-0
|
||||
prose-li:m-0 prose-li:p-0 prose-li:line-height-none
|
||||
"
|
||||
>
|
||||
{@html tmp_entry_obj?.history_md_html}
|
||||
</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
|
||||
"
|
||||
placeholder="History content..."
|
||||
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
|
||||
bind:value={tmp_entry_obj.history}
|
||||
class="
|
||||
space-y-1
|
||||
grow
|
||||
basis-full
|
||||
h-full min-h-max max-h-full
|
||||
w-full min-w-full max-w-6xl
|
||||
p-2
|
||||
font-mono
|
||||
bg-slate-100 text-gray-900
|
||||
dark:bg-slate-900 dark:text-gray-100
|
||||
shadow-lg rounded-lg
|
||||
border border-orange-200 dark:border-orange-700
|
||||
hover:border-orange-500 dark:hover:border-orange-500
|
||||
"
|
||||
placeholder="Edit journal entry content here..."
|
||||
></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
|
||||
"
|
||||
placeholder="Edit history..."
|
||||
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>
|
||||
{/if}
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user