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

View file

@ -13,6 +13,7 @@ use time::{
OffsetDateTime,
};
use url::Url;
use uuid::Uuid;
const FORMAT: Iso8601<6651332276412969266533270467398074368> = Iso8601::<
{
@ -49,6 +50,25 @@ pub enum LysandType {
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)]
pub enum LysandExtensions {
#[serde(rename = "org.lysand:microblogging/Announce")]
@ -116,7 +136,7 @@ impl<'de> Deserialize<'de> for ContentFormat {
#[derive(Debug, Serialize, Deserialize, Clone)]
struct FieldKV {
key: ContentFormat,
name: ContentFormat,
value: ContentFormat,
}
@ -135,25 +155,74 @@ pub struct ContentEntry {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct User {
public_key: PublicKey,
pub public_key: PublicKey,
#[serde(rename = "type")]
rtype: LysandType,
id: String,
uri: Url,
pub rtype: LysandType,
pub id: Uuid,
pub uri: Url,
#[serde(with = "iso_lysand")]
created_at: OffsetDateTime,
display_name: Option<String>,
pub created_at: OffsetDateTime,
pub display_name: Option<String>,
// TODO bio: Option<String>,
inbox: Url,
outbox: Url,
featured: Url,
followers: Url,
following: Url,
likes: Url,
dislikes: Url,
username: String,
bio: Option<ContentFormat>,
avatar: Option<ContentFormat>,
header: Option<ContentFormat>,
fields: Option<Vec<FieldKV>>,
pub inbox: Url,
pub outbox: Url,
pub featured: Url,
pub followers: Url,
pub following: Url,
pub likes: Url,
pub dislikes: Url,
pub username: String,
pub bio: Option<ContentFormat>,
pub avatar: Option<ContentFormat>,
pub header: Option<ContentFormat>,
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)
}
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]
pub fn request_client() -> reqwest::Client {
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))?;
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(())
}

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"));
//TODO remove this
//lysand::test::main().await?;
//return Ok(());
lysand::test::main().await?;
return Ok(());
let ap_id = Url::parse(&format!(
"https://{}/{}",