feat: Update API domain variable name

This commit is contained in:
aprilthepink 2024-05-17 13:24:41 +02:00
parent 14322c961f
commit b65a51a1ef
6 changed files with 139 additions and 21 deletions

9
Cargo.lock generated
View file

@ -457,6 +457,12 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "atomic"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.2.0" version = "1.2.0"
@ -1917,6 +1923,7 @@ dependencies = [
"tokio", "tokio",
"tracing", "tracing",
"url", "url",
"uuid",
"vcpkg", "vcpkg",
] ]
@ -3784,7 +3791,9 @@ version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0"
dependencies = [ dependencies = [
"atomic",
"getrandom", "getrandom",
"rand",
"serde", "serde",
] ]

View file

@ -44,6 +44,15 @@ features = [
"sqlx-sqlite","sqlx-mysql","with-chrono" "sqlx-sqlite","sqlx-mysql","with-chrono"
] ]
[dependencies.uuid]
version = "1.8.0"
features = [
"v4",
"v7",
"fast-rng", # Use a faster (but still sufficiently random) RNG
"serde",
]
[build-dependencies] [build-dependencies]
vcpkg = "0.2.15" vcpkg = "0.2.15"

View file

@ -13,6 +13,7 @@ use time::{
OffsetDateTime, OffsetDateTime,
}; };
use url::Url; use url::Url;
use uuid::Uuid;
const FORMAT: Iso8601<6651332276412969266533270467398074368> = Iso8601::< const FORMAT: Iso8601<6651332276412969266533270467398074368> = Iso8601::<
{ {
@ -49,6 +50,25 @@ pub enum LysandType {
ServerMetadata, ServerMetadata,
} }
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum CategoryType {
Microblog,
Forum,
Blog,
Image,
Video,
Audio,
Messaging
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum VisibilityType {
Public,
Unlisted,
Followers,
Direct
}
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub enum LysandExtensions { pub enum LysandExtensions {
#[serde(rename = "org.lysand:microblogging/Announce")] #[serde(rename = "org.lysand:microblogging/Announce")]
@ -116,7 +136,7 @@ impl<'de> Deserialize<'de> for ContentFormat {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
struct FieldKV { struct FieldKV {
key: ContentFormat, name: ContentFormat,
value: ContentFormat, value: ContentFormat,
} }
@ -135,25 +155,74 @@ pub struct ContentEntry {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct User { pub struct User {
public_key: PublicKey, pub public_key: PublicKey,
#[serde(rename = "type")] #[serde(rename = "type")]
rtype: LysandType, pub rtype: LysandType,
id: String, pub id: Uuid,
uri: Url, pub uri: Url,
#[serde(with = "iso_lysand")] #[serde(with = "iso_lysand")]
created_at: OffsetDateTime, pub created_at: OffsetDateTime,
display_name: Option<String>, pub display_name: Option<String>,
// TODO bio: Option<String>, // TODO bio: Option<String>,
inbox: Url, pub inbox: Url,
outbox: Url, pub outbox: Url,
featured: Url, pub featured: Url,
followers: Url, pub followers: Url,
following: Url, pub following: Url,
likes: Url, pub likes: Url,
dislikes: Url, pub dislikes: Url,
username: String, pub username: String,
bio: Option<ContentFormat>, pub bio: Option<ContentFormat>,
avatar: Option<ContentFormat>, pub avatar: Option<ContentFormat>,
header: Option<ContentFormat>, pub header: Option<ContentFormat>,
fields: Option<Vec<FieldKV>>, pub fields: Option<Vec<FieldKV>>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DeviceInfo {
name: String,
version: String,
url: Url,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct LinkPreview {
description: String,
title: String,
link: Url,
image: Option<Url>,
icon: Option<Url>
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Note {
#[serde(rename = "type")]
pub rtype: LysandType,
pub id: Uuid,
pub uri: Url,
pub author: Url,
#[serde(with = "iso_lysand")]
pub created_at: OffsetDateTime,
pub category: Option<CategoryType>,
pub content: Option<ContentFormat>,
pub device: Option<DeviceInfo>,
pub previews: Option<Vec<LinkPreview>>,
pub group: Option<String>,
pub attachments: Option<Vec<ContentFormat>>,
pub replies_to: Option<Url>,
pub quotes: Option<Url>,
pub mentions: Option<Vec<Url>>,
pub subject: Option<String>,
pub is_sensitive: Option<bool>,
pub visibility: Option<VisibilityType>,
//TODO extensions
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Outbox {
pub first: Url,
pub last: Url,
pub next: Option<Url>,
pub prev: Option<Url>,
pub items: Vec<Note>,
} }

View file

@ -22,6 +22,26 @@ pub async fn serialize_lysand_type(
Ok(data) Ok(data)
} }
pub async fn deserialize_note(data: String) -> anyhow::Result<super::objects::Note> {
let post: super::objects::Note = serde_json::from_str(&data)?;
Ok(post)
}
pub async fn serialize_note(post: super::objects::Note) -> anyhow::Result<String> {
let data = serde_json::to_string(&SortAlphabetically(&post))?;
Ok(data)
}
pub async fn deserialize_outbox(data: String) -> anyhow::Result<super::objects::Outbox> {
let outbox: super::objects::Outbox = serde_json::from_str(&data)?;
Ok(outbox)
}
pub async fn serialize_outbox(outbox: super::objects::Outbox) -> anyhow::Result<String> {
let data = serde_json::to_string(&SortAlphabetically(&outbox))?;
Ok(data)
}
#[inline] #[inline]
pub fn request_client() -> reqwest::Client { pub fn request_client() -> reqwest::Client {
reqwest::Client::builder() reqwest::Client::builder()

View file

@ -22,5 +22,16 @@ pub async fn main() -> anyhow::Result<()> {
let user_json = serde_json::to_string_pretty(&SortAlphabetically(&user))?; let user_json = serde_json::to_string_pretty(&SortAlphabetically(&user))?;
println!("{}", user_json); println!("{}", user_json);
let response_outbox = client
.get(user.outbox.as_str())
.send()
.await?;
let outbox_json = response_outbox.text().await?;
let outbox = super::superx::deserialize_outbox(outbox_json).await?;
println!("\n\n\nOutbox: ");
print!("{:#?}", outbox);
Ok(()) Ok(())
} }

View file

@ -151,8 +151,8 @@ async fn main() -> actix_web::Result<(), anyhow::Error> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
//TODO remove this //TODO remove this
//lysand::test::main().await?; lysand::test::main().await?;
//return Ok(()); return Ok(());
let ap_id = Url::parse(&format!( let ap_id = Url::parse(&format!(
"https://{}/{}", "https://{}/{}",