1
0
This commit is contained in:
syui 2024-02-07 11:58:39 +09:00
parent 47b1e7cb89
commit 4b13aa48a3
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
3 changed files with 45 additions and 15 deletions

View File

@ -14,15 +14,31 @@ $ ./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
```
```
# server: syu.is
$ ai r -s syu.is
```
### notify
```
$ ai n
```

View File

@ -36,12 +36,22 @@ fn main() {
.description("password flag")
.alias("p"),
)
.flag(
Flag::new("server", FlagType::String)
.description("server flag")
.alias("s"),
)
)
.command(
Command::new("refresh")
.alias("r")
.action(c_refresh),
.action(c_refresh)
.flag(
Flag::new("server", FlagType::String)
.description("server flag")
.alias("s"),
)
)
.command(
Command::new("notify")
.alias("n")
@ -59,9 +69,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);
@ -72,22 +86,23 @@ fn c_token(c: &Context) {
token(c);
}
fn refresh() {
fn refresh(c: &Context) {
let h = async {
let res = refresh::post_request().await;
println!("{}", res);
w_cfg("bsky.social", &res)
if let Ok(s) = c.string_flag("server") {
w_cfg(&s, &res)
} else {
w_cfg("bsky.social", &res)
}
};
let res = tokio::runtime::Runtime::new().unwrap().block_on(h);
return res
}
fn c_refresh(_c: &Context) {
refresh();
fn c_refresh(c: &Context) {
refresh(c);
}
fn notify() {
let h = async {
let j = notify::get_request(100).await;

View File

@ -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);