diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-06-19 19:47:50 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-06-19 19:47:50 -0400 |
| commit | e1cae593b1acde2d5552dfbae8367c6b0a726d5c (patch) | |
| tree | b33836cf52838788303e8e16fa125910505252df /src | |
| parent | 4e9f8ff708dae197416e17fca29862194de4c25a (diff) | |
[birka-web] implement a "missing thumbnail" for non-image files.
Diffstat (limited to 'src')
| -rw-r--r-- | src/birka-web.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/birka-web.rs b/src/birka-web.rs index b4d1d12..0bbaf59 100644 --- a/src/birka-web.rs +++ b/src/birka-web.rs @@ -319,11 +319,18 @@ fn add_to_store(file: &database::File, file_dir: &str) { let thumb_path = thumb_filename(file.id, &file.path); let thumb_path = Path::new(file_dir).join(&thumb_path); if !thumb_path.exists() { - let im = image::open(store_path).unwrap(); - let out = &mut File::create(&thumb_path).unwrap(); - im.thumbnail(100, 100) - .write_to(out, ImageFormat::Png) - .unwrap(); + if let Ok(im) = image::open(&store_path) { + let out = &mut File::create(&thumb_path).unwrap(); + im.thumbnail(100, 100) + .write_to(out, ImageFormat::Png) + .unwrap(); + } else { + let src = Path::new("./static/img/missing_thumb.png"); + symlink(src.canonicalize().unwrap(), &thumb_path).unwrap(); + if !thumb_path.exists() { + panic!("could not create symlink {:?}!", thumb_path); + } + } } } |