1use crate::*;
2use cyfs_base::*;
3
4use std::fmt;
5use std::sync::Arc;
6
7#[derive(Clone, Debug)]
8pub struct NONInputRequestCommon {
9 pub req_path: Option<String>,
11
12 pub source: RequestSourceInfo,
14
15 pub level: NONAPILevel,
17
18 pub target: Option<ObjectId>,
20
21 pub flags: u32,
22}
23
24impl fmt::Display for NONInputRequestCommon {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "req_path: {:?}", self.req_path)?;
27
28 write!(f, ", {}", self.source)?;
29 write!(f, ", level: {}", self.level.to_string())?;
30
31 if let Some(target) = &self.target {
32 write!(f, ", target: {}", target.to_string())?;
33 }
34
35 write!(f, ", flags: {}", self.flags)?;
36
37 Ok(())
38 }
39}
40
41#[derive(Clone, Debug)]
46pub struct NONGetObjectInputRequest {
47 pub common: NONInputRequestCommon,
48
49 pub object_id: ObjectId,
50
51 pub inner_path: Option<String>,
53}
54
55impl fmt::Display for NONGetObjectInputRequest {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 write!(f, "common: {}", self.common)?;
58 write!(f, ", object_id: {}", self.object_id)?;
59
60 write!(f, ", inner_path: {:?}", self.inner_path)
61 }
62}
63
64impl NONGetObjectInputRequest {
65 pub fn is_with_inner_path_relation(&self) -> bool {
66 match self.object_id.obj_type_code() {
67 ObjectTypeCode::ObjectMap | ObjectTypeCode::Dir => {
68 self.inner_path.is_some()
69 }
70 _ => false,
71 }
72 }
73}
74
75#[derive(Debug)]
76pub struct NONGetObjectInputResponse {
77 pub object_update_time: Option<u64>,
78 pub object_expires_time: Option<u64>,
79
80 pub object: NONObjectInfo,
81
82 pub attr: Option<Attributes>,
84}
85
86impl NONGetObjectInputResponse {
87 pub fn new(
88 object_id: ObjectId,
89 object_raw: Vec<u8>,
90 object: Option<Arc<AnyNamedObject>>,
91 ) -> Self {
92 let object = NONObjectInfo::new(object_id, object_raw, object);
93 Self::new_with_object(object)
94 }
95
96 pub fn new_with_object(object: NONObjectInfo) -> Self {
97 Self {
98 object,
99 object_expires_time: None,
100 object_update_time: None,
101 attr: None,
102 }
103 }
104
105 pub fn init_times(&mut self) -> BuckyResult<()> {
106 let t = self.object.get_update_time()?;
107 if t > 0 {
108 self.object_update_time = Some(t);
109 }
110
111 let t = self.object.get_expired_time()?;
112 self.object_expires_time = t;
113 Ok(())
114 }
115}
116
117impl fmt::Display for NONGetObjectInputResponse {
118 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119 write!(f, ", object: {}", self.object)?;
120 write!(f, ", object_update_time: {:?}", self.object_update_time)?;
121 write!(f, ", object_expires_time: {:?}", self.object_expires_time)?;
122
123 if let Some(attr) = &self.attr {
124 write!(f, ", attr: {:?}", attr)?;
125 }
126
127 Ok(())
128 }
129}
130
131#[derive(Debug, Clone)]
132pub struct NONPutObjectInputRequest {
133 pub common: NONInputRequestCommon,
134
135 pub object: NONObjectInfo,
136 pub access: Option<AccessString>,
137}
138
139impl fmt::Display for NONPutObjectInputRequest {
140 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
141 write!(f, "common: {}", self.common)?;
142 write!(f, ", object: {}", self.object)?;
143 if let Some(access) = &self.access {
144 write!(f, ", access: {}", access.to_string())?;
145 }
146
147 Ok(())
148 }
149}
150
151#[derive(Debug)]
152pub struct NONPutObjectInputResponse {
153 pub result: NONPutObjectResult,
154 pub object_update_time: Option<u64>,
155 pub object_expires_time: Option<u64>,
156}
157
158impl Default for NONPutObjectInputResponse {
159 fn default() -> Self {
160 Self::new(NONPutObjectResult::Accept)
161 }
162}
163
164impl NONPutObjectInputResponse {
165 pub fn new(result: NONPutObjectResult) -> Self {
166 Self {
167 result,
168 object_update_time: None,
169 object_expires_time: None,
170 }
171 }
172}
173
174impl fmt::Display for NONPutObjectInputResponse {
175 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176 write!(f, "result: {:?}", self.result)?;
177 write!(f, ", object_update_time: {:?}", self.object_update_time)?;
178 write!(f, ", object_expires_time: {:?}", self.object_expires_time)
179 }
180}
181
182#[derive(Debug, Clone)]
184pub struct NONPostObjectInputRequest {
185 pub common: NONInputRequestCommon,
186
187 pub object: NONObjectInfo,
188}
189
190impl fmt::Display for NONPostObjectInputRequest {
191 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
192 write!(f, "common: {}", self.common)?;
193 write!(f, ", object: {}", self.object)
194 }
195}
196
197#[derive(Debug)]
198pub struct NONPostObjectInputResponse {
199 pub object: Option<NONObjectInfo>,
200}
201
202impl fmt::Display for NONPostObjectInputResponse {
203 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
204 match &self.object {
205 Some(object) => {
206 write!(f, "object: {}", object,)
207 }
208 None => {
209 write!(f, "none",)
210 }
211 }
212 }
213}
214
215#[derive(Debug, Clone)]
217pub struct NONSelectObjectInputRequest {
218 pub common: NONInputRequestCommon,
219
220 pub filter: SelectFilter,
221 pub opt: Option<SelectOption>,
222}
223
224impl fmt::Display for NONSelectObjectInputRequest {
225 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
226 write!(f, "common: {}", self.common)?;
227 write!(f, ", filter: {}", self.filter)?;
228 write!(f, ", opt: {:?}", self.opt)
229 }
230}
231
232#[derive(Debug)]
233pub struct NONSelectObjectInputResponse {
234 pub objects: Vec<SelectResponseObjectInfo>,
235}
236
237impl fmt::Display for NONSelectObjectInputResponse {
238 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
239 write!(f, "select count: {}, list=[", self.objects.len())?;
240
241 for item in &self.objects {
242 write!(f, "{{ {} }}, ", item)?;
243 }
244
245 write!(f, "]")?;
246
247 Ok(())
248 }
249}
250
251#[derive(Debug, Clone)]
253pub struct NONDeleteObjectInputRequest {
254 pub common: NONInputRequestCommon,
255
256 pub object_id: ObjectId,
257
258 pub inner_path: Option<String>,
259}
260
261impl fmt::Display for NONDeleteObjectInputRequest {
262 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
263 write!(f, "common: {}", self.common)?;
264 write!(f, ", object_id: {}", self.object_id)?;
265
266 if let Some(inner_path) = &self.inner_path {
267 write!(f, ", inner_path: {}", inner_path)?;
268 }
269
270 Ok(())
271 }
272}
273
274#[derive(Debug)]
275pub struct NONDeleteObjectInputResponse {
276 pub object: Option<NONObjectInfo>,
277}
278
279impl fmt::Display for NONDeleteObjectInputResponse {
280 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
281 if let Some(item) = &self.object {
282 write!(f, "object: {}", item)?;
283 }
284 Ok(())
285 }
286}