diff options
Diffstat (limited to 'src/server/object.rs')
-rw-r--r-- | src/server/object.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/server/object.rs b/src/server/object.rs new file mode 100644 index 0000000..9bad6c9 --- /dev/null +++ b/src/server/object.rs @@ -0,0 +1,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() + } +} |