diff --git a/src/convert/npf.rs b/src/convert/npf.rs index 48a017b..a9286c7 100644 --- a/src/convert/npf.rs +++ b/src/convert/npf.rs @@ -1,11 +1,4 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Deserialize, Serialize)] -pub struct NPF { - pub content: Vec, -} - -pub mod blocks { +pub mod content_blocks { use std::{collections::HashMap, str::FromStr}; use serde::{Deserialize, Serialize}; @@ -277,6 +270,120 @@ pub mod blocks { } } +pub mod layout_blocks { + use serde::{Deserialize, Serialize}; + + #[derive(Debug, Deserialize, Serialize)] + #[serde(untagged)] + pub enum BlockValue { + Rows(BlockRows), + Ask(BlockAsk), + } + + #[derive(Debug, Deserialize, Serialize)] + pub struct BlockRows { + r#type: String, + pub display: Vec, + pub truncate_after: Option, + } + impl BlockRows { + pub fn new(blocks: Vec) -> Self { + Self::from(blocks) + } + fn default() -> Self { + Self { + r#type: String::from("rows"), + display: vec![], + truncate_after: None, + } + } + } + impl From> for BlockRows { + fn from(value: Vec) -> Self { + Self { + display: value, + ..Self::default() + } + } + } + impl From for BlockRows { + fn from(value: DisplayBlocks) -> Self { + Self { + display: vec![value], + ..Self::default() + } + } + } + + #[derive(Debug, Deserialize, Serialize)] + pub struct DisplayBlocks { + pub blocks: Vec, + pub mode: Option, + } + impl DisplayBlocks { + pub fn new(blocks: Vec) -> Self { + Self::from(blocks) + } + fn default() -> Self { + Self { + blocks: vec![], + mode: None, + } + } + } + impl From> for DisplayBlocks { + fn from(value: Vec) -> Self { + Self { + blocks: value, + ..Self::default() + } + } + } + impl From for DisplayBlocks { + fn from(value: u64) -> Self { + Self { + blocks: vec![value], + ..Self::default() + } + } + } + + #[derive(Debug, Deserialize, Serialize)] + pub struct BlockAsk { + r#type: String, + blocks: Vec, + attribution: Option, + } + impl BlockAsk { + pub fn new(blocks: Vec) -> Self { + Self::from(blocks) + } + fn default() -> Self { + Self { + r#type: String::from("ask"), + blocks: vec![], + attribution: None, + } + } + } + impl From> for BlockAsk { + fn from(value: Vec) -> Self { + Self { + blocks: value, + ..Self::default() + } + } + } + impl From for BlockAsk { + fn from(value: u64) -> Self { + Self { + blocks: vec![value], + ..Self::default() + } + } + } +} + pub mod text_formatting { use std::{ops::Range, str::FromStr}; @@ -496,18 +603,134 @@ pub mod objects { } } + #[serde_with::skip_serializing_none] + #[derive(Debug, Deserialize, Serialize)] + pub struct ReblogTrailPost { + pub id: String, + pub timestamp: Option, + pub is_commercial: Option, + } + #[serde_with::skip_serializing_none] + #[derive(Debug, Deserialize, Serialize)] + pub struct ReblogTrail { + pub post: Option, + pub blog: Option, + pub content: Vec, + pub layout: Vec, + pub broken_blog_name: Option, + } + + #[serde_with::skip_serializing_none] + #[derive(Debug, Deserialize, Serialize)] + pub struct Avatar { + pub width: u64, + pub height: u64, + pub url: url::Url, + pub accessories: Vec, // TODO: Find values for accessories + } + + #[serde_with::skip_serializing_none] #[derive(Debug, Deserialize, Serialize)] pub struct Post { + object_type: String, pub id: u64, + pub id_string: String, + pub r#type: Option, + pub tumblelog_uuid: Option, + pub original_type: Option, + pub is_blocks_post_format: Option, + pub blog_name: Option, + pub blog: Option, + pub is_blazed: Option, + pub is_bale_pending: Option, + pub can_ignite: Option, + pub can_blaze: Option, + pub post_url: Option, + pub slug: Option, + pub date: Option, + pub timestamp: Option, + pub state: Option, + pub reblog_key: Option, + pub tags: Option>, + pub short_url: Option, + pub summary: Option, + pub should_open_in_legacy: Option, + pub recommended_source: Option, + pub recommended_color: Option, + pub followed: Option, + pub post_author: Option, + pub author_blog: Option, + pub post_author_avatar: Option, + pub liked: Option, + pub note_count: Option, + pub content: Vec, + pub layout: Vec, + pub trail: Vec, + pub can_line: Option, + pub interactability_reblog: Option, + pub interactability_blaze: Option, + pub can_reblog: Option, + pub can_send_in_message: Option, + pub muted: Option, + pub mute_end_timestamp: Option, + pub can_mute: Option, } impl Post { pub fn new(id: u64) -> Self { Self::from(id) } - } - impl Default for Post { + pub fn is_valid(&self) -> bool { + if let Ok(i) = self.id_string.parse::() { + self.id == i + } else { + false + } + } fn default() -> Self { - Self { id: 0 } + Self { + object_type: String::from("post"), + r#type: None, + id: 0, + id_string: String::from("0"), + tumblelog_uuid: None, + original_type: None, + is_blocks_post_format: None, + blog_name: None, + blog: None, + is_blazed: None, + is_bale_pending: None, + can_ignite: None, + can_blaze: None, + post_url: None, + slug: None, + date: None, + timestamp: None, + state: None, + reblog_key: None, + tags: None, + short_url: None, + summary: None, + should_open_in_legacy: None, + recommended_source: None, + recommended_color: None, + followed: None, + post_author: None, + author_blog: None, + post_author_avatar: None, + liked: None, + note_count: None, + content: vec![], + layout: vec![], + trail: vec![], + can_line: None, + interactability_reblog: None, + interactability_blaze: None, + can_reblog: None, + can_send_in_message: None, + muted: None, + mute_end_timestamp: None, + can_mute: None, + } } } impl From for Post {