imgchest/model/
post.rs

1use std::num::NonZeroU32;
2use time::OffsetDateTime;
3
4/// An API post object
5#[derive(Debug, serde::Serialize, serde::Deserialize)]
6pub struct Post {
7    /// The post id
8    pub id: Box<str>,
9
10    /// The post title
11    pub title: Option<Box<str>>,
12
13    /// The post author's username
14    pub username: Box<str>,
15
16    /// The privacy of the post
17    pub privacy: Privacy,
18
19    /// ?
20    pub report_status: i32,
21
22    /// The number of views
23    pub views: u64,
24
25    /// Whether the post is nsfw
26    #[serde(with = "crate::serde::u8_to_bool")]
27    pub nsfw: bool,
28
29    /// The number of images
30    pub image_count: u64,
31
32    /// The time this was created
33    #[serde(with = "time::serde::iso8601")]
34    pub created: OffsetDateTime,
35
36    /// The files of this post
37    pub images: Box<[File]>,
38
39    /// The url to delete this post
40    ///
41    /// Only present if the current user owns this post.
42    pub delete_url: Option<Box<str>>,
43    // #[serde(flatten)]
44    // extra: std::collections::HashMap<Box<str>, serde_json::Value>,
45}
46
47/// An API file of a post
48#[derive(Debug, serde::Serialize, serde::Deserialize)]
49pub struct File {
50    /// The id of the image
51    pub id: Box<str>,
52
53    /// The file description
54    pub description: Option<Box<str>>,
55
56    /// The link to the image file
57    pub link: Box<str>,
58
59    /// The position of the image in the post.
60    ///
61    /// Starts at 1.
62    pub position: NonZeroU32,
63
64    /// The time this image was created.
65    #[serde(with = "time::serde::iso8601")]
66    pub created: OffsetDateTime,
67
68    /// The original name of the image.
69    ///
70    /// Only present if the current user owns this image.
71    pub original_name: Option<Box<str>>,
72    // #[serde(flatten)]
73    // extra: std::collections::HashMap<Box<str>, serde_json::Value>,
74}
75
76/// The post privacy
77#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
78pub enum Privacy {
79    #[serde(rename = "public")]
80    Public,
81
82    #[serde(rename = "hidden")]
83    Hidden,
84
85    #[serde(rename = "secret")]
86    Secret,
87}
88
89impl Privacy {
90    /// Get this as a str.
91    pub fn as_str(self) -> &'static str {
92        match self {
93            Self::Public => "public",
94            Self::Hidden => "hidden",
95            Self::Secret => "secret",
96        }
97    }
98}