add password to frontend

This commit is contained in:
2023-05-23 09:39:19 +02:00
parent 6da28a701e
commit fdc2722fb9
8 changed files with 124 additions and 70 deletions

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { AES, Hex } from 'occulto'
import { AES, Hex, Bytes } from 'occulto'
import { t } from 'svelte-intl-precompile'
import { blur } from 'svelte/transition'
@@ -57,13 +57,14 @@
try {
loading = $t('common.encrypting')
const key = await AES.generateKey()
const password = Hex.encode(key)
const derived = note.password && (await AES.derive(note.password))
const key = derived ? derived[0] : await AES.generateKey()
const data: Note = {
contents: '',
meta: note.meta,
}
if (derived) data.meta.derivation = derived[1]
if (isFile) {
if (files.length === 0) throw new EmptyContentError()
data.contents = await Adapters.Files.encrypt(files, key)
@@ -77,8 +78,8 @@
loading = $t('common.uploading')
const response = await create(data)
result = {
password: password,
id: response.id,
password: note.password ? undefined : Hex.encode(key),
}
notify.success($t('home.messages.note_created'))
} catch (e) {
@@ -148,7 +149,7 @@
{#if advanced}
<div transition:blur={{ duration: 250 }}>
<br />
<hr />
<AdvancedParameters bind:note bind:timeExpiration />
</div>
{/if}