From e8c6467faabad1941c2fe809d64b57bae999f3cd Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Wed, 2 Mar 2022 16:55:10 +0100 Subject: [PATCH] dont' allow empty notes --- frontend/locales/de.json | 3 ++- frontend/locales/en.json | 3 ++- frontend/locales/es.json | 3 ++- frontend/locales/fr.json | 3 ++- frontend/locales/it.json | 3 ++- frontend/src/lib/views/Create.svelte | 5 +++++ 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend/locales/de.json b/frontend/locales/de.json index 1ceea60..86f6a80 100644 --- a/frontend/locales/de.json +++ b/frontend/locales/de.json @@ -20,7 +20,8 @@ "errors": { "note_to_big": "Notiz konnte nicht erstellt werden. Notiz ist zu groß", "note_error": "konnte keine Notiz erstellen. Bitte versuchen Sie es erneut.", - "max": "max: {n}" + "max": "max: {n}", + "empty_content": "Notiz ist leer." }, "copied_to_clipboard": "in die Zwischenablage kopiert 🔗" }, diff --git a/frontend/locales/en.json b/frontend/locales/en.json index 9c31407..ae8490f 100644 --- a/frontend/locales/en.json +++ b/frontend/locales/en.json @@ -20,7 +20,8 @@ "errors": { "note_to_big": "could not create note. note is to big", "note_error": "could not create note. please try again.", - "max": "max: {n}" + "max": "max: {n}", + "empty_content": "note is empty." }, "copied_to_clipboard": "copied to clipboard 🔗" }, diff --git a/frontend/locales/es.json b/frontend/locales/es.json index 623af0e..c71daad 100644 --- a/frontend/locales/es.json +++ b/frontend/locales/es.json @@ -20,7 +20,8 @@ "errors": { "note_to_big": "no se pudo crear la nota. la nota es demasiado grande", "note_error": "No se ha podido crear la nota. Por favor, inténtelo de nuevo.", - "max": "max: {n}" + "max": "max: {n}", + "empty_content": "la nota está vacía." }, "copied_to_clipboard": "copiado al portapapeles 🔗" }, diff --git a/frontend/locales/fr.json b/frontend/locales/fr.json index 2ecd309..5abeae1 100644 --- a/frontend/locales/fr.json +++ b/frontend/locales/fr.json @@ -20,7 +20,8 @@ "errors": { "note_to_big": "Impossible de créer une note. La note est trop grande", "note_error": "n'a pas pu créer de note. Veuillez réessayer.", - "max": "max: {n}" + "max": "max: {n}", + "empty_content": "La note est vide." }, "copied_to_clipboard": "copié dans le presse-papiers 🔗" }, diff --git a/frontend/locales/it.json b/frontend/locales/it.json index dc56a54..08349e2 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -20,7 +20,8 @@ "errors": { "note_to_big": "impossibile creare una nota. la nota è troppo grande", "note_error": "Impossibile creare la nota. Riprova.", - "max": "max: {n}" + "max": "max: {n}", + "empty_content": "la nota è vuota." }, "copied_to_clipboard": "copiato negli appunti 🔗" }, diff --git a/frontend/src/lib/views/Create.svelte b/frontend/src/lib/views/Create.svelte index 1c5a9d7..bb63644 100644 --- a/frontend/src/lib/views/Create.svelte +++ b/frontend/src/lib/views/Create.svelte @@ -46,12 +46,15 @@ note.contents = '' } + class EmptyContentError extends Error {} + async function submit() { try { error = null loading = true const password = Hex.encode(getRandomBytes(32)) const key = await getKeyFromString(password) + if (note.contents === '') throw new EmptyContentError() const data: Note = { contents: await encrypt(note.contents, key), meta: note.meta, @@ -67,6 +70,8 @@ } catch (e) { if (e instanceof PayloadToLargeError) { error = $t('home.errors.note_to_big') + } else if (e instanceof EmptyContentError) { + error = $t('home.errors.empty_content') } else { error = $t('home.errors.note_error') }