diff --git a/src/cache.rs b/src/cache.rs index 40c28db..7683c62 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -4,7 +4,7 @@ pub async fn download_image(cache_path: &str, image_url: String, file_name: Stri let replaced = cache_path.replace('~', &crate::get_home()[..]); // replace ~ with $HOME crate::ensure_exists(&replaced); - if Path::new(&format!("{cache_path}/{file_name}")).exists() { + if Path::new(&format!("{cache_path}/{file_name}.json")).exists() { return } @@ -24,7 +24,7 @@ pub async fn download_image(cache_path: &str, image_url: String, file_name: Stri // println!("{replaced}/{file_name}"); - let wrote = fs::write(format!("{replaced}/{file_name}"), image); + let wrote = fs::write(format!("{replaced}/images/{file_name}.jpg"), image); if let Err(why) = wrote { eprintln!("cache::download_image: Couldn't save the image to `{replaced}/{file_name}`: {why:?}"); process::exit(1); diff --git a/src/lib.rs b/src/lib.rs index 7ffda28..ef88d0a 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -144,6 +144,7 @@ pub struct Page { pub next_page: Option, pub prev_page: Option, pub image: String, + pub cached: bool } pub async fn get_page(date: &str) -> Page { @@ -190,10 +191,15 @@ pub async fn get_page(date: &str) -> Page { prev_page = Some(element.value().attr("href").unwrap().to_string()); } + // check if cache/date.json exists + // if it does, cached = true + // if it doesn't, cached = false + Page { date: date.to_string(), next_page, prev_page, image, + cached, } } diff --git a/src/main.rs b/src/main.rs index 739a30e..a2f394f 100755 --- a/src/main.rs +++ b/src/main.rs @@ -22,5 +22,5 @@ async fn main() { let current_page = ggg::get_page(&config.latest_date).await; println!("image url: {}\ncache folder: {}", ¤t_page.image, &config.cache_folder); - cache::download_image(&config.cache_folder.replace('~', &ggg::get_home()[..]), current_page.image, format!("{}.jpg", current_page.date)).await; + cache::download_image(&config.cache_folder.replace('~', &ggg::get_home()[..]), current_page.image, current_page.date).await; }