diff --git a/src/api.rs b/src/api.rs index df30bb1..79f8950 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,7 +1,30 @@ use crate::structs; +use std::env; +use std::process::exit; + 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( client: reqwest::Client, sauce: i32, diff --git a/src/commands/download.rs b/src/commands/download.rs index a7b52ba..1b7d164 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -24,7 +24,7 @@ pub async fn run(args: env::Args) { eprintln!("Missing sauce(s)"); exit(1); } - let client = reqwest::Client::new(); + let client = api::get_client(); let mut pages_vec: Vec<(String, String)> = Vec::new(); { let mut handles: Vec> = diff --git a/src/commands/search.rs b/src/commands/search.rs index ae09d29..2603741 100644 --- a/src/commands/search.rs +++ b/src/commands/search.rs @@ -14,7 +14,7 @@ pub async fn run(args: env::Args) { eprintln!("Missing search query"); 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 .unwrap(); if search_info.num_pages < 1 { diff --git a/src/commands/view.rs b/src/commands/view.rs index d895f8a..8867127 100644 --- a/src/commands/view.rs +++ b/src/commands/view.rs @@ -14,7 +14,7 @@ pub async fn run(args: env::Args) { eprintln!("Missing sauce(s)"); exit(1); } - let client = reqwest::Client::new(); + let client = api::get_client(); let mut handles: Vec> = Vec::with_capacity(sauces.len()); for sauce in sauces {