From 12a134dcf676f7d2a697ce6a2802b044b7f16b7c Mon Sep 17 00:00:00 2001 From: syui Date: Wed, 7 Feb 2024 11:58:39 +0900 Subject: [PATCH] fix host --- README.md | 13 ++++++++++++- src/main.rs | 17 ++++++++++++----- src/token.rs | 5 ++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a58b53e..9199eab 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,26 @@ $ ./target/debug/ai ai -t ### login ```sh -# ai t $handle -p $password +# ai token $handle -p $password $ ai t yui.syui.ai -p password $ cat ~/.config/ai/token.toml ``` +```sh +# ai token $handle -p $password -s $server +$ ai t ai.syu.is -p password -s syu.is +``` + ### refresh ``` $ ai r ``` +### notify + +``` +$ ai n +``` + diff --git a/src/main.rs b/src/main.rs index 5a8701c..75d52b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,12 @@ fn main() { .description("password flag") .alias("p"), ) + .flag( + Flag::new("server", FlagType::String) + .description("server flag") + .alias("s"), ) + ) .command( Command::new("refresh") .alias("r") @@ -59,9 +64,13 @@ fn token(c: &Context) { let m = c.args[0].to_string(); let h = async { if let Ok(p) = c.string_flag("password") { - let res = token::post_request(m.to_string(), p.to_string()).await; - println!("{}", res); - w_cfg("bsky.social", &res) + if let Ok(s) = c.string_flag("server") { + let res = token::post_request(m.to_string(), p.to_string(), s.to_string()).await; + w_cfg(&s, &res) + } else { + let res = token::post_request(m.to_string(), p.to_string(), "bsky.social".to_string()).await; + w_cfg(&"bsky.social", &res) + } } }; let res = tokio::runtime::Runtime::new().unwrap().block_on(h); @@ -86,8 +95,6 @@ fn c_refresh(_c: &Context) { refresh(); } - - fn notify() { let h = async { let j = notify::get_request(100).await; diff --git a/src/token.rs b/src/token.rs index 2b35127..4f0f715 100644 --- a/src/token.rs +++ b/src/token.rs @@ -1,10 +1,9 @@ extern crate reqwest; use std::collections::HashMap; -use crate::url; -pub async fn post_request(handle: String, pass: String) -> String { +pub async fn post_request(handle: String, pass: String, host: String) -> String { - let url = url(&"session_create"); + let url = "https://".to_owned() + &host.to_string() + &"/xrpc/com.atproto.server.createSession".to_string(); let mut map = HashMap::new(); map.insert("identifier", &handle);