Skip to main content

proto_blue_api/generated/tools/ozone/server/
getConfig.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: tools.ozone.server.getConfig
3#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7/// Get details about ozone's server configuration.
8/// XRPC Query: tools.ozone.server.getConfig
9#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct Output {
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub appview: Option<ServiceConfig>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub blob_divert: Option<ServiceConfig>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub chat: Option<ServiceConfig>,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub pds: Option<ServiceConfig>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub verifier_did: Option<proto_blue_syntax::Did>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub viewer: Option<ViewerConfig>,
24}
25
26/// Errors a `call()` on this method can return.
27#[derive(Debug, thiserror::Error)]
28pub enum CallError {
29    #[error("{0}")]
30    Xrpc(proto_blue_xrpc::XrpcError),
31    #[error(transparent)]
32    Transport(#[from] proto_blue_xrpc::Error),
33    #[error(transparent)]
34    Json(#[from] serde_json::Error),
35}
36
37fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
38    CallError::Xrpc(err)
39}
40
41/// Execute the query.
42pub async fn call(
43    client: &proto_blue_xrpc::XrpcClient,
44    opts: Option<&proto_blue_xrpc::CallOptions>,
45) -> Result<Output, CallError> {
46    let response = match client
47        .query("tools.ozone.server.getConfig", None, opts)
48        .await
49    {
50        Ok(r) => r,
51        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
52        Err(e) => return Err(CallError::Transport(e)),
53    };
54    Ok(serde_json::from_value(response.data)?)
55}
56
57/// Register a typed handler for this method on an [`proto_blue_xrpc::XrpcServer`].
58#[cfg(feature = "server")]
59pub fn register<F, Fut>(
60    server: proto_blue_xrpc::XrpcServer,
61    handler: F,
62) -> proto_blue_xrpc::XrpcServer
63where
64    F: Fn(proto_blue_xrpc::HandlerContext) -> Fut + Send + Sync + 'static,
65    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
66        + Send
67        + 'static,
68{
69    let handler = std::sync::Arc::new(handler);
70    server.query("tools.ozone.server.getConfig", move |ctx| {
71        let handler = handler.clone();
72        async move {
73            let out = handler(ctx).await?;
74            let value = serde_json::to_value(&out).map_err(|e| {
75                proto_blue_xrpc::XrpcServerError::new(
76                    proto_blue_xrpc::ResponseType::InternalServerError,
77                    format!("output serialize: {e}"),
78                )
79            })?;
80            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
81        }
82    })
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(rename_all = "camelCase")]
87pub struct ServiceConfig {
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub url: Option<String>,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(rename_all = "camelCase")]
94pub struct ViewerConfig {
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub role: Option<String>,
97}