fixes and cleanup

This commit is contained in:
Simon
2026-03-05 18:18:48 +00:00
parent 76fd5a4f4f
commit 2627505ade
49 changed files with 3245 additions and 1376 deletions

View File

@@ -1,17 +1,17 @@
use serde::Serialize;
use wreq::multipart::Form;
use std::env;
use wreq::Client;
use wreq::Proxy;
use wreq::Response;
use wreq::Version;
use wreq::header::HeaderValue;
use wreq::multipart::Form;
use wreq::redirect::Policy;
use wreq_util::Emulation;
use crate::util::proxy;
use crate::util::flaresolverr::FlareSolverrRequest;
use crate::util::flaresolverr::Flaresolverr;
use crate::util::proxy;
// A Send + Sync error type for all async paths
type AnyErr = Box<dyn std::error::Error + Send + Sync + 'static>;
@@ -99,7 +99,7 @@ impl Requester {
request.send().await
}
pub async fn post_json<S>(
pub async fn post_json<S>(
&mut self,
url: &str,
data: &S,
@@ -131,7 +131,11 @@ pub async fn post_json<S>(
data: &str,
headers: Vec<(&str, &str)>,
) -> Result<Response, wreq::Error> {
let mut request = self.client.post(url).version(Version::HTTP_11).body(data.to_string());
let mut request = self
.client
.post(url)
.version(Version::HTTP_11)
.body(data.to_string());
// Set custom headers
for (key, value) in headers.iter() {
@@ -154,8 +158,7 @@ pub async fn post_json<S>(
form: Form,
headers: Vec<(String, String)>,
_http_version: Option<Version>,
) -> Result<Response, wreq::Error>
{
) -> Result<Response, wreq::Error> {
let http_version = match _http_version {
Some(v) => v,
None => Version::HTTP_11,
@@ -178,7 +181,11 @@ pub async fn post_json<S>(
request.send().await
}
pub async fn get(&mut self, url: &str, _http_version: Option<Version>) -> Result<String, AnyErr> {
pub async fn get(
&mut self,
url: &str,
_http_version: Option<Version>,
) -> Result<String, AnyErr> {
let http_version = match _http_version {
Some(v) => v,
None => Version::HTTP_11,
@@ -190,7 +197,7 @@ pub async fn post_json<S>(
let proxy = Proxy::all(&proxy_url).unwrap();
request = request.proxy(proxy);
}
}
}
let response = request.send().await?;
if response.status().is_success() || response.status().as_u16() == 404 {
return Ok(response.text().await?);
@@ -208,7 +215,6 @@ pub async fn post_json<S>(
}
}
// If direct request failed, try FlareSolverr. Map its error to a Send+Sync error immediately,
// so no non-Send error value lives across later `.await`s.
let flare_url = match env::var("FLARE_URL") {