From 1ebbe5d92255b5ab3bb5137f51067e0d7a6e055a Mon Sep 17 00:00:00 2001 From: Jade Date: Mon, 27 Feb 2023 00:47:40 +0100 Subject: [PATCH] added embedded images at pasta view --- src/endpoints/info.rs | 4 ++++ src/pasta.rs | 6 ++++++ templates/pasta.html | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/src/endpoints/info.rs b/src/endpoints/info.rs index 7230050..173ac05 100644 --- a/src/endpoints/info.rs +++ b/src/endpoints/info.rs @@ -21,6 +21,10 @@ pub async fn info(data: web::Data) -> HttpResponse { let pastas = data.pastas.lock().await; // TODO: status report more sophisticated + // maybe: + // - detect weird/invalid configurations? + // - detect server storage issues + // - detect performance problems? let mut status = "OK"; let mut message = ""; diff --git a/src/pasta.rs b/src/pasta.rs index 5ac74d5..b771c66 100644 --- a/src/pasta.rs +++ b/src/pasta.rs @@ -30,6 +30,12 @@ impl PastaFile { pub fn name(&self) -> &str { &self.name } + + /// Check if file is an image for embedding + pub fn is_image(&self) -> bool { + let guess = mime_guess::from_path(&self.name).first_or_text_plain(); + guess.type_() == "image" + } } #[derive(Serialize, Deserialize)] diff --git a/templates/pasta.html b/templates/pasta.html index 5a32196..d41742e 100644 --- a/templates/pasta.html +++ b/templates/pasta.html @@ -32,6 +32,10 @@ {% if pasta.file.is_some() %}

+{% if pasta.file.as_ref().unwrap().is_image() %} + +
+{%- endif %} Download attached file: '{{pasta.file.as_ref().unwrap().name()}}' [{{pasta.file.as_ref().unwrap().size}}]