about summary refs log tree commit diff
path: root/src/bin
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2025-04-09 23:31:02 +0300
committerVika <vika@fireburn.ru>2025-04-09 23:31:57 +0300
commit8826d9446e6c492db2243b9921e59ce496027bef (patch)
tree63738aa9001cb73b11cb0e974e93129bcdf1adbb /src/bin
parent519cadfbb298f50cbf819dde757037ab56e2863e (diff)
downloadkittybox-8826d9446e6c492db2243b9921e59ce496027bef.tar.zst
cargo fmt
Change-Id: I80e81ebba3f0cdf8c094451c9fe3ee4126b8c888
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/kittybox-check-webmention.rs13
-rw-r--r--src/bin/kittybox-indieauth-helper.rs96
-rw-r--r--src/bin/kittybox-mf2.rs14
3 files changed, 72 insertions, 51 deletions
diff --git a/src/bin/kittybox-check-webmention.rs b/src/bin/kittybox-check-webmention.rs
index b43980e..a9e5957 100644
--- a/src/bin/kittybox-check-webmention.rs
+++ b/src/bin/kittybox-check-webmention.rs
@@ -7,7 +7,7 @@ enum Error {
     #[error("reqwest error: {0}")]
     Http(#[from] reqwest::Error),
     #[error("webmention check error: {0}")]
-    Webmention(#[from] WebmentionError)
+    Webmention(#[from] WebmentionError),
 }
 
 #[derive(Parser, Debug)]
@@ -21,7 +21,7 @@ struct Args {
     #[clap(value_parser)]
     url: url::Url,
     #[clap(value_parser)]
-    link: url::Url
+    link: url::Url,
 }
 
 #[tokio::main]
@@ -30,10 +30,11 @@ async fn main() -> Result<(), Error> {
 
     let http: reqwest::Client = {
         #[allow(unused_mut)]
-        let mut builder = reqwest::Client::builder()
-            .user_agent(concat!(
-                env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")
-            ));
+        let mut builder = reqwest::Client::builder().user_agent(concat!(
+            env!("CARGO_PKG_NAME"),
+            "/",
+            env!("CARGO_PKG_VERSION")
+        ));
 
         builder.build().unwrap()
     };
diff --git a/src/bin/kittybox-indieauth-helper.rs b/src/bin/kittybox-indieauth-helper.rs
index f4ad679..0725aac 100644
--- a/src/bin/kittybox-indieauth-helper.rs
+++ b/src/bin/kittybox-indieauth-helper.rs
@@ -1,13 +1,11 @@
+use clap::Parser;
 use futures::{FutureExt, TryFutureExt};
 use kittybox_indieauth::{
-    AuthorizationRequest, PKCEVerifier,
-    PKCEChallenge, PKCEMethod, GrantRequest, Scope,
-    AuthorizationResponse, GrantResponse,
-    Error as IndieauthError
+    AuthorizationRequest, AuthorizationResponse, Error as IndieauthError, GrantRequest,
+    GrantResponse, PKCEChallenge, PKCEMethod, PKCEVerifier, Scope,
 };
-use clap::Parser;
-use tokio::net::TcpListener;
 use std::{borrow::Cow, future::IntoFuture, io::Write};
+use tokio::net::TcpListener;
 
 const DEFAULT_CLIENT_ID: &str = "https://kittybox.fireburn.ru/indieauth-helper.html";
 const DEFAULT_REDIRECT_URI: &str = "http://localhost:60000/callback";
@@ -21,7 +19,7 @@ enum Error {
     #[error("url parsing error: {0}")]
     UrlParse(#[from] url::ParseError),
     #[error("indieauth flow error: {0}")]
-    IndieAuth(#[from] IndieauthError)
+    IndieAuth(#[from] IndieauthError),
 }
 
 #[derive(Parser, Debug)]
@@ -46,20 +44,20 @@ struct Args {
     client_id: url::Url,
     /// Redirect URI to declare. Note: This will break the flow, use only for testing UI.
     #[clap(long, value_parser)]
-    redirect_uri: Option<url::Url>
+    redirect_uri: Option<url::Url>,
 }
 
-
 #[tokio::main]
 async fn main() -> Result<(), Error> {
     let args = Args::parse();
 
     let http: reqwest::Client = {
         #[allow(unused_mut)]
-        let mut builder = reqwest::Client::builder()
-            .user_agent(concat!(
-                env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")
-            ));
+        let mut builder = reqwest::Client::builder().user_agent(concat!(
+            env!("CARGO_PKG_NAME"),
+            "/",
+            env!("CARGO_PKG_VERSION")
+        ));
         // This only works on debug builds. Don't get any funny thoughts.
         #[cfg(debug_assertions)]
         if std::env::var("KITTYBOX_DANGER_INSECURE_TLS")
@@ -71,12 +69,14 @@ async fn main() -> Result<(), Error> {
         builder.build().unwrap()
     };
 
-    let redirect_uri: url::Url = args.redirect_uri
+    let redirect_uri: url::Url = args
+        .redirect_uri
         .clone()
         .unwrap_or_else(|| DEFAULT_REDIRECT_URI.parse().unwrap());
 
     eprintln!("Checking .well-known for metadata...");
-    let metadata = http.get(args.me.join("/.well-known/oauth-authorization-server")?)
+    let metadata = http
+        .get(args.me.join("/.well-known/oauth-authorization-server")?)
         .header("Accept", "application/json")
         .send()
         .await?
@@ -92,7 +92,7 @@ async fn main() -> Result<(), Error> {
         state: kittybox_indieauth::State::new(),
         code_challenge: PKCEChallenge::new(&verifier, PKCEMethod::default()),
         scope: Some(kittybox_indieauth::Scopes::new(args.scope)),
-        me: Some(args.me)
+        me: Some(args.me),
     };
 
     let indieauth_url = {
@@ -103,12 +103,18 @@ async fn main() -> Result<(), Error> {
         url
     };
 
-    eprintln!("Please visit the following URL in your browser:\n\n   {}\n", indieauth_url.as_str());
+    eprintln!(
+        "Please visit the following URL in your browser:\n\n   {}\n",
+        indieauth_url.as_str()
+    );
 
     #[cfg(target_os = "linux")]
-    match std::process::Command::new("xdg-open").arg(indieauth_url.as_str()).spawn() {
+    match std::process::Command::new("xdg-open")
+        .arg(indieauth_url.as_str())
+        .spawn()
+    {
         Ok(child) => drop(child),
-        Err(err) => eprintln!("Couldn't xdg-open: {}", err)
+        Err(err) => eprintln!("Couldn't xdg-open: {}", err),
     }
 
     if args.redirect_uri.is_some() {
@@ -123,32 +129,38 @@ async fn main() -> Result<(), Error> {
 
         let tx = std::sync::Arc::new(tokio::sync::Mutex::new(Some(tx)));
 
-        let router = axum::Router::new()
-            .route("/callback", axum::routing::get(
+        let router = axum::Router::new().route(
+            "/callback",
+            axum::routing::get(
                 move |Query(response): Query<AuthorizationResponse>| async move {
                     if let Some(tx) = tx.lock_owned().await.take() {
                         tx.send(response).unwrap();
 
-                        (axum::http::StatusCode::OK,
-                         [("Content-Type", "text/plain")],
-                         "Thank you! This window can now be closed.")
+                        (
+                            axum::http::StatusCode::OK,
+                            [("Content-Type", "text/plain")],
+                            "Thank you! This window can now be closed.",
+                        )
                             .into_response()
                     } else {
-                        (axum::http::StatusCode::BAD_REQUEST,
-                         [("Content-Type", "text/plain")],
-                         "Oops. The callback was already received. Did you click twice?")
+                        (
+                            axum::http::StatusCode::BAD_REQUEST,
+                            [("Content-Type", "text/plain")],
+                            "Oops. The callback was already received. Did you click twice?",
+                        )
                             .into_response()
                     }
-                }
-            ));
+                },
+            ),
+        );
 
-        use std::net::{SocketAddr, IpAddr, Ipv4Addr};
+        use std::net::{IpAddr, Ipv4Addr, SocketAddr};
 
         let server = axum::serve(
-            TcpListener::bind(
-                SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST),60000)
-            ).await.unwrap(),
-            router.into_make_service()
+            TcpListener::bind(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 60000))
+                .await
+                .unwrap(),
+            router.into_make_service(),
         );
 
         tokio::task::spawn(server.into_future())
@@ -175,12 +187,13 @@ async fn main() -> Result<(), Error> {
         #[cfg(not(debug_assertions))]
         std::process::exit(1);
     }
-    let response: Result<GrantResponse, IndieauthError> = http.post(metadata.token_endpoint)
+    let response: Result<GrantResponse, IndieauthError> = http
+        .post(metadata.token_endpoint)
         .form(&GrantRequest::AuthorizationCode {
             code: authorization_response.code,
             client_id: args.client_id,
             redirect_uri,
-            code_verifier: verifier
+            code_verifier: verifier,
         })
         .header("Accept", "application/json")
         .send()
@@ -201,9 +214,14 @@ async fn main() -> Result<(), Error> {
         refresh_token,
         scope,
         ..
-    } = response? {
-        eprintln!("Congratulations, {}, access token is ready! {}",
-            profile.as_ref().and_then(|p| p.name.as_deref()).unwrap_or(me.as_str()),
+    } = response?
+    {
+        eprintln!(
+            "Congratulations, {}, access token is ready! {}",
+            profile
+                .as_ref()
+                .and_then(|p| p.name.as_deref())
+                .unwrap_or(me.as_str()),
             if let Some(exp) = expires_in {
                 Cow::Owned(format!("It expires in {exp} seconds."))
             } else {
diff --git a/src/bin/kittybox-mf2.rs b/src/bin/kittybox-mf2.rs
index 0cd89b4..b6f4999 100644
--- a/src/bin/kittybox-mf2.rs
+++ b/src/bin/kittybox-mf2.rs
@@ -37,8 +37,9 @@ async fn main() -> Result<(), Error> {
                 .with_indent_lines(true)
                 .with_verbose_exit(true),
             #[cfg(not(debug_assertions))]
-            tracing_subscriber::fmt::layer().json()
-                .with_ansi(std::io::IsTerminal::is_terminal(&std::io::stdout().lock()))
+            tracing_subscriber::fmt::layer()
+                .json()
+                .with_ansi(std::io::IsTerminal::is_terminal(&std::io::stdout().lock())),
         );
     tracing_registry.init();
 
@@ -46,10 +47,11 @@ async fn main() -> Result<(), Error> {
 
     let http: reqwest::Client = {
         #[allow(unused_mut)]
-        let mut builder = reqwest::Client::builder()
-            .user_agent(concat!(
-                env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")
-            ));
+        let mut builder = reqwest::Client::builder().user_agent(concat!(
+            env!("CARGO_PKG_NAME"),
+            "/",
+            env!("CARGO_PKG_VERSION")
+        ));
 
         builder.build().unwrap()
     };