syui 3 months ago
parent b57034ba58
commit a38fae8a7e
Signed by: syui
GPG Key ID: 67AC97A939D3EA19

@ -23,6 +23,58 @@ impl Data {
// at://
// https://atproto.com/lexicons/app-bsky-feed
#[derive(Serialize, Deserialize)]
pub struct BaseUrl {
pub profile_get: String,
pub describe: String,
pub record_list: String,
pub record_create: String,
pub session_create: String,
pub timeline_get: String,
pub upload_blob: String,
pub update_handle: String,
pub account_create: String,
pub notify_count: String,
pub notify_list: String,
}
pub fn url(s: &String) -> String {
let s = String::from(s);
let data = Data::new().unwrap();
let data = Data {
host: data.host,
user: data.user,
pass: data.pass,
};
let baseurl = BaseUrl {
profile_get: "https://".to_string() + &data.host.to_string() + &"/xrpc/app.bsky.actor.getProfile".to_string(),
record_create: "https://".to_string() + &data.host.to_string() + &"/xrpc/com.atproto.repo.createRecord".to_string(),
describe: "https://".to_string() + &data.host.to_string() + &"/xrpc/com.atproto.repo.describe".to_string(),
record_list: "https://".to_string() + &data.host.to_string() + &"/xrpc/com.atproto.repo.listRecords".to_string(),
session_create: "https://".to_string() + &data.host.to_string() + &"/xrpc/com.atproto.session.create".to_string(),
timeline_get: "https://".to_string() + &data.host.to_string() + &"/xrpc/app.bsky.feed.getTimeline".to_string(),
upload_blob: "https://".to_string() + &data.host.to_string() + &"/xrpc/com.atproto.blob.upload".to_string(),
account_create: "https://".to_string() + &data.host.to_string() + &"/xrpc/com.atproto.account.create".to_string(),
update_handle: "https://".to_string() + &data.host.to_string() + &"/xrpc/com.atproto.handle.update".to_string(),
notify_count: "https://".to_string() + &data.host.to_string() + &"/xrpc/app.bsky.notification.getCount".to_string(),
notify_list: "https://".to_string() + &data.host.to_string() + &"/xrpc/app.bsky.notification.list".to_string(),
};
match &*s {
"profile_get" => baseurl.profile_get,
"describe" => baseurl.describe,
"record_list" => baseurl.record_list,
"record_create" => baseurl.record_create,
"session_create" => baseurl.session_create,
"timeline_get" => baseurl.timeline_get,
"upload_blob" => baseurl.upload_blob,
"account_create" => baseurl.account_create,
"update_handle" => baseurl.update_handle,
"notify_list" => baseurl.notify_list,
"notify_count" => baseurl.notify_count,
_ => s,
}
}
#[derive(Serialize, Deserialize)]
pub struct Notify {
pub notifications: Vec<Notifications>

@ -20,6 +20,7 @@ use data::Did as Did;
use data::Cid as Cid;
use data::Handle as Handle;
use crate::data::Timeline;
use crate::data::url;
use std::io;
use std::io::Write;
@ -246,7 +247,8 @@ fn ss(c :&Context) -> reqwest::Result<()> {
user: data.user,
pass: data.pass,
};
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.describe";
let s = "describe".to_string();
let url = url(&s);
if let Ok(user) = c.string_flag("user") {
at_user(url, user);
} else {
@ -281,7 +283,8 @@ fn ff(c :&Context) -> reqwest::Result<()> {
user: data.user,
pass: data.pass,
};
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.listRecords";
let s = "record_list".to_string();
let url = url(&s);
let col = "app.bsky.feed.post".to_string();
if let Ok(user) = c.string_flag("user") {
at_feed(url, user, col);
@ -312,7 +315,8 @@ async fn aa() -> reqwest::Result<()> {
let handle = data.user;
let mut map = HashMap::new();
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.session.create";
let s = "session_create".to_string();
let url = url(&s);
map.insert("handle", &handle);
map.insert("password", &data.pass);
let client = reqwest::Client::new();
@ -350,14 +354,8 @@ async fn pp(c: &Context) -> reqwest::Result<()> {
let token = json.accessJwt;
let did = json.did;
let data = Datas::new().unwrap();
let data = Datas {
host: data.host,
user: data.user,
pass: data.pass,
};
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.createRecord";
let s = "record_create".to_string();
let url = url(&s);
let col = "app.bsky.feed.post".to_string();
let d = Timestamp::now_utc();
let d = d.to_string();
@ -449,7 +447,8 @@ async fn tt(c: &Context) -> reqwest::Result<()> {
let json: Token = serde_json::from_str(&data).unwrap();
let token = json.accessJwt;
let url = "https://bsky.social/xrpc/app.bsky.feed.getTimeline";
let s = "timeline_get".to_string();
let url = url(&s);
let client = reqwest::Client::new();
let j = client.get(url)
@ -506,16 +505,11 @@ async fn pro(c: &Context) -> reqwest::Result<()> {
let json: Token = serde_json::from_str(&data).unwrap();
let token = json.accessJwt;
let data = Datas::new().unwrap();
let data = Datas {
host: data.host,
user: data.user,
pass: data.pass,
};
let user = c.args[0].to_string();
if user.is_empty() == false {
let url = "https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=".to_owned() + &user;
let s = "profile_get".to_string();
if c.args[0].is_empty() == false {
let user = c.args[0].to_string();
let url = url(&s) + &"?actor=" + &user;
println!("{}", url);
let client = reqwest::Client::new();
let j = client.get(url)
.header("Authorization", "Bearer ".to_owned() + &token)
@ -531,16 +525,6 @@ async fn pro(c: &Context) -> reqwest::Result<()> {
f.write_all(&j.as_bytes()).unwrap();
}
println!("{}", j);
} else {
let url = "https://bsky.social/xrpc/app.bsky.actor.getProfile?actor=".to_owned() + &data.user;
let client = reqwest::Client::new();
let j = client.get(url)
.header("Authorization", "Bearer ".to_owned() + &token)
.send()
.await?
.text()
.await?;
println!("{}", j);
}
Ok(())
}
@ -570,7 +554,9 @@ async fn mm(c: &Context) -> reqwest::Result<()> {
user: data.user,
pass: data.pass,
};
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.blob.upload";
let s = "upload_blob".to_string();
let url = url(&s);
let f = "@".to_owned() + &c.args[0].to_string();
use std::process::Command;
@ -619,13 +605,8 @@ async fn hh(c: &Context) -> reqwest::Result<()> {
let m = c.args[0].to_string();
let data = Datas::new().unwrap();
let data = Datas {
host: data.host,
user: data.user,
pass: data.pass,
};
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.handle.update";
let s = "update_handle".to_string();
let url = url(&s);
println!("DNS txt : _atproto.{}, did={}.", m, did);
let handle = Handle {
@ -659,7 +640,9 @@ async fn cc(c: &Context) -> reqwest::Result<()> {
user: data.user,
pass: data.pass,
};
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.account.create";
let s = "account_create".to_string();
let url = url(&s);
let handle = data.user;
let mut map = HashMap::new();
@ -716,13 +699,8 @@ async fn mention(c: &Context) -> reqwest::Result<()> {
let handle: Handle = serde_json::from_str(&data).unwrap();
let handle = handle.handle;
let data = Datas::new().unwrap();
let data = Datas {
host: data.host,
user: data.user,
pass: data.pass,
};
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.createRecord";
let s = "record_create".to_string();
let url = url(&s);
let col = "app.bsky.feed.post".to_string();
let d = Timestamp::now_utc();
@ -811,15 +789,11 @@ async fn nn(c: &Context) -> reqwest::Result<()> {
let json: Token = serde_json::from_str(&data).unwrap();
let token = json.accessJwt;
let data = Datas::new().unwrap();
let data = Datas {
host: data.host,
user: data.user,
pass: data.pass,
};
if let Ok(_get) = c.string_flag("get") {
let url = "https://".to_owned() + &data.host + &"/xrpc/app.bsky.notification.getCount";
let s = "notify_count".to_string();
let url = url(&s);
let client = reqwest::Client::new();
let res = client
.get(url)
@ -831,7 +805,8 @@ async fn nn(c: &Context) -> reqwest::Result<()> {
println!("{}", res);
}
let url = "https://".to_owned() + &data.host + &"/xrpc/app.bsky.notification.list";
let s = "notify_list".to_string();
let url = url(&s);
let client = reqwest::Client::new();
let res = client
.get(url)
@ -1001,14 +976,8 @@ async fn rr(c: &Context) -> reqwest::Result<()> {
let token = json.accessJwt;
let did = json.did;
let data = Datas::new().unwrap();
let data = Datas {
host: data.host,
user: data.user,
pass: data.pass,
};
let url = "https://".to_owned() + &data.host + &"/xrpc/com.atproto.repo.createRecord";
let s = "record_create".to_string();
let url = url(&s);
let col = "app.bsky.feed.post".to_string();
let d = Timestamp::now_utc();
let d = d.to_string();

Loading…
Cancel
Save