From ce75fe6572565ccb68ec06173caf1065bf726cda Mon Sep 17 00:00:00 2001 From: SadlyNotSappho Date: Fri, 1 Sep 2023 11:49:03 -0700 Subject: [PATCH] stop it from redownloading already cached files (or pages but i guess you could use the function for anything) --- src/cache.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cache.rs b/src/cache.rs index 1198647..40c28db 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,9 +1,13 @@ -use std::{fs, process}; +use std::{fs, process, path::Path}; pub async fn download_image(cache_path: &str, image_url: String, file_name: String) { let replaced = cache_path.replace('~', &crate::get_home()[..]); // replace ~ with $HOME crate::ensure_exists(&replaced); + if Path::new(&format!("{cache_path}/{file_name}")).exists() { + return + } + let image = match reqwest::get(image_url).await { Ok(image) => match image.bytes().await { Ok(bytes) => bytes,