diff --git a/src/main.rs b/src/main.rs index d643d2b..698cbed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -174,15 +174,6 @@ async fn create_thumbnails() { let thumbs = &dotenv::var("THUMBNAILS").expect("THUMBNAILS not defined"); let thumbnail_directory: &Path = Path::new(thumbs); - let t: Vec<_> = thumbnail_directory - .read_dir() - .expect("Error reading thumbnail directory") - .collect(); - if !t.is_empty() { - println!("Skipping thumbs"); - return; - } - let images = PathBuf::from(dotenv::var("BASE_PATH").unwrap()); walkdir::WalkDir::new(&images) @@ -211,6 +202,12 @@ async fn create_thumbnails() { false } }) + .filter(|entry| { + let path = entry.path(); + let relative_path = &path.strip_prefix(&images).unwrap(); + let thumb_path = Path::new(thumbnail_directory).join(relative_path); + return !thumb_path.exists(); + }) .map(|entry| (image::open(entry.path()), entry.path().to_path_buf())) .filter(|(img, _)| img.is_ok()) .map(|(img, path)| (img.unwrap(), path))