feat: post and layout structs
This commit is contained in:
@@ -1,11 +1,4 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct NPF {
|
||||
pub content: Vec<blocks::BlockValue>,
|
||||
}
|
||||
|
||||
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<DisplayBlocks>,
|
||||
pub truncate_after: Option<u32>,
|
||||
}
|
||||
impl BlockRows {
|
||||
pub fn new(blocks: Vec<DisplayBlocks>) -> Self {
|
||||
Self::from(blocks)
|
||||
}
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
r#type: String::from("rows"),
|
||||
display: vec![],
|
||||
truncate_after: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Vec<DisplayBlocks>> for BlockRows {
|
||||
fn from(value: Vec<DisplayBlocks>) -> Self {
|
||||
Self {
|
||||
display: value,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<DisplayBlocks> for BlockRows {
|
||||
fn from(value: DisplayBlocks) -> Self {
|
||||
Self {
|
||||
display: vec![value],
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct DisplayBlocks {
|
||||
pub blocks: Vec<u64>,
|
||||
pub mode: Option<String>,
|
||||
}
|
||||
impl DisplayBlocks {
|
||||
pub fn new(blocks: Vec<u64>) -> Self {
|
||||
Self::from(blocks)
|
||||
}
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
blocks: vec![],
|
||||
mode: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Vec<u64>> for DisplayBlocks {
|
||||
fn from(value: Vec<u64>) -> Self {
|
||||
Self {
|
||||
blocks: value,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<u64> 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<u64>,
|
||||
attribution: Option<super::attributions::AttributionBlog>,
|
||||
}
|
||||
impl BlockAsk {
|
||||
pub fn new(blocks: Vec<u64>) -> Self {
|
||||
Self::from(blocks)
|
||||
}
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
r#type: String::from("ask"),
|
||||
blocks: vec![],
|
||||
attribution: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Vec<u64>> for BlockAsk {
|
||||
fn from(value: Vec<u64>) -> Self {
|
||||
Self {
|
||||
blocks: value,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<u64> 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<String>,
|
||||
pub is_commercial: Option<bool>,
|
||||
}
|
||||
#[serde_with::skip_serializing_none]
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct ReblogTrail {
|
||||
pub post: Option<ReblogTrailPost>,
|
||||
pub blog: Option<BlogInfo>,
|
||||
pub content: Vec<super::content_blocks::BlockValue>,
|
||||
pub layout: Vec<super::layout_blocks::BlockValue>,
|
||||
pub broken_blog_name: Option<bool>,
|
||||
}
|
||||
|
||||
#[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<serde_json::Value>, // 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<String>,
|
||||
pub tumblelog_uuid: Option<String>,
|
||||
pub original_type: Option<String>,
|
||||
pub is_blocks_post_format: Option<bool>,
|
||||
pub blog_name: Option<String>,
|
||||
pub blog: Option<BlogInfo>,
|
||||
pub is_blazed: Option<bool>,
|
||||
pub is_bale_pending: Option<bool>,
|
||||
pub can_ignite: Option<bool>,
|
||||
pub can_blaze: Option<bool>,
|
||||
pub post_url: Option<url::Url>,
|
||||
pub slug: Option<String>,
|
||||
pub date: Option<String>,
|
||||
pub timestamp: Option<String>,
|
||||
pub state: Option<String>,
|
||||
pub reblog_key: Option<String>,
|
||||
pub tags: Option<Vec<String>>,
|
||||
pub short_url: Option<String>,
|
||||
pub summary: Option<String>,
|
||||
pub should_open_in_legacy: Option<bool>,
|
||||
pub recommended_source: Option<String>,
|
||||
pub recommended_color: Option<String>,
|
||||
pub followed: Option<String>,
|
||||
pub post_author: Option<String>,
|
||||
pub author_blog: Option<BlogInfo>,
|
||||
pub post_author_avatar: Option<Avatar>,
|
||||
pub liked: Option<bool>,
|
||||
pub note_count: Option<u64>,
|
||||
pub content: Vec<super::content_blocks::BlockValue>,
|
||||
pub layout: Vec<super::layout_blocks::BlockValue>,
|
||||
pub trail: Vec<ReblogTrail>,
|
||||
pub can_line: Option<bool>,
|
||||
pub interactability_reblog: Option<String>,
|
||||
pub interactability_blaze: Option<String>,
|
||||
pub can_reblog: Option<bool>,
|
||||
pub can_send_in_message: Option<bool>,
|
||||
pub muted: Option<bool>,
|
||||
pub mute_end_timestamp: Option<u64>,
|
||||
pub can_mute: Option<bool>,
|
||||
}
|
||||
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::<u64>() {
|
||||
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<u64> for Post {
|
||||
|
||||
Reference in New Issue
Block a user