Add NHENTAIRS_INSECURE

This commit is contained in:
blankie 2023-10-28 11:25:53 +11:00
parent c2ea9b87b0
commit dd62cc2c19
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
4 changed files with 26 additions and 3 deletions

View File

@ -1,7 +1,30 @@
use crate::structs; use crate::structs;
use std::env;
use std::process::exit;
extern crate serde_json; extern crate serde_json;
pub fn get_client() -> reqwest::Client {
let mut builder = reqwest::Client::builder();
match env::var("NHENTAIRS_INSECURE") {
Ok(val) => {
if val == "true" || val == "yes" || val == "1" {
builder = builder.danger_accept_invalid_certs(true);
}
}
Err(env::VarError::NotPresent) => {}
Err(err) => eprintln!("failed to parse NHENTAIRS_INSECURE: {err}"),
};
match builder.build() {
Ok(client) => client,
Err(err) => {
eprintln!("Failed to create reqwest client: {err}");
exit(1);
}
}
}
pub async fn get_sauce_info( pub async fn get_sauce_info(
client: reqwest::Client, client: reqwest::Client,
sauce: i32, sauce: i32,

View File

@ -24,7 +24,7 @@ pub async fn run(args: env::Args) {
eprintln!("Missing sauce(s)"); eprintln!("Missing sauce(s)");
exit(1); exit(1);
} }
let client = reqwest::Client::new(); let client = api::get_client();
let mut pages_vec: Vec<(String, String)> = Vec::new(); let mut pages_vec: Vec<(String, String)> = Vec::new();
{ {
let mut handles: Vec<JoinHandle<structs::GalleryInfoSuccess>> = let mut handles: Vec<JoinHandle<structs::GalleryInfoSuccess>> =

View File

@ -14,7 +14,7 @@ pub async fn run(args: env::Args) {
eprintln!("Missing search query"); eprintln!("Missing search query");
exit(1); exit(1);
} }
let search_info = api::get_search_info(reqwest::Client::new(), &query) let search_info = api::get_search_info(api::get_client(), &query)
.await .await
.unwrap(); .unwrap();
if search_info.num_pages < 1 { if search_info.num_pages < 1 {

View File

@ -14,7 +14,7 @@ pub async fn run(args: env::Args) {
eprintln!("Missing sauce(s)"); eprintln!("Missing sauce(s)");
exit(1); exit(1);
} }
let client = reqwest::Client::new(); let client = api::get_client();
let mut handles: Vec<JoinHandle<(structs::GalleryInfo, i32)>> = let mut handles: Vec<JoinHandle<(structs::GalleryInfo, i32)>> =
Vec::with_capacity(sauces.len()); Vec::with_capacity(sauces.len());
for sauce in sauces { for sauce in sauces {