From 2fb68202a88f2abfc80d88d2237b2ba190af2905 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 12 Aug 2023 13:56:09 -0700 Subject: [PATCH 1/3] utils: remove link to issues page in nothuman error --- utils/src/error.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/utils/src/error.rs b/utils/src/error.rs index 0f2502b..992ff53 100644 --- a/utils/src/error.rs +++ b/utils/src/error.rs @@ -40,9 +40,7 @@ impl ResponseError for Error { Self::NotHuman { target } => format!( "It looks like you're accessing the Tatoeba API proxy from a script!\n\ Tatoeba CORS restrictions do not apply outside of browsers, so please access the API directly:\n\ - {target}\n\ - If you feel this is mistake, please open an issue:\n\ - https://codeberg.org/ElnuDev/tatoeba-api-rs"), + {target}"), _ => self.to_string(), }) } From 18f64358f01e8b233dd663a475f4c5de61c09259 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 12 Aug 2023 13:58:11 -0700 Subject: [PATCH 2/3] images: remove /search route prefix --- images/src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/images/src/main.rs b/images/src/main.rs index 268f72b..c91ca54 100644 --- a/images/src/main.rs +++ b/images/src/main.rs @@ -43,7 +43,7 @@ where }) } -#[get("/search/{query}/list")] +#[get("/{query}/list")] async fn route_query_list(path: web::Path) -> Result { let query = path.into_inner(); let images = get_images(&query).await?; @@ -52,19 +52,19 @@ async fn route_query_list(path: web::Path) -> Result { .body(serde_json::to_string(&images).unwrap_or_else(|_| "[]".to_string()))) } -#[get("/search/{query}")] +#[get("/{query}")] async fn route_query(path: web::Path) -> Result { let query = path.into_inner(); route(&query, |images| images.get(0)).await } -#[get("/search/{query}/random")] +#[get("/{query}/random")] async fn route_query_random(path: web::Path) -> Result { let query = path.into_inner(); route(&query, |images| images.choose(&mut rand::thread_rng())).await } -#[get("/search/{query}/{index}")] +#[get("/{query}/{index}")] async fn route_query_index(path: web::Path<(String, usize)>) -> Result { let (query, index) = path.into_inner(); route(&query, move |images| images.get(index % images.len())).await From 412ca4e53890761467de233cf0ed37bebbc8eeac Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 12 Aug 2023 13:58:28 -0700 Subject: [PATCH 3/3] cargo fmt --- images/src/main.rs | 2 +- tatoeba/src/main.rs | 7 +++++-- utils/src/error.rs | 5 +++-- utils/src/is_human.rs | 8 ++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/images/src/main.rs b/images/src/main.rs index c91ca54..00d18c7 100644 --- a/images/src/main.rs +++ b/images/src/main.rs @@ -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, } diff --git a/tatoeba/src/main.rs b/tatoeba/src/main.rs index 2fe39ec..630091d 100644 --- a/tatoeba/src/main.rs +++ b/tatoeba/src/main.rs @@ -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, } diff --git a/utils/src/error.rs b/utils/src/error.rs index 992ff53..b248336 100644 --- a/utils/src/error.rs +++ b/utils/src/error.rs @@ -11,7 +11,9 @@ pub type Result = std::result::Result; 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 { }) } } - diff --git a/utils/src/is_human.rs b/utils/src/is_human.rs index b9ba6eb..eef95b9 100644 --- a/utils/src/is_human.rs +++ b/utils/src/is_human.rs @@ -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) -} \ No newline at end of file +}