diff --git a/images/src/main.rs b/images/src/main.rs index 00d18c7..268f72b 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("/{query}/list")] +#[get("/search/{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("/{query}")] +#[get("/search/{query}")] async fn route_query(path: web::Path) -> Result { let query = path.into_inner(); route(&query, |images| images.get(0)).await } -#[get("/{query}/random")] +#[get("/search/{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("/{query}/{index}")] +#[get("/search/{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 630091d..2fe39ec 100644 --- a/tatoeba/src/main.rs +++ b/tatoeba/src/main.rs @@ -1,7 +1,4 @@ -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; @@ -12,7 +9,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 b248336..0f2502b 100644 --- a/utils/src/error.rs +++ b/utils/src/error.rs @@ -11,9 +11,7 @@ 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 { @@ -42,8 +40,11 @@ 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}"), + {target}\n\ + If you feel this is mistake, please open an issue:\n\ + https://codeberg.org/ElnuDev/tatoeba-api-rs"), _ => self.to_string(), }) } } + diff --git a/utils/src/is_human.rs b/utils/src/is_human.rs index eef95b9..b9ba6eb 100644 --- a/utils/src/is_human.rs +++ b/utils/src/is_human.rs @@ -12,6 +12,10 @@ 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