diff --git a/images/src/main.rs b/images/src/main.rs index 268f72b..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, } @@ -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 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 0f2502b..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 { @@ -40,11 +42,8 @@ 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(), }) } } - 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 +}