main
Elnu 1 year ago
parent 18f64358f0
commit 412ca4e538

@ -10,7 +10,7 @@ pub const BING: &str = "https://www.bing.com/images/search";
#[command(author, version, about, long_about = None)]
struct Args {
/// The port at which to run.
#[arg(short, long, default_value_t=3002)]
#[arg(short, long, default_value_t = 3002)]
port: u16,
}

@ -1,4 +1,7 @@
use utils::{error::{Error, Result}, is_human};
use utils::{
error::{Error, Result},
is_human,
};
use actix_web::{get, http::header, App, HttpRequest, HttpResponse, HttpServer, Responder};
use clap::Parser;
@ -9,7 +12,7 @@ pub const TATOEBA_API: &str = "https://tatoeba.org/en/api_v0/search";
#[command(author, version, about, long_about = None)]
struct Args {
/// The port at which to run.
#[arg(short, long, default_value_t=3001)]
#[arg(short, long, default_value_t = 3001)]
port: u16,
}

@ -11,7 +11,9 @@ pub type Result<T> = std::result::Result<T, Error>;
pub enum Error {
Reqwest(reqwest::Error),
#[cfg(feature = "nothuman")]
NotHuman { target: String },
NotHuman {
target: String,
},
}
impl Display for Error {
@ -45,4 +47,3 @@ impl ResponseError for Error {
})
}
}

@ -12,10 +12,6 @@ pub fn is_human(request: &HttpRequest) -> bool {
.headers()
.get(header::USER_AGENT)
.and_then(|header| header.to_str().ok())
.map(|ua| {
HUMANS
.iter()
.any(|&human| ua.contains(human))
})
.map(|ua| HUMANS.iter().any(|&human| ua.contains(human)))
.unwrap_or(false)
}
Loading…
Cancel
Save