diff --git a/.config/ai/scpt b/.config/ai/scpt index 9cbca76..03a64c3 160000 --- a/.config/ai/scpt +++ b/.config/ai/scpt @@ -1 +1 @@ -Subproject commit 9cbca76fc7846495894b254881cde1f7dc0ae363 +Subproject commit 03a64c3652bd60cc8cfab09bd70368a1c7dab9d8 diff --git a/README.md b/README.md index da289b5..577f0a6 100644 --- a/README.md +++ b/README.md @@ -107,3 +107,13 @@ ADMIN=syui.syu.is $ docker compose build $ docker compose up -d ``` + +## pds + +- https://atproto.com/ja/guides/lexicon +- https://at.syu.is/at/did:plc:uqzpqmrjnptsxezjx4xuh2mn/ai.syui.card/3lagpwihqxi2v + +```sh +# oauth(button) +[yui]ai.syui.card.verify -> [user]ai.syui.card +``` diff --git a/src/main.rs b/src/main.rs index 7ccf663..fead43f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,8 @@ pub mod notify_read; pub mod openai; pub mod post; pub mod post_link; +pub mod post_card; +pub mod post_card_verify; pub mod profile; pub mod refresh; pub mod reply; @@ -154,6 +156,73 @@ fn main() { .alias("c"), ) ) + .command( + Command::new("card") + .description("-v -i -p -r -c -a -img -rare ") + .action(card) + .flag( + Flag::new("id", FlagType::Int) + .alias("i"), + ) + .flag( + Flag::new("cp", FlagType::Int) + .alias("p"), + ) + .flag( + Flag::new("rank", FlagType::Int) + .alias("r"), + ) + .flag( + Flag::new("rare", FlagType::Int) + ) + .flag( + Flag::new("col", FlagType::String) + .alias("c"), + ) + .flag( + Flag::new("author", FlagType::String) + .alias("a"), + ) + .flag( + Flag::new("verify", FlagType::String) + .alias("v"), + ) + .flag( + Flag::new("img", FlagType::String) + ) + ) + .command( + Command::new("card-verify") + .description(" -c -i -p -r -rare -h -d ") + .action(card_verify) + .flag( + Flag::new("col", FlagType::String) + .alias("c"), + ) + .flag( + Flag::new("id", FlagType::Int) + .alias("i"), + ) + .flag( + Flag::new("cp", FlagType::Int) + .alias("p"), + ) + .flag( + Flag::new("rank", FlagType::Int) + .alias("r"), + ) + .flag( + Flag::new("rare", FlagType::String) + ) + .flag( + Flag::new("handle", FlagType::String) + .alias("handle"), + ) + .flag( + Flag::new("did", FlagType::String) + .alias("did"), + ) + ) .command( Command::new("like") .description("like -u ") @@ -474,6 +543,57 @@ fn like(c: &Context) { return res; } +async fn c_card(c: &Context) -> Result<(), Box> { + //let m = c.args[0].to_string(); + let author = c.string_flag("author").unwrap_or_else(|_| "syui".to_string()); + let verify = c.string_flag("verify").unwrap_or_else(|_| "at://did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.card.verify/3lagpvhppmd2q".to_string()); + let col = c.string_flag("col").unwrap_or_else(|_| "ai.syui.card".to_string()); + //let img = c.string_flag("img").unwrap_or_else(|_| "bafkreigvcjc46qtelpc4wsg7fwf6qktbi6a23ouqiupth2r37zhrn7wbza".to_string()); + let id = c.int_flag("id")?.try_into()?; + let cp = c.int_flag("cp")?.try_into()?; + let rank = c.int_flag("rank")?.try_into()?; + let rare = c.string_flag("rare").unwrap_or_else(|_| "normal".to_string()); + let str = post_card::post_request(verify, id, cp, rank, rare, col, author); + println!("{}", str.await); + Ok(()) +} + +fn card(c: &Context) { + refresh(c); + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async { + if let Err(e) = c_card(c).await { + eprintln!("Error: {}", e); + } + }); +} + +async fn c_card_verify(c: &Context) -> Result<(), Box> { + let col = c.string_flag("col").unwrap_or_else(|_| "ai.syui.card.verify".to_string()); + let img = c.string_flag("img").unwrap_or_else(|_| "bafkreigvcjc46qtelpc4wsg7fwf6qktbi6a23ouqiupth2r37zhrn7wbza".to_string()); + let id = c.int_flag("id")?.try_into()?; + let cp = c.int_flag("cp")?.try_into()?; + let rank = c.int_flag("rank")?.try_into()?; + let rare = c.string_flag("rare").unwrap_or_else(|_| "normal".to_string()); + let user_handle = c.string_flag("handle").unwrap_or_else(|_| "syui.ai".to_string()); + let user_did = c.string_flag("did").unwrap_or_else(|_| "did:plc:uqzpqmrjnptsxezjx4xuh2mn".to_string()); + let str = post_card_verify::post_request(col, img, id, cp, rank, rare, user_handle, user_did); + println!("{}", str.await); + Ok(()) +} + +fn card_verify(c: &Context) { + refresh(c); + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async { + if let Err(e) = c_card_verify(c).await { + eprintln!("Error: {}", e); + } + }); +} + fn repost(c: &Context) { refresh(c); let m = c.args[0].to_string(); diff --git a/src/post_card.rs b/src/post_card.rs new file mode 100644 index 0000000..09c3efa --- /dev/null +++ b/src/post_card.rs @@ -0,0 +1,46 @@ +extern crate reqwest; +use crate::data_toml; +use crate::data_refresh; +use crate::url; +use iso8601_timestamp::Timestamp; +use serde_json::json; + +pub async fn post_request(verify: String, id: i32, cp: i32, rank: i32, rare: String, col: String, author: String) -> String { + let token = data_refresh(&"access"); + let did = data_toml(&"did"); + let handle = data_toml(&"handle"); + + let url = url(&"record_create"); + + let d = Timestamp::now_utc(); + let d = d.to_string(); + + let post = Some(json!({ + "repo": handle.to_string(), + "did": did.to_string(), + "collection": col.to_string(), + "record": { + "id": id, + "cp": cp, + "rank": rank, + "rare": rare.to_string(), + "author": author.to_string(), + "verify": verify.to_string(), + "createdAt": d.to_string(), + }, + })); + + let client = reqwest::Client::new(); + let res = client + .post(url) + .json(&post) + .header("Authorization", "Bearer ".to_owned() + &token) + .send() + .await + .unwrap() + .text() + .await + .unwrap(); + + return res; +} diff --git a/src/post_card_verify.rs b/src/post_card_verify.rs new file mode 100644 index 0000000..5543735 --- /dev/null +++ b/src/post_card_verify.rs @@ -0,0 +1,58 @@ +extern crate reqwest; +use crate::data_toml; +use crate::data_refresh; +use crate::url; +use iso8601_timestamp::Timestamp; +use serde_json::json; + +pub async fn post_request(col: String, img: String, id: i32, cp: i32, rank: i32, rare: String, user_handle: String, user_did: String) -> String { + let token = data_refresh(&"access"); + let did = data_toml(&"did"); + let handle = data_toml(&"handle"); + let url = url(&"record_create"); + let d = Timestamp::now_utc(); + let d = d.to_string(); + let link = "https://bsky.app/profile/yui.syui.ai".to_string(); + let post = Some(json!({ + "repo": handle.to_string(), + "did": did.to_string(), + "collection": col.to_string(), + "record": { + "id": id, + "cp": cp, + "rank": rank, + "rare": rare.to_string(), + "handle": user_handle.to_string(), + "did": user_did.to_string(), + "embed": { + "$type": "app.bsky.embed.external", + "external": { + "uri": link, + "thumb": { + "$type": "blob", + "ref": { + "$link": img.to_string() + }, + "mimeType": "image/jpeg", + "size": 0 + } + } + }, + "createdAt": d.to_string(), + }, + })); + + let client = reqwest::Client::new(); + let res = client + .post(url) + .json(&post) + .header("Authorization", "Bearer ".to_owned() + &token) + .send() + .await + .unwrap() + .text() + .await + .unwrap(); + + return res; +}