stop it from redownloading already cached files (or pages but i guess you could use the function for anything)

This commit is contained in:
SadlyNotSappho 2023-09-01 11:49:03 -07:00
parent 90a305f55f
commit ce75fe6572
1 changed files with 5 additions and 1 deletions

View File

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