1
0

add notify

This commit is contained in:
syui 2024-02-07 11:34:12 +09:00
parent dc1fc9d229
commit 47b1e7cb89
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
4 changed files with 77 additions and 24 deletions

View File

@ -10,6 +10,7 @@ use crate::data::w_cfg;
pub mod data;
pub mod refresh;
pub mod token;
pub mod notify;
pub mod ascii;
fn main() {
@ -25,11 +26,6 @@ fn main() {
.alias("t"),
)
)
.command(
Command::new("refresh")
.alias("r")
.action(c_refresh),
)
.command(
Command::new("token")
.alias("t")
@ -41,6 +37,16 @@ fn main() {
.alias("p"),
)
)
.command(
Command::new("refresh")
.alias("r")
.action(c_refresh),
)
.command(
Command::new("notify")
.alias("n")
.action(c_notify),
)
;
app.run(args);
}
@ -49,20 +55,6 @@ fn c_ascii_art(c: &Context) {
c_ascii(c.bool_flag("type"));
}
fn refresh() {
let h = async {
let res = refresh::post_request().await;
println!("{}", res);
w_cfg("bsky.social", &res)
};
let res = tokio::runtime::Runtime::new().unwrap().block_on(h);
return res
}
fn c_refresh(_c: &Context) {
refresh();
}
fn token(c: &Context) {
let m = c.args[0].to_string();
let h = async {
@ -79,3 +71,32 @@ fn token(c: &Context) {
fn c_token(c: &Context) {
token(c);
}
fn refresh() {
let h = async {
let res = refresh::post_request().await;
println!("{}", res);
w_cfg("bsky.social", &res)
};
let res = tokio::runtime::Runtime::new().unwrap().block_on(h);
return res
}
fn c_refresh(_c: &Context) {
refresh();
}
fn notify() {
let h = async {
let j = notify::get_request(100).await;
println!("{}", j);
};
let res = tokio::runtime::Runtime::new().unwrap().block_on(h);
return res
}
fn c_notify(_c: &Context) {
notify();
}

31
src/notify.rs Normal file
View File

@ -0,0 +1,31 @@
extern crate reqwest;
use crate::data_toml;
use crate::url;
//use serde_json::json;
pub async fn get_request(limit: i32, ) -> String {
let token = data_toml(&"access");
let url = url(&"notify_list");
let client = reqwest::Client::new();
let res = client
.get(url)
.query(&[("limit", limit)])
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await
.unwrap();
let status_ref = res.error_for_status_ref();
match status_ref {
Ok(_) => {
return res.text().await.unwrap();
},
Err(_e) => {
let e = "err".to_string();
return e
}
}
}

View File

@ -1,14 +1,14 @@
extern crate reqwest;
use crate::token_toml;
use crate::data_toml;
use crate::url;
use serde_json::json;
use iso8601_timestamp::Timestamp;
pub async fn post_request(text: String, cid: String, uri: String, cid_p: String, uri_p: String) -> String {
let token = token_toml(&"access");
let did = token_toml(&"did");
let handle = token_toml(&"handle");
let token = data_toml(&"access");
let did = data_toml(&"did");
let handle = data_toml(&"handle");
let url = url(&"record_create");
//let url = "https://bsky.social/xrpc/com.atproto.repo.createRecord";

View File

@ -1,9 +1,10 @@
extern crate reqwest;
use std::collections::HashMap;
use crate::url;
pub async fn post_request(handle: String, pass: String) -> String {
let url = "https://bsky.social/xrpc/com.atproto.server.createSession";
let url = url(&"session_create");
let mut map = HashMap::new();
map.insert("identifier", &handle);