aboutsummaryrefslogtreecommitdiff
path: root/src/server/object.rs
blob: 9bad6c95e314736d4924f6985669b4a50313329e (plain)
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
use super::blobref::BlobRef;
use crate::common::mime::MimeType;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

#[derive(Debug)]
pub(super) struct Attrs {
    pub name: Option<String>,
    pub group: Option<BlobRef>,
    pub mime: Option<MimeType>,
    pub created_at: Option<OffsetDateTime>,
    pub updated_at: Option<OffsetDateTime>,
    pub deleted_at: Option<OffsetDateTime>,
    pub tags: Vec<String>,
    pub note: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub(super) struct Chunk {
    pub size: usize,
    pub offset: usize,
    pub blobref: BlobRef,
}

#[derive(Debug)]
pub struct Object {
    pub(super) blobref: BlobRef,
    pub(super) size: usize,
    pub(super) chunks: Vec<Chunk>,
    pub(super) attrs: Attrs,
    pub(super) created_at: Option<OffsetDateTime>,
    pub(super) updated_at: Option<OffsetDateTime>,
}

impl Object {
    pub fn blobref(&self) -> &BlobRef {
        &self.blobref
    }

    pub fn size(&self) -> usize {
        self.size
    }

    pub fn is_group(&self) -> bool {
        matches!(self.attrs.mime, Some(MimeType::ApplicationXGroup))
    }

    pub fn get_name(&self) -> Option<String> {
        self.attrs.name.clone()
    }
}