remove some comments and add some horrible error handling

This commit is contained in:
SadlyNotSappho 2023-08-29 14:20:11 -07:00
parent 1367f2d684
commit d8d3311d25
2 changed files with 24 additions and 11 deletions

View File

@ -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:?}");

View File

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