1use chrono::{DateTime, Utc};
20use serde::{Deserialize, Serialize};
21
22use crate::neo_fs::types::{Attributes, ContainerId, ObjectId, ObjectType, OwnerId};
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct Object {
27 pub id: Option<ObjectId>,
29 pub container_id: ContainerId,
31 pub owner_id: OwnerId,
33 pub object_type: ObjectType,
35 #[serde(skip_serializing, skip_deserializing)]
37 pub payload: Vec<u8>,
38 pub attributes: Attributes,
40 #[serde(skip_serializing_if = "Option::is_none")]
42 #[serde(with = "chrono::serde::ts_seconds_option")]
43 pub created_at: Option<DateTime<Utc>>,
44}
45
46impl Object {
47 pub fn new(container_id: ContainerId, owner_id: OwnerId) -> Self {
49 Self {
50 id: None,
51 container_id,
52 owner_id,
53 object_type: ObjectType::Regular,
54 payload: Vec::new(),
55 attributes: Attributes::new(),
56 created_at: None,
57 }
58 }
59
60 pub fn with_payload(mut self, payload: Vec<u8>) -> Self {
62 self.payload = payload;
63 self
64 }
65
66 pub fn with_type(mut self, object_type: ObjectType) -> Self {
68 self.object_type = object_type;
69 self
70 }
71
72 pub fn with_attribute(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
74 self.attributes.add(key, value);
75 self
76 }
77
78 pub fn with_filename(self, filename: impl Into<String>) -> Self {
80 self.with_attribute("FileName", filename)
81 }
82
83 pub fn with_content_type(self, content_type: impl Into<String>) -> Self {
85 self.with_attribute("Content-Type", content_type)
86 }
87
88 pub fn size(&self) -> usize {
90 self.payload.len()
91 }
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct MultipartUpload {
99 pub id: Option<ObjectId>,
101 pub container_id: ContainerId,
103 pub owner_id: OwnerId,
105 pub upload_id: String,
107 pub attributes: Attributes,
109 pub part_size: u64,
111 pub max_parts: u64,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct Part {
118 pub part_number: u32,
120 #[serde(skip_serializing, skip_deserializing)]
122 pub payload: Vec<u8>,
123}
124
125impl Part {
126 pub fn new(part_number: u32, payload: Vec<u8>) -> Self {
128 Self { part_number, payload }
129 }
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct MultipartUploadResult {
135 pub object_id: ObjectId,
137 pub container_id: ContainerId,
139}