1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use serde::Deserialize;

/// Metadata associated with attachment
#[derive(Deserialize, Debug, Clone)]
#[serde(tag = "type")]
pub enum Metadata {
    /// Attachment is just a generic uncategorised file
    File,

    /// Attachment contains textual data and should be displayed as such
    Text,

    /// Attachment is an image with specific dimensions
    Image { width: isize, height: isize },

    /// Attachment is a video with specific dimensions
    Video { width: isize, height: isize },

    /// Attachment is audio
    Audio,
}

impl Default for Metadata {
    fn default() -> Metadata {
        Metadata::File
    }
}

/// Representation of an attachment on Revolt
#[derive(Deserialize, Debug, Clone)]
pub struct Attachment {
    /// Unique Id
    #[serde(rename = "_id")]
    pub id: String,

    /// Tag/bucket this attachment was uploaded to
    pub tag: String,

    /// Original filename
    pub filename: String,

    /// Parsed metadata of this attachment
    pub metadata: Metadata,

    /// Raw content type of this attachment
    pub content_type: String,

    /// Size of this attachment (in bytes)
    pub size: isize,

    /// Whether this attachment was deleted
    pub deleted: Option<bool>,

    /// Whether this attachment was reported
    pub reported: Option<bool>,

    // NOTE: Theese 3 fields will be deprecated in the next update
    pub message_id: Option<String>,
    pub user_id: Option<String>,
    pub server_id: Option<String>,

    /// ID of the object this attachment is associated with
    pub object_id: Option<String>,
}