diff --git a/proxy/api/src/http.rs b/proxy/api/src/http.rs index 3360771ae2..58b1787216 100644 --- a/proxy/api/src/http.rs +++ b/proxy/api/src/http.rs @@ -7,7 +7,6 @@ use radicle_daemon::{net, signer::BoxedSigner, state, LocalIdentity, PeerId}; use crate::{context, notification::Subscriptions}; -mod avatar; mod control; mod error; mod identity; @@ -41,7 +40,6 @@ pub fn api( ) -> impl Filter + Clone { let test = ctx.test(); - let avatar_filter = path("avatars").and(avatar::get_filter()); let control_filter = path("control") .map(move || test) .and_then(|enable| async move { @@ -62,7 +60,6 @@ pub fn api( let source_filter = path("source").and(source::filters(ctx)); let api = path("v1").and(combine!( - avatar_filter, control_filter, identity_filter, notification_filter, diff --git a/proxy/api/src/http/avatar.rs b/proxy/api/src/http/avatar.rs deleted file mode 100644 index c083ee7402..0000000000 --- a/proxy/api/src/http/avatar.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! Endpoints for Avatar. - -use serde::Deserialize; -use warp::{filters::BoxedFilter, path, Filter, Reply}; - -/// `GET /?usage=` -pub fn get_filter() -> BoxedFilter<(impl Reply,)> { - warp::any() - .and(warp::get()) - .and(path::param::()) - .and(warp::filters::query::query::()) - .and_then(handler::get) - .boxed() -} - -/// Avatar handlers for conversion between core domain and http request fullfilment. -mod handler { - use warp::{http::StatusCode, reply, Rejection, Reply}; - - use radicle_avatar as avatar; - - use crate::http::error; - - /// Get the avatar for the given `id`. - #[allow(clippy::wildcard_enum_match_arm)] - pub async fn get( - id: String, - super::GetAvatarQuery { usage }: super::GetAvatarQuery, - ) -> Result { - let avatar = avatar::Avatar::from( - &id, - match usage.as_deref() { - Some("identity") => avatar::Usage::Identity, - Some("any") | None => avatar::Usage::Any, - _ => { - return Ok(reply::with_status( - reply::json(&error::Error { - message: "BAD_REQUEST".to_string(), - variant: "Invalid query input".to_string(), - }), - StatusCode::BAD_REQUEST, - )) - }, - }, - ); - - Ok(reply::with_status(reply::json(&avatar), StatusCode::OK)) - } -} - -/// Bundled query params to pass to the avatar handler. -#[derive(Debug, Deserialize)] -pub struct GetAvatarQuery { - /// Kind of avatar usage. - usage: Option, -} - -#[allow(clippy::non_ascii_literal, clippy::unwrap_used)] -#[cfg(test)] -mod test { - use pretty_assertions::assert_eq; - use serde_json::{json, Value}; - use warp::{http::StatusCode, test::request}; - - #[tokio::test] - async fn get() { - let api = super::get_filter(); - let res = request() - .method("GET") - .path(&format!("/{}?usage={}", "monadic", "any")) - .reply(&api) - .await; - - let have: Value = serde_json::from_slice(res.body()).unwrap(); - - assert_eq!(res.status(), StatusCode::OK); - assert_eq!( - have, - json!({ - "background": { - "r": 148, - "g": 187, - "b": 61, - }, - "emoji": "🎮", - }) - ); - } -}