added embedded images at pasta view

This commit is contained in:
Schrottkatze 2023-02-27 00:47:40 +01:00
parent 51751e3ee2
commit 1ebbe5d922
3 changed files with 14 additions and 0 deletions

View file

@ -21,6 +21,10 @@ pub async fn info(data: web::Data<AppState>) -> 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 = "";

View file

@ -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)]

View file

@ -32,6 +32,10 @@
{% if pasta.file.is_some() %}
<br>
<br>
{% if pasta.file.as_ref().unwrap().is_image() %}
<img src="{{ args.public_path }}/file/{{pasta.id_as_animals()}}/{{pasta.file.as_ref().unwrap().name()}}" alt="">
<br>
{%- endif %}
<a href="{{ args.public_path }}/file/{{pasta.id_as_animals()}}/{{pasta.file.as_ref().unwrap().name()}}" download>
Download attached file: '{{pasta.file.as_ref().unwrap().name()}}' [{{pasta.file.as_ref().unwrap().size}}]
</a>