start reworking cache system (it will not compile and my brain has died)
This commit is contained in:
parent
ce75fe6572
commit
5b69c68f24
|
@ -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
|
let replaced = cache_path.replace('~', &crate::get_home()[..]); // replace ~ with $HOME
|
||||||
crate::ensure_exists(&replaced);
|
crate::ensure_exists(&replaced);
|
||||||
|
|
||||||
if Path::new(&format!("{cache_path}/{file_name}")).exists() {
|
if Path::new(&format!("{cache_path}/{file_name}.json")).exists() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ pub async fn download_image(cache_path: &str, image_url: String, file_name: Stri
|
||||||
|
|
||||||
// println!("{replaced}/{file_name}");
|
// 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 {
|
if let Err(why) = wrote {
|
||||||
eprintln!("cache::download_image: Couldn't save the image to `{replaced}/{file_name}`: {why:?}");
|
eprintln!("cache::download_image: Couldn't save the image to `{replaced}/{file_name}`: {why:?}");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
|
|
|
@ -144,6 +144,7 @@ pub struct Page {
|
||||||
pub next_page: Option<String>,
|
pub next_page: Option<String>,
|
||||||
pub prev_page: Option<String>,
|
pub prev_page: Option<String>,
|
||||||
pub image: String,
|
pub image: String,
|
||||||
|
pub cached: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_page(date: &str) -> Page {
|
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());
|
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 {
|
Page {
|
||||||
date: date.to_string(),
|
date: date.to_string(),
|
||||||
next_page,
|
next_page,
|
||||||
prev_page,
|
prev_page,
|
||||||
image,
|
image,
|
||||||
|
cached,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,5 @@ async fn main() {
|
||||||
let current_page = ggg::get_page(&config.latest_date).await;
|
let current_page = ggg::get_page(&config.latest_date).await;
|
||||||
|
|
||||||
println!("image url: {}\ncache folder: {}", ¤t_page.image, &config.cache_folder);
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue