proto_blue_api/generated/com/atproto/sync/
getHostStatus.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Params {
11 pub hostname: String,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Output {
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub account_count: Option<i64>,
19 pub hostname: String,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub seq: Option<i64>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 pub status: Option<crate::com::atproto::sync::defs::HostStatus>,
24}
25
26#[derive(Debug, thiserror::Error)]
28pub enum CallError {
29 #[error("HostNotFound")]
30 HostNotFound,
31 #[error("{0}")]
32 Xrpc(proto_blue_xrpc::XrpcError),
33 #[error(transparent)]
34 Transport(#[from] proto_blue_xrpc::Error),
35 #[error(transparent)]
36 Json(#[from] serde_json::Error),
37}
38
39fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
40 match err.error.as_deref() {
41 Some("HostNotFound") => CallError::HostNotFound,
42 _ => CallError::Xrpc(err),
43 }
44}
45
46fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
47 let mut qp = proto_blue_xrpc::QueryParams::new();
48 {
49 let v = &p.hostname;
50 qp.insert(
51 "hostname".to_string(),
52 proto_blue_xrpc::QueryValue::String(v.clone()),
53 );
54 }
55 qp
56}
57
58pub async fn call(
60 client: &proto_blue_xrpc::XrpcClient,
61 params: Option<&Params>,
62 opts: Option<&proto_blue_xrpc::CallOptions>,
63) -> Result<Output, CallError> {
64 let qp = params.map(to_query_params);
65 let response = match client
66 .query("com.atproto.sync.getHostStatus", qp.as_ref(), opts)
67 .await
68 {
69 Ok(r) => r,
70 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
71 Err(e) => return Err(CallError::Transport(e)),
72 };
73 Ok(serde_json::from_value(response.data)?)
74}
75
76#[cfg(feature = "server")]
78pub fn register<F, Fut>(
79 server: proto_blue_xrpc::XrpcServer,
80 handler: F,
81) -> proto_blue_xrpc::XrpcServer
82where
83 F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
84 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
85 + Send
86 + 'static,
87{
88 let handler = std::sync::Arc::new(handler);
89 server.query("com.atproto.sync.getHostStatus", move |ctx| {
90 let handler = handler.clone();
91 async move {
92 let params = params_from_ctx(&ctx);
93 let out = handler(ctx, params).await?;
94 let value = serde_json::to_value(&out).map_err(|e| {
95 proto_blue_xrpc::XrpcServerError::new(
96 proto_blue_xrpc::ResponseType::InternalServerError,
97 format!("output serialize: {e}"),
98 )
99 })?;
100 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
101 }
102 })
103}
104
105#[cfg(feature = "server")]
106fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
107 Some(Params {
111 hostname: (ctx.params.get("hostname").cloned())?,
112 })
113}