start reworking cache system (it will not compile and my brain has died)

This commit is contained in:
SadlyNotSappho 2023-09-01 11:56:12 -07:00
parent ce75fe6572
commit 5b69c68f24
3 changed files with 9 additions and 3 deletions

View File

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

View File

@ -144,6 +144,7 @@ pub struct Page {
pub next_page: Option<String>,
pub prev_page: Option<String>,
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,
}
}

View File

@ -22,5 +22,5 @@ async fn main() {
let current_page = ggg::get_page(&config.latest_date).await;
println!("image url: {}\ncache folder: {}", &current_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;
}