|
|
@ -34,7 +34,7 @@ where
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/{query}/list")]
|
|
|
|
#[get("/search/{query}/list")]
|
|
|
|
async fn route_query_list(path: web::Path<String>) -> Result<impl Responder> {
|
|
|
|
async fn route_query_list(path: web::Path<String>) -> Result<impl Responder> {
|
|
|
|
let query = path.into_inner();
|
|
|
|
let query = path.into_inner();
|
|
|
|
let images = get_images(&query).await?;
|
|
|
|
let images = get_images(&query).await?;
|
|
|
@ -43,19 +43,19 @@ async fn route_query_list(path: web::Path<String>) -> Result<impl Responder> {
|
|
|
|
.body(serde_json::to_string(&images).unwrap_or_else(|_| "[]".to_string())))
|
|
|
|
.body(serde_json::to_string(&images).unwrap_or_else(|_| "[]".to_string())))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/{query}")]
|
|
|
|
#[get("/search/{query}")]
|
|
|
|
async fn route_query(path: web::Path<String>) -> Result<impl Responder> {
|
|
|
|
async fn route_query(path: web::Path<String>) -> Result<impl Responder> {
|
|
|
|
let query = path.into_inner();
|
|
|
|
let query = path.into_inner();
|
|
|
|
route(&query, |images| images.get(0)).await
|
|
|
|
route(&query, |images| images.get(0)).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/{query}/random")]
|
|
|
|
#[get("/search/{query}/random")]
|
|
|
|
async fn route_query_random(path: web::Path<String>) -> Result<impl Responder> {
|
|
|
|
async fn route_query_random(path: web::Path<String>) -> Result<impl Responder> {
|
|
|
|
let query = path.into_inner();
|
|
|
|
let query = path.into_inner();
|
|
|
|
route(&query, |images| images.choose(&mut rand::thread_rng())).await
|
|
|
|
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<impl Responder> {
|
|
|
|
async fn route_query_index(path: web::Path<(String, usize)>) -> Result<impl Responder> {
|
|
|
|
let (query, index) = path.into_inner();
|
|
|
|
let (query, index) = path.into_inner();
|
|
|
|
route(&query, move |images| images.get(index % images.len())).await
|
|
|
|
route(&query, move |images| images.get(index % images.len())).await
|
|
|
|