feat: initial work on tenor gif searching

This commit is contained in:
Zomatree
2025-08-08 00:16:20 +01:00
committed by Angelo Kontaxis
parent bfe4018e43
commit b0c977b324
20 changed files with 1268 additions and 524 deletions

View File

@@ -0,0 +1,64 @@
use std::sync::Arc;
use axum::{extract::{Query, State}, routing::get, Json, Router};
use revolt_result::{create_error, Result};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::tenor::{Tenor, types};
pub async fn router() -> Router<Tenor> {
Router::new()
.route("/", get(root))
.route("/search", get(search))
}
/// Successful root response
#[derive(Serialize, Debug, ToSchema)]
pub struct RootResponse {
message: &'static str,
version: &'static str,
}
/// Capture crate version from Cargo
static CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");
/// Root response from service
#[utoipa::path(
get,
path = "/",
responses(
(status = 200, description = "Echo response", body = RootResponse)
)
)]
async fn root() -> Json<RootResponse> {
Json(RootResponse {
message: "Gifbox lives on!",
version: CRATE_VERSION,
})
}
#[derive(Deserialize)]
struct SearchQueryParams {
pub query: String,
pub locale: String,
pub position: Option<String>
}
#[utoipa::path(
get,
path = "/search",
responses(
(status = 200, description = "Search results", body = SearchResponse)
)
)]
async fn search(
Query(params): Query<SearchQueryParams>,
State(tenor): State<Tenor>,
) -> Result<Json<Arc<types::SearchResponse>>> {
// Todo
tenor.search(&params.query, &params.locale, params.position.as_deref())
.await
.map_err(|_| create_error!(InternalError))
.map(Json)
}