Scan for new files every startup
This commit is contained in:
15
src/main.rs
15
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))
|
||||
|
||||
Reference in New Issue
Block a user