Scan for new files every startup

This commit is contained in:
Cameron Cordes
2020-08-07 21:38:00 -04:00
parent a300b78fd0
commit 74043c5c6a

View File

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