proto_blue_api/generated/com/atproto/server/
describeServer.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct Contact {
9 #[serde(skip_serializing_if = "Option::is_none")]
10 pub email: Option<String>,
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct Links {
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub privacy_policy: Option<String>,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub terms_of_service: Option<String>,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct Output {
27 pub available_user_domains: Vec<String>,
28 #[serde(skip_serializing_if = "Option::is_none")]
29 pub contact: Option<Contact>,
30 pub did: String,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 pub invite_code_required: Option<bool>,
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub links: Option<Links>,
35 #[serde(skip_serializing_if = "Option::is_none")]
36 pub phone_verification_required: Option<bool>,
37}
38
39#[derive(Debug, thiserror::Error)]
41pub enum CallError {
42 #[error("{0}")]
43 Xrpc(proto_blue_xrpc::XrpcError),
44 #[error(transparent)]
45 Transport(#[from] proto_blue_xrpc::Error),
46 #[error(transparent)]
47 Json(#[from] serde_json::Error),
48}
49
50fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
51 CallError::Xrpc(err)
52}
53
54pub async fn call(
56 client: &proto_blue_xrpc::XrpcClient,
57 opts: Option<&proto_blue_xrpc::CallOptions>,
58) -> Result<Output, CallError> {
59 let response = match client
60 .query("com.atproto.server.describeServer", None, opts)
61 .await
62 {
63 Ok(r) => r,
64 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
65 Err(e) => return Err(CallError::Transport(e)),
66 };
67 Ok(serde_json::from_value(response.data)?)
68}
69
70#[cfg(feature = "server")]
72pub fn register<F, Fut>(
73 server: proto_blue_xrpc::XrpcServer,
74 handler: F,
75) -> proto_blue_xrpc::XrpcServer
76where
77 F: Fn(proto_blue_xrpc::HandlerContext) -> Fut + Send + Sync + 'static,
78 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
79 + Send
80 + 'static,
81{
82 let handler = std::sync::Arc::new(handler);
83 server.query("com.atproto.server.describeServer", move |ctx| {
84 let handler = handler.clone();
85 async move {
86 let out = handler(ctx).await?;
87 let value = serde_json::to_value(&out).map_err(|e| {
88 proto_blue_xrpc::XrpcServerError::new(
89 proto_blue_xrpc::ResponseType::InternalServerError,
90 format!("output serialize: {e}"),
91 )
92 })?;
93 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
94 }
95 })
96}