diff --git a/backend/src/config.rs b/backend/src/config.rs index fe201ac..85fafd9 100644 --- a/backend/src/config.rs +++ b/backend/src/config.rs @@ -4,15 +4,15 @@ lazy_static! { pub static ref VERSION: String = option_env!("CARGO_PKG_VERSION") .unwrap_or("Unknown") .to_string(); - pub static ref LIMIT: usize = + pub static ref LIMIT: u32 = Byte::from_str(std::env::var("SIZE_LIMIT").unwrap_or("1 KiB".to_string())) .unwrap() - .get_bytes() as usize; - pub static ref MAX_VIEWS: usize = std::env::var("MAX_VIEWS") + .get_bytes() as u32; + pub static ref MAX_VIEWS: u32 = std::env::var("MAX_VIEWS") .unwrap_or("100".to_string()) .parse() .unwrap(); - pub static ref MAX_EXPIRATION: usize = std::env::var("MAX_EXPIRATION") + pub static ref MAX_EXPIRATION: u32 = std::env::var("MAX_EXPIRATION") .unwrap_or("360".to_string()) // 6 hours in minutes .parse() .unwrap(); diff --git a/backend/src/note/model.rs b/backend/src/note/model.rs index c9e1792..398eaaa 100644 --- a/backend/src/note/model.rs +++ b/backend/src/note/model.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; pub struct Note { pub meta: String, pub contents: String, - pub views: Option, + pub views: Option, pub expiration: Option, } diff --git a/backend/src/note/routes.rs b/backend/src/note/routes.rs index 40d3948..063d5b6 100644 --- a/backend/src/note/routes.rs +++ b/backend/src/note/routes.rs @@ -2,6 +2,7 @@ use actix_web::{delete, get, post, web, HttpResponse, Responder, Scope}; use serde::{Deserialize, Serialize}; use std::time::SystemTime; +use crate::config; use crate::note::{generate_id, Note, NoteInfo, NotePublic}; use crate::store; @@ -40,17 +41,22 @@ async fn create(note: web::Json) -> impl Responder { if n.views == None && n.expiration == None { return bad_req; } + if !*config::ALLOW_ADVANCED { + n.views = Some(1); + n.expiration = None; + } match n.views { Some(v) => { - if v > 100 { + if v > *config::MAX_VIEWS { return bad_req; } + n.expiration = None; // views overrides expiration } _ => {} } match n.expiration { Some(e) => { - if e > 360 { + if e > *config::MAX_EXPIRATION { return bad_req; } let expiration = now() + (e * 60); diff --git a/backend/src/status/model.rs b/backend/src/status/model.rs index 05edeaa..68c19bb 100644 --- a/backend/src/status/model.rs +++ b/backend/src/status/model.rs @@ -3,8 +3,8 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] pub struct Status { pub version: String, - pub max_size: usize, - pub max_views: usize, - pub max_expiration: usize, + pub max_size: u32, + pub max_views: u32, + pub max_expiration: u32, pub allow_advanced: bool, } diff --git a/frontend/locales/de.json b/frontend/locales/de.json index a7c6bb0..1ceea60 100644 --- a/frontend/locales/de.json +++ b/frontend/locales/de.json @@ -19,7 +19,8 @@ "new_note_notice": "Verfügbarkeit:
es ist nicht garantiert, dass die Notiz gespeichert wird, da alles im Speicher gehalten wird. Wenn dieser voll ist, werden die ältesten Notizen entfernt.
(Sie werden wahrscheinlich keine Probleme haben, seien Sie nur gewarnt).", "errors": { "note_to_big": "Notiz konnte nicht erstellt werden. Notiz ist zu groß", - "note_error": "konnte keine Notiz erstellen. Bitte versuchen Sie es erneut." + "note_error": "konnte keine Notiz erstellen. Bitte versuchen Sie es erneut.", + "max": "max: {n}" }, "copied_to_clipboard": "in die Zwischenablage kopiert 🔗" }, diff --git a/frontend/locales/en.json b/frontend/locales/en.json index 60741e6..9c31407 100644 --- a/frontend/locales/en.json +++ b/frontend/locales/en.json @@ -19,7 +19,8 @@ "new_note_notice": "availability:
the note is not guaranteed to be stored as everything is kept in ram, if it fills up the oldest notes will be removed.
(you probably will be fine, just be warned.)", "errors": { "note_to_big": "could not create note. note is to big", - "note_error": "could not create note. please try again." + "note_error": "could not create note. please try again.", + "max": "max: {n}" }, "copied_to_clipboard": "copied to clipboard 🔗" }, diff --git a/frontend/locales/es.json b/frontend/locales/es.json index f2cf547..623af0e 100644 --- a/frontend/locales/es.json +++ b/frontend/locales/es.json @@ -19,7 +19,8 @@ "new_note_notice": "disponibilidad:
no se garantiza que la nota se almacene, ya que todo se guarda en la memoria RAM, si se llena se eliminarán las notas más antiguas.
(probablemente estará bien, sólo está advertido.)", "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." + "note_error": "No se ha podido crear la nota. Por favor, inténtelo de nuevo.", + "max": "max: {n}" }, "copied_to_clipboard": "copiado al portapapeles 🔗" }, diff --git a/frontend/locales/fr.json b/frontend/locales/fr.json index 48f6d5d..2ecd309 100644 --- a/frontend/locales/fr.json +++ b/frontend/locales/fr.json @@ -19,7 +19,8 @@ "new_note_notice": "disponibilité :
la note n'est pas garantie d'être stockée car tout est conservé dans la mémoire vive, si elle se remplit les notes les plus anciennes seront supprimées.
(vous serez probablement bien, soyez juste averti.)", "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." + "note_error": "n'a pas pu créer de note. Veuillez réessayer.", + "max": "max: {n}" }, "copied_to_clipboard": "copié dans le presse-papiers 🔗" }, diff --git a/frontend/locales/it.json b/frontend/locales/it.json index 100355e..dc56a54 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -19,7 +19,8 @@ "new_note_notice": "disponibilità:
la nota non è garantita per essere memorizzata come tutto è tenuto in ram, se si riempie le note più vecchie saranno rimosse.
(probabilmente andrà bene, basta essere avvertiti).", "errors": { "note_to_big": "impossibile creare una nota. la nota è troppo grande", - "note_error": "Impossibile creare la nota. Riprova." + "note_error": "Impossibile creare la nota. Riprova.", + "max": "max: {n}" }, "copied_to_clipboard": "copiato negli appunti 🔗" }, diff --git a/frontend/src/lib/ui/Switch.svelte b/frontend/src/lib/ui/Switch.svelte index e170884..ec419da 100644 --- a/frontend/src/lib/ui/Switch.svelte +++ b/frontend/src/lib/ui/Switch.svelte @@ -49,7 +49,7 @@ height: 2rem; width: 1.25rem; left: 0.125rem; - bottom: 0.1rem; + bottom: 0.125rem; background-color: var(--ui-bg-1); -webkit-transition: 0.4s; transition: var(--ui-anim); diff --git a/frontend/src/lib/ui/TextInput.svelte b/frontend/src/lib/ui/TextInput.svelte index da8d9ee..9fb6b4f 100644 --- a/frontend/src/lib/ui/TextInput.svelte +++ b/frontend/src/lib/ui/TextInput.svelte @@ -1,15 +1,13 @@