diff --git a/src/cache.rs b/src/cache.rs index 7672591..fd90c15 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -17,12 +17,9 @@ pub async fn download_image(cache_path: &String, image_url: String, file_name: S process::exit(1); } }; - // println!("{image:?}"); - // println!("{}", yansi::Color::Magenta.paint(filename.clone())); - - // println!("{}", yansi::Color::Magenta.paint(filepath.clone())); - println!("{replaced}/{file_name}"); + // println!("{replaced}/{file_name}"); + let wrote = fs::write(format!("{replaced}/{file_name}"), image); if let Err(why) = wrote { eprintln!("cache::download_image: Couldn't save the image to `{replaced}/{file_name}`: {why:?}"); diff --git a/src/lib.rs b/src/lib.rs index 41470fd..8384efb 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,17 +1,33 @@ pub mod cache; -use std::{fs, path::Path}; +use std::{fs, path::Path, process}; use scraper::{Html, Selector}; use serde::{Deserialize, Serialize}; pub fn get_home() -> String { match std::env::consts::OS { - "linux" => std::env::var("HOME").expect("how is there not a $HOME"), - "windows" => std::env::var("userprofile").expect("yell at me if this doesn't work please"), - _ => std::env::var("HOME").expect( - "if this doesn't work, you're probably on macos, which i literally cannot test on", - ), + "linux" => match std::env::var("HOME") { + Ok(var) => var, + Err(why) => { + eprintln!("lib::get_home: Couldn't get $HOME on Linux: {why:?}"); + process::exit(1); + } + }, + "windows" => match std::env::var("userprofile") { + Ok(var) => var, + Err(why) => { + eprintln!("lib::get_home: Couldn't get $userprofile on Windows: {why:?}"); + process::exit(1) + } + }, + _ => match std::env::var("HOME") { + Ok(var) => var, + Err(why) => { + eprintln!("lib::get_home: Couldn't get $HOME on other OS: {why:?}"); + process::exit(1) + } + } } }