1#[derive(Debug, Clone, Default)]
4#[doc = "调用 API 所用的 URL 查询参数"]
5pub struct QueryParams<'a> {
6 map: indexmap::IndexMap<qiniu_http_client::QueryPairKey<'a>, qiniu_http_client::QueryPairValue<'a>>,
7}
8impl<'a> QueryParams<'a> {
9 #[inline]
10 #[must_use]
11 #[doc = "插入一个新的查询参数对"]
12 pub fn insert(
13 mut self,
14 query_pair_key: qiniu_http_client::QueryPairKey<'a>,
15 query_pair_value: qiniu_http_client::QueryPairValue<'a>,
16 ) -> Self {
17 self.map.insert(query_pair_key, query_pair_value);
18 self
19 }
20 fn build(self) -> Vec<qiniu_http_client::QueryPair<'a>> {
21 Vec::from_iter(self.map)
22 }
23}
24impl<'a> From<QueryParams<'a>> for Vec<qiniu_http_client::QueryPair<'a>> {
25 #[inline]
26 fn from(map: QueryParams<'a>) -> Self {
27 map.build()
28 }
29}
30impl<'a> QueryParams<'a> {
31 #[inline]
32 #[must_use]
33 #[doc = "指定存储空间"]
34 pub fn set_bucket_as_str(self, value: impl Into<qiniu_http_client::QueryPairValue<'a>>) -> Self {
35 self.insert("bucket".into(), value.into())
36 }
37 #[inline]
38 #[must_use]
39 #[doc = "上一次列举返回的位置标记,作为本次列举的起点信息"]
40 pub fn set_marker_as_str(self, value: impl Into<qiniu_http_client::QueryPairValue<'a>>) -> Self {
41 self.insert("marker".into(), value.into())
42 }
43 #[inline]
44 #[must_use]
45 #[doc = "本次列举的条目数,范围为 1-1000"]
46 pub fn set_limit_as_i8(self, value: i8) -> Self {
47 self.insert("limit".into(), value.to_string().into())
48 }
49 #[inline]
50 #[must_use]
51 #[doc = "本次列举的条目数,范围为 1-1000"]
52 pub fn set_limit_as_i16(self, value: i16) -> Self {
53 self.insert("limit".into(), value.to_string().into())
54 }
55 #[inline]
56 #[must_use]
57 #[doc = "本次列举的条目数,范围为 1-1000"]
58 pub fn set_limit_as_i32(self, value: i32) -> Self {
59 self.insert("limit".into(), value.to_string().into())
60 }
61 #[inline]
62 #[must_use]
63 #[doc = "本次列举的条目数,范围为 1-1000"]
64 pub fn set_limit_as_i64(self, value: i64) -> Self {
65 self.insert("limit".into(), value.to_string().into())
66 }
67 #[inline]
68 #[must_use]
69 #[doc = "本次列举的条目数,范围为 1-1000"]
70 pub fn set_limit_as_isize(self, value: isize) -> Self {
71 self.insert("limit".into(), value.to_string().into())
72 }
73 #[inline]
74 #[must_use]
75 #[doc = "本次列举的条目数,范围为 1-1000"]
76 pub fn set_limit_as_u8(self, value: u8) -> Self {
77 self.insert("limit".into(), value.to_string().into())
78 }
79 #[inline]
80 #[must_use]
81 #[doc = "本次列举的条目数,范围为 1-1000"]
82 pub fn set_limit_as_u16(self, value: u16) -> Self {
83 self.insert("limit".into(), value.to_string().into())
84 }
85 #[inline]
86 #[must_use]
87 #[doc = "本次列举的条目数,范围为 1-1000"]
88 pub fn set_limit_as_u32(self, value: u32) -> Self {
89 self.insert("limit".into(), value.to_string().into())
90 }
91 #[inline]
92 #[must_use]
93 #[doc = "本次列举的条目数,范围为 1-1000"]
94 pub fn set_limit_as_u64(self, value: u64) -> Self {
95 self.insert("limit".into(), value.to_string().into())
96 }
97 #[inline]
98 #[must_use]
99 #[doc = "本次列举的条目数,范围为 1-1000"]
100 pub fn set_limit_as_usize(self, value: usize) -> Self {
101 self.insert("limit".into(), value.to_string().into())
102 }
103 #[inline]
104 #[must_use]
105 #[doc = "指定前缀,只有资源名匹配该前缀的资源会被列出"]
106 pub fn set_prefix_as_str(self, value: impl Into<qiniu_http_client::QueryPairValue<'a>>) -> Self {
107 self.insert("prefix".into(), value.into())
108 }
109 #[inline]
110 #[must_use]
111 #[doc = "指定目录分隔符,列出所有公共前缀(模拟列出目录效果)"]
112 pub fn set_delimiter_as_str(self, value: impl Into<qiniu_http_client::QueryPairValue<'a>>) -> Self {
113 self.insert("delimiter".into(), value.into())
114 }
115 #[inline]
116 #[must_use]
117 #[doc = "如果文件是通过分片上传的,是否返回对应的分片信息"]
118 pub fn set_need_parts_as_bool(self, value: bool) -> Self {
119 self.insert("needparts".into(), value.to_string().into())
120 }
121}
122#[derive(Clone, Debug, serde :: Serialize, serde :: Deserialize)]
123#[serde(transparent)]
124#[doc = "获取 API 所用的响应体参数"]
125pub struct ResponseBody(serde_json::Value);
126impl ResponseBody {
127 #[allow(dead_code)]
128 pub(crate) fn new(value: serde_json::Value) -> Self {
129 Self(value)
130 }
131}
132impl Default for ResponseBody {
133 #[inline]
134 fn default() -> Self {
135 Self(serde_json::Value::Object(Default::default()))
136 }
137}
138impl From<ResponseBody> for serde_json::Value {
139 #[inline]
140 fn from(val: ResponseBody) -> Self {
141 val.0
142 }
143}
144impl AsRef<serde_json::Value> for ResponseBody {
145 #[inline]
146 fn as_ref(&self) -> &serde_json::Value {
147 &self.0
148 }
149}
150impl AsMut<serde_json::Value> for ResponseBody {
151 #[inline]
152 fn as_mut(&mut self) -> &mut serde_json::Value {
153 &mut self.0
154 }
155}
156impl ResponseBody {
157 #[doc = "获取 有剩余条目则返回非空字符串,作为下一次列举的参数传入,如果没有剩余条目则返回空字符串"]
158 pub fn get_marker_as_str(&self) -> Option<&str> {
159 self.0
160 .as_object()
161 .and_then(|obj| obj.get("marker"))
162 .and_then(|val| val.as_str())
163 }
164}
165impl ResponseBody {
166 #[doc = "设置 有剩余条目则返回非空字符串,作为下一次列举的参数传入,如果没有剩余条目则返回空字符串"]
167 pub fn set_marker_as_str(&mut self, new: String) -> Option<String> {
168 self.0.as_object_mut().and_then(|object| {
169 object
170 .insert("marker".to_owned(), new.into())
171 .and_then(|val| match val {
172 serde_json::Value::String(s) => Some(s),
173 _ => None,
174 })
175 })
176 }
177}
178#[derive(Clone, Debug, serde :: Serialize, serde :: Deserialize)]
179#[serde(transparent)]
180#[doc = "公共前缀的数组"]
181pub struct CommonPrefixes(serde_json::Value);
182impl CommonPrefixes {
183 #[allow(dead_code)]
184 pub(crate) fn new(value: serde_json::Value) -> Self {
185 Self(value)
186 }
187}
188impl Default for CommonPrefixes {
189 #[inline]
190 fn default() -> Self {
191 Self(serde_json::Value::Array(Default::default()))
192 }
193}
194impl From<CommonPrefixes> for serde_json::Value {
195 #[inline]
196 fn from(val: CommonPrefixes) -> Self {
197 val.0
198 }
199}
200impl AsRef<serde_json::Value> for CommonPrefixes {
201 #[inline]
202 fn as_ref(&self) -> &serde_json::Value {
203 &self.0
204 }
205}
206impl AsMut<serde_json::Value> for CommonPrefixes {
207 #[inline]
208 fn as_mut(&mut self) -> &mut serde_json::Value {
209 &mut self.0
210 }
211}
212impl CommonPrefixes {
213 #[doc = "解析 JSON 得到 String 列表"]
214 pub fn to_str_vec(&self) -> Vec<&str> {
215 self.0
216 .as_array()
217 .unwrap()
218 .iter()
219 .map(|ele| ele.as_str().unwrap())
220 .collect()
221 }
222}
223impl From<Vec<String>> for CommonPrefixes {
224 #[inline]
225 fn from(val: Vec<String>) -> Self {
226 Self(serde_json::Value::from(val))
227 }
228}
229impl CommonPrefixes {
230 #[doc = "获取数组的长度"]
231 pub fn len(&self) -> usize {
232 self.0.as_array().unwrap().len()
233 }
234 #[doc = "数组是否为空"]
235 pub fn is_empty(&self) -> bool {
236 self.0.as_array().unwrap().is_empty()
237 }
238}
239impl CommonPrefixes {
240 #[doc = "在列表的指定位置插入 JSON String"]
241 pub fn insert_str(&mut self, index: usize, val: String) {
242 self.0.as_array_mut().unwrap().insert(index, val.into());
243 }
244}
245impl CommonPrefixes {
246 #[doc = "在列表的指定位置移出 JSON String"]
247 pub fn remove_as_str(&mut self, index: usize) -> Option<String> {
248 match self.0.as_array_mut().unwrap().remove(index) {
249 serde_json::Value::String(s) => Some(s),
250 _ => None,
251 }
252 }
253}
254impl CommonPrefixes {
255 #[doc = "在列表尾部追加 JSON String"]
256 pub fn push_str(&mut self, val: String) {
257 self.0.as_array_mut().unwrap().push(val.into());
258 }
259}
260impl CommonPrefixes {
261 #[doc = "在列表尾部取出 JSON String"]
262 pub fn pop_as_str(&mut self) -> Option<String> {
263 self.0.as_array_mut().unwrap().pop().and_then(|val| match val {
264 serde_json::Value::String(s) => Some(s),
265 _ => None,
266 })
267 }
268}
269impl ResponseBody {
270 #[doc = "获取 公共前缀的数组,如没有指定 delimiter 参数则不返回"]
271 pub fn get_common_prefixes(&self) -> Option<CommonPrefixes> {
272 self.0
273 .as_object()
274 .and_then(|obj| obj.get("common_prefixes"))
275 .cloned()
276 .map(CommonPrefixes::new)
277 }
278}
279impl ResponseBody {
280 #[doc = "设置 公共前缀的数组,如没有指定 delimiter 参数则不返回"]
281 pub fn set_common_prefixes(&mut self, new: CommonPrefixes) -> Option<CommonPrefixes> {
282 self.0.as_object_mut().and_then(|object| {
283 object
284 .insert("common_prefixes".to_owned(), new.into())
285 .map(CommonPrefixes::new)
286 })
287 }
288}
289#[derive(Clone, Debug, serde :: Serialize, serde :: Deserialize)]
290#[serde(transparent)]
291#[doc = "条目的数组,不能用来判断是否还有剩余条目"]
292pub struct ListedObjects(serde_json::Value);
293impl ListedObjects {
294 #[allow(dead_code)]
295 pub(crate) fn new(value: serde_json::Value) -> Self {
296 Self(value)
297 }
298}
299impl Default for ListedObjects {
300 #[inline]
301 fn default() -> Self {
302 Self(serde_json::Value::Array(Default::default()))
303 }
304}
305impl From<ListedObjects> for serde_json::Value {
306 #[inline]
307 fn from(val: ListedObjects) -> Self {
308 val.0
309 }
310}
311impl AsRef<serde_json::Value> for ListedObjects {
312 #[inline]
313 fn as_ref(&self) -> &serde_json::Value {
314 &self.0
315 }
316}
317impl AsMut<serde_json::Value> for ListedObjects {
318 #[inline]
319 fn as_mut(&mut self) -> &mut serde_json::Value {
320 &mut self.0
321 }
322}
323#[derive(Clone, Debug, serde :: Serialize, serde :: Deserialize)]
324#[serde(transparent)]
325#[doc = "对象条目,包含对象的元信息"]
326pub struct ListedObjectEntry(serde_json::Value);
327impl ListedObjectEntry {
328 #[allow(dead_code)]
329 pub(crate) fn new(value: serde_json::Value) -> Self {
330 Self(value)
331 }
332}
333impl Default for ListedObjectEntry {
334 #[inline]
335 fn default() -> Self {
336 Self(serde_json::Value::Object(Default::default()))
337 }
338}
339impl From<ListedObjectEntry> for serde_json::Value {
340 #[inline]
341 fn from(val: ListedObjectEntry) -> Self {
342 val.0
343 }
344}
345impl AsRef<serde_json::Value> for ListedObjectEntry {
346 #[inline]
347 fn as_ref(&self) -> &serde_json::Value {
348 &self.0
349 }
350}
351impl AsMut<serde_json::Value> for ListedObjectEntry {
352 #[inline]
353 fn as_mut(&mut self) -> &mut serde_json::Value {
354 &mut self.0
355 }
356}
357impl ListedObjectEntry {
358 #[doc = "获取 对象名称"]
359 pub fn get_key_as_str(&self) -> &str {
360 self.0.as_object().unwrap().get("key").unwrap().as_str().unwrap()
361 }
362}
363impl ListedObjectEntry {
364 #[doc = "设置 对象名称"]
365 pub fn set_key_as_str(&mut self, new: String) -> Option<String> {
366 self.0
367 .as_object_mut()
368 .unwrap()
369 .insert("key".to_owned(), new.into())
370 .and_then(|val| match val {
371 serde_json::Value::String(s) => Some(s),
372 _ => None,
373 })
374 }
375}
376impl ListedObjectEntry {
377 #[doc = "获取 文件上传时间,UNIX 时间戳格式,单位为 100 纳秒"]
378 pub fn get_put_time_as_i64(&self) -> i64 {
379 self.0.as_object().unwrap().get("putTime").unwrap().as_i64().unwrap()
380 }
381}
382impl ListedObjectEntry {
383 #[doc = "设置 文件上传时间,UNIX 时间戳格式,单位为 100 纳秒"]
384 pub fn set_put_time_as_i64(&mut self, new: i64) -> Option<i64> {
385 self.0
386 .as_object_mut()
387 .unwrap()
388 .insert("putTime".to_owned(), new.into())
389 .and_then(|val| val.as_i64())
390 }
391}
392impl ListedObjectEntry {
393 #[doc = "获取 文件上传时间,UNIX 时间戳格式,单位为 100 纳秒"]
394 pub fn get_put_time_as_u64(&self) -> u64 {
395 self.0.as_object().unwrap().get("putTime").unwrap().as_u64().unwrap()
396 }
397}
398impl ListedObjectEntry {
399 #[doc = "设置 文件上传时间,UNIX 时间戳格式,单位为 100 纳秒"]
400 pub fn set_put_time_as_u64(&mut self, new: u64) -> Option<u64> {
401 self.0
402 .as_object_mut()
403 .unwrap()
404 .insert("putTime".to_owned(), new.into())
405 .and_then(|val| val.as_u64())
406 }
407}
408impl ListedObjectEntry {
409 #[doc = "获取 文件的哈希值"]
410 pub fn get_hash_as_str(&self) -> &str {
411 self.0.as_object().unwrap().get("hash").unwrap().as_str().unwrap()
412 }
413}
414impl ListedObjectEntry {
415 #[doc = "设置 文件的哈希值"]
416 pub fn set_hash_as_str(&mut self, new: String) -> Option<String> {
417 self.0
418 .as_object_mut()
419 .unwrap()
420 .insert("hash".to_owned(), new.into())
421 .and_then(|val| match val {
422 serde_json::Value::String(s) => Some(s),
423 _ => None,
424 })
425 }
426}
427impl ListedObjectEntry {
428 #[doc = "获取 对象大小,单位为字节"]
429 pub fn get_size_as_i64(&self) -> i64 {
430 self.0.as_object().unwrap().get("fsize").unwrap().as_i64().unwrap()
431 }
432}
433impl ListedObjectEntry {
434 #[doc = "设置 对象大小,单位为字节"]
435 pub fn set_size_as_i64(&mut self, new: i64) -> Option<i64> {
436 self.0
437 .as_object_mut()
438 .unwrap()
439 .insert("fsize".to_owned(), new.into())
440 .and_then(|val| val.as_i64())
441 }
442}
443impl ListedObjectEntry {
444 #[doc = "获取 对象大小,单位为字节"]
445 pub fn get_size_as_u64(&self) -> u64 {
446 self.0.as_object().unwrap().get("fsize").unwrap().as_u64().unwrap()
447 }
448}
449impl ListedObjectEntry {
450 #[doc = "设置 对象大小,单位为字节"]
451 pub fn set_size_as_u64(&mut self, new: u64) -> Option<u64> {
452 self.0
453 .as_object_mut()
454 .unwrap()
455 .insert("fsize".to_owned(), new.into())
456 .and_then(|val| val.as_u64())
457 }
458}
459impl ListedObjectEntry {
460 #[doc = "获取 对象 MIME 类型"]
461 pub fn get_mime_type_as_str(&self) -> &str {
462 self.0.as_object().unwrap().get("mimeType").unwrap().as_str().unwrap()
463 }
464}
465impl ListedObjectEntry {
466 #[doc = "设置 对象 MIME 类型"]
467 pub fn set_mime_type_as_str(&mut self, new: String) -> Option<String> {
468 self.0
469 .as_object_mut()
470 .unwrap()
471 .insert("mimeType".to_owned(), new.into())
472 .and_then(|val| match val {
473 serde_json::Value::String(s) => Some(s),
474 _ => None,
475 })
476 }
477}
478impl ListedObjectEntry {
479 #[doc = "获取 资源内容的唯一属主标识"]
480 pub fn get_end_user_as_str(&self) -> Option<&str> {
481 self.0
482 .as_object()
483 .and_then(|obj| obj.get("endUser"))
484 .and_then(|val| val.as_str())
485 }
486}
487impl ListedObjectEntry {
488 #[doc = "设置 资源内容的唯一属主标识"]
489 pub fn set_end_user_as_str(&mut self, new: String) -> Option<String> {
490 self.0.as_object_mut().and_then(|object| {
491 object
492 .insert("endUser".to_owned(), new.into())
493 .and_then(|val| match val {
494 serde_json::Value::String(s) => Some(s),
495 _ => None,
496 })
497 })
498 }
499}
500impl ListedObjectEntry {
501 #[doc = "获取 对象存储类型,`0` 表示普通存储,`1` 表示低频存储,`2` 表示归档存储"]
502 pub fn get_type_as_i64(&self) -> Option<i64> {
503 self.0
504 .as_object()
505 .and_then(|obj| obj.get("type"))
506 .and_then(|val| val.as_i64())
507 }
508}
509impl ListedObjectEntry {
510 #[doc = "设置 对象存储类型,`0` 表示普通存储,`1` 表示低频存储,`2` 表示归档存储"]
511 pub fn set_type_as_i64(&mut self, new: i64) -> Option<i64> {
512 self.0.as_object_mut().and_then(|object| {
513 object
514 .insert("type".to_owned(), new.into())
515 .and_then(|val| val.as_i64())
516 })
517 }
518}
519impl ListedObjectEntry {
520 #[doc = "获取 对象存储类型,`0` 表示普通存储,`1` 表示低频存储,`2` 表示归档存储"]
521 pub fn get_type_as_u64(&self) -> Option<u64> {
522 self.0
523 .as_object()
524 .and_then(|obj| obj.get("type"))
525 .and_then(|val| val.as_u64())
526 }
527}
528impl ListedObjectEntry {
529 #[doc = "设置 对象存储类型,`0` 表示普通存储,`1` 表示低频存储,`2` 表示归档存储"]
530 pub fn set_type_as_u64(&mut self, new: u64) -> Option<u64> {
531 self.0.as_object_mut().and_then(|object| {
532 object
533 .insert("type".to_owned(), new.into())
534 .and_then(|val| val.as_u64())
535 })
536 }
537}
538impl ListedObjectEntry {
539 #[doc = "获取 文件的存储状态,即禁用状态和启用状态间的的互相转换,`0` 表示启用,`1`表示禁用"]
540 pub fn get_unfreezing_status_as_i64(&self) -> i64 {
541 self.0.as_object().unwrap().get("status").unwrap().as_i64().unwrap()
542 }
543}
544impl ListedObjectEntry {
545 #[doc = "设置 文件的存储状态,即禁用状态和启用状态间的的互相转换,`0` 表示启用,`1`表示禁用"]
546 pub fn set_unfreezing_status_as_i64(&mut self, new: i64) -> Option<i64> {
547 self.0
548 .as_object_mut()
549 .unwrap()
550 .insert("status".to_owned(), new.into())
551 .and_then(|val| val.as_i64())
552 }
553}
554impl ListedObjectEntry {
555 #[doc = "获取 文件的存储状态,即禁用状态和启用状态间的的互相转换,`0` 表示启用,`1`表示禁用"]
556 pub fn get_unfreezing_status_as_u64(&self) -> u64 {
557 self.0.as_object().unwrap().get("status").unwrap().as_u64().unwrap()
558 }
559}
560impl ListedObjectEntry {
561 #[doc = "设置 文件的存储状态,即禁用状态和启用状态间的的互相转换,`0` 表示启用,`1`表示禁用"]
562 pub fn set_unfreezing_status_as_u64(&mut self, new: u64) -> Option<u64> {
563 self.0
564 .as_object_mut()
565 .unwrap()
566 .insert("status".to_owned(), new.into())
567 .and_then(|val| val.as_u64())
568 }
569}
570impl ListedObjectEntry {
571 #[doc = "获取 对象 MD5 值,只有通过直传文件和追加文件 API 上传的文件,服务端确保有该字段返回"]
572 pub fn get_md_5_as_str(&self) -> Option<&str> {
573 self.0
574 .as_object()
575 .and_then(|obj| obj.get("md5"))
576 .and_then(|val| val.as_str())
577 }
578}
579impl ListedObjectEntry {
580 #[doc = "设置 对象 MD5 值,只有通过直传文件和追加文件 API 上传的文件,服务端确保有该字段返回"]
581 pub fn set_md_5_as_str(&mut self, new: String) -> Option<String> {
582 self.0.as_object_mut().and_then(|object| {
583 object.insert("md5".to_owned(), new.into()).and_then(|val| match val {
584 serde_json::Value::String(s) => Some(s),
585 _ => None,
586 })
587 })
588 }
589}
590#[derive(Clone, Debug, serde :: Serialize, serde :: Deserialize)]
591#[serde(transparent)]
592#[doc = "每个分片的大小"]
593pub struct PartSizes(serde_json::Value);
594impl PartSizes {
595 #[allow(dead_code)]
596 pub(crate) fn new(value: serde_json::Value) -> Self {
597 Self(value)
598 }
599}
600impl Default for PartSizes {
601 #[inline]
602 fn default() -> Self {
603 Self(serde_json::Value::Array(Default::default()))
604 }
605}
606impl From<PartSizes> for serde_json::Value {
607 #[inline]
608 fn from(val: PartSizes) -> Self {
609 val.0
610 }
611}
612impl AsRef<serde_json::Value> for PartSizes {
613 #[inline]
614 fn as_ref(&self) -> &serde_json::Value {
615 &self.0
616 }
617}
618impl AsMut<serde_json::Value> for PartSizes {
619 #[inline]
620 fn as_mut(&mut self) -> &mut serde_json::Value {
621 &mut self.0
622 }
623}
624impl PartSizes {
625 #[doc = "获取数组的长度"]
626 pub fn len(&self) -> usize {
627 self.0.as_array().unwrap().len()
628 }
629 #[doc = "数组是否为空"]
630 pub fn is_empty(&self) -> bool {
631 self.0.as_array().unwrap().is_empty()
632 }
633}
634impl PartSizes {
635 #[doc = "解析 JSON 得到整型列表"]
636 pub fn to_i64_vec(&self) -> Vec<i64> {
637 self.0
638 .as_array()
639 .unwrap()
640 .iter()
641 .map(|ele| ele.as_i64().unwrap())
642 .collect()
643 }
644}
645impl PartSizes {
646 #[doc = "解析 JSON 得到无符号整型列表"]
647 pub fn to_u64_vec(&self) -> Vec<u64> {
648 self.0
649 .as_array()
650 .unwrap()
651 .iter()
652 .map(|ele| ele.as_u64().unwrap())
653 .collect()
654 }
655}
656impl PartSizes {
657 #[doc = "在列表的指定位置移出 JSON i64 整型"]
658 pub fn remove_as_i64(&mut self, index: usize) -> Option<i64> {
659 match self.0.as_array_mut().unwrap().remove(index) {
660 serde_json::Value::Number(s) => s.as_i64(),
661 _ => None,
662 }
663 }
664}
665impl PartSizes {
666 #[doc = "在列表尾部取出 JSON i64 整型"]
667 pub fn pop_as_i64(&mut self) -> Option<i64> {
668 self.0.as_array_mut().unwrap().pop().and_then(|val| match val {
669 serde_json::Value::Number(s) => s.as_i64(),
670 _ => None,
671 })
672 }
673}
674impl PartSizes {
675 #[doc = "在列表的指定位置移出 JSON u64 整型"]
676 pub fn remove_as_u64(&mut self, index: usize) -> Option<u64> {
677 match self.0.as_array_mut().unwrap().remove(index) {
678 serde_json::Value::Number(s) => s.as_u64(),
679 _ => None,
680 }
681 }
682}
683impl PartSizes {
684 #[doc = "在列表尾部取出 JSON u64 整型"]
685 pub fn pop_as_u64(&mut self) -> Option<u64> {
686 self.0.as_array_mut().unwrap().pop().and_then(|val| match val {
687 serde_json::Value::Number(s) => s.as_u64(),
688 _ => None,
689 })
690 }
691}
692impl From<Vec<i8>> for PartSizes {
693 #[inline]
694 fn from(val: Vec<i8>) -> Self {
695 Self(serde_json::Value::from(val))
696 }
697}
698impl PartSizes {
699 #[doc = "在列表的指定位置插入 JSON i8 整型"]
700 pub fn insert_i8(&mut self, index: usize, val: i8) {
701 self.0.as_array_mut().unwrap().insert(index, val.into());
702 }
703}
704impl PartSizes {
705 #[doc = "在列表尾部追加 JSON i8 整型"]
706 pub fn push_i8(&mut self, val: i8) {
707 self.0.as_array_mut().unwrap().push(val.into());
708 }
709}
710impl From<Vec<i16>> for PartSizes {
711 #[inline]
712 fn from(val: Vec<i16>) -> Self {
713 Self(serde_json::Value::from(val))
714 }
715}
716impl PartSizes {
717 #[doc = "在列表的指定位置插入 JSON i16 整型"]
718 pub fn insert_i16(&mut self, index: usize, val: i16) {
719 self.0.as_array_mut().unwrap().insert(index, val.into());
720 }
721}
722impl PartSizes {
723 #[doc = "在列表尾部追加 JSON i16 整型"]
724 pub fn push_i16(&mut self, val: i16) {
725 self.0.as_array_mut().unwrap().push(val.into());
726 }
727}
728impl From<Vec<i32>> for PartSizes {
729 #[inline]
730 fn from(val: Vec<i32>) -> Self {
731 Self(serde_json::Value::from(val))
732 }
733}
734impl PartSizes {
735 #[doc = "在列表的指定位置插入 JSON i32 整型"]
736 pub fn insert_i32(&mut self, index: usize, val: i32) {
737 self.0.as_array_mut().unwrap().insert(index, val.into());
738 }
739}
740impl PartSizes {
741 #[doc = "在列表尾部追加 JSON i32 整型"]
742 pub fn push_i32(&mut self, val: i32) {
743 self.0.as_array_mut().unwrap().push(val.into());
744 }
745}
746impl From<Vec<i64>> for PartSizes {
747 #[inline]
748 fn from(val: Vec<i64>) -> Self {
749 Self(serde_json::Value::from(val))
750 }
751}
752impl PartSizes {
753 #[doc = "在列表的指定位置插入 JSON i64 整型"]
754 pub fn insert_i64(&mut self, index: usize, val: i64) {
755 self.0.as_array_mut().unwrap().insert(index, val.into());
756 }
757}
758impl PartSizes {
759 #[doc = "在列表尾部追加 JSON i64 整型"]
760 pub fn push_i64(&mut self, val: i64) {
761 self.0.as_array_mut().unwrap().push(val.into());
762 }
763}
764impl From<Vec<isize>> for PartSizes {
765 #[inline]
766 fn from(val: Vec<isize>) -> Self {
767 Self(serde_json::Value::from(val))
768 }
769}
770impl PartSizes {
771 #[doc = "在列表的指定位置插入 JSON isize 整型"]
772 pub fn insert_isize(&mut self, index: usize, val: isize) {
773 self.0.as_array_mut().unwrap().insert(index, val.into());
774 }
775}
776impl PartSizes {
777 #[doc = "在列表尾部追加 JSON isize 整型"]
778 pub fn push_isize(&mut self, val: isize) {
779 self.0.as_array_mut().unwrap().push(val.into());
780 }
781}
782impl From<Vec<u8>> for PartSizes {
783 #[inline]
784 fn from(val: Vec<u8>) -> Self {
785 Self(serde_json::Value::from(val))
786 }
787}
788impl PartSizes {
789 #[doc = "在列表的指定位置插入 JSON u8 整型"]
790 pub fn insert_u8(&mut self, index: usize, val: u8) {
791 self.0.as_array_mut().unwrap().insert(index, val.into());
792 }
793}
794impl PartSizes {
795 #[doc = "在列表尾部追加 JSON u8 整型"]
796 pub fn push_u8(&mut self, val: u8) {
797 self.0.as_array_mut().unwrap().push(val.into());
798 }
799}
800impl From<Vec<u16>> for PartSizes {
801 #[inline]
802 fn from(val: Vec<u16>) -> Self {
803 Self(serde_json::Value::from(val))
804 }
805}
806impl PartSizes {
807 #[doc = "在列表的指定位置插入 JSON u16 整型"]
808 pub fn insert_u16(&mut self, index: usize, val: u16) {
809 self.0.as_array_mut().unwrap().insert(index, val.into());
810 }
811}
812impl PartSizes {
813 #[doc = "在列表尾部追加 JSON u16 整型"]
814 pub fn push_u16(&mut self, val: u16) {
815 self.0.as_array_mut().unwrap().push(val.into());
816 }
817}
818impl From<Vec<u32>> for PartSizes {
819 #[inline]
820 fn from(val: Vec<u32>) -> Self {
821 Self(serde_json::Value::from(val))
822 }
823}
824impl PartSizes {
825 #[doc = "在列表的指定位置插入 JSON u32 整型"]
826 pub fn insert_u32(&mut self, index: usize, val: u32) {
827 self.0.as_array_mut().unwrap().insert(index, val.into());
828 }
829}
830impl PartSizes {
831 #[doc = "在列表尾部追加 JSON u32 整型"]
832 pub fn push_u32(&mut self, val: u32) {
833 self.0.as_array_mut().unwrap().push(val.into());
834 }
835}
836impl From<Vec<u64>> for PartSizes {
837 #[inline]
838 fn from(val: Vec<u64>) -> Self {
839 Self(serde_json::Value::from(val))
840 }
841}
842impl PartSizes {
843 #[doc = "在列表的指定位置插入 JSON u64 整型"]
844 pub fn insert_u64(&mut self, index: usize, val: u64) {
845 self.0.as_array_mut().unwrap().insert(index, val.into());
846 }
847}
848impl PartSizes {
849 #[doc = "在列表尾部追加 JSON u64 整型"]
850 pub fn push_u64(&mut self, val: u64) {
851 self.0.as_array_mut().unwrap().push(val.into());
852 }
853}
854impl From<Vec<usize>> for PartSizes {
855 #[inline]
856 fn from(val: Vec<usize>) -> Self {
857 Self(serde_json::Value::from(val))
858 }
859}
860impl PartSizes {
861 #[doc = "在列表的指定位置插入 JSON usize 整型"]
862 pub fn insert_usize(&mut self, index: usize, val: usize) {
863 self.0.as_array_mut().unwrap().insert(index, val.into());
864 }
865}
866impl PartSizes {
867 #[doc = "在列表尾部追加 JSON usize 整型"]
868 pub fn push_usize(&mut self, val: usize) {
869 self.0.as_array_mut().unwrap().push(val.into());
870 }
871}
872impl ListedObjectEntry {
873 #[doc = "获取 每个分片的大小,如没有指定 need_parts 参数则不返回"]
874 pub fn get_parts(&self) -> Option<PartSizes> {
875 self.0
876 .as_object()
877 .and_then(|obj| obj.get("parts"))
878 .cloned()
879 .map(PartSizes::new)
880 }
881}
882impl ListedObjectEntry {
883 #[doc = "设置 每个分片的大小,如没有指定 need_parts 参数则不返回"]
884 pub fn set_parts(&mut self, new: PartSizes) -> Option<PartSizes> {
885 self.0
886 .as_object_mut()
887 .and_then(|object| object.insert("parts".to_owned(), new.into()).map(PartSizes::new))
888 }
889}
890impl ListedObjects {
891 #[doc = "解析 JSON 得到 ListedObjectEntry 列表"]
892 pub fn to_listed_object_entry_vec(&self) -> Vec<ListedObjectEntry> {
893 self.0
894 .as_array()
895 .unwrap()
896 .iter()
897 .cloned()
898 .map(ListedObjectEntry::new)
899 .collect()
900 }
901}
902impl From<Vec<ListedObjectEntry>> for ListedObjects {
903 #[inline]
904 fn from(val: Vec<ListedObjectEntry>) -> Self {
905 Self(serde_json::Value::from(val))
906 }
907}
908impl ListedObjects {
909 #[doc = "获取数组的长度"]
910 pub fn len(&self) -> usize {
911 self.0.as_array().unwrap().len()
912 }
913 #[doc = "数组是否为空"]
914 pub fn is_empty(&self) -> bool {
915 self.0.as_array().unwrap().is_empty()
916 }
917}
918impl ListedObjects {
919 #[doc = "在列表的指定位置插入 JSON ListedObjectEntry"]
920 pub fn insert_listed_object_entry(&mut self, index: usize, val: ListedObjectEntry) {
921 self.0.as_array_mut().unwrap().insert(index, val.into());
922 }
923}
924impl ListedObjects {
925 #[doc = "在列表的指定位置移出 JSON ListedObjectEntry"]
926 pub fn remove_as_listed_object_entry(&mut self, index: usize) -> ListedObjectEntry {
927 ListedObjectEntry::new(self.0.as_array_mut().unwrap().remove(index))
928 }
929}
930impl ListedObjects {
931 #[doc = "在列表尾部追加 JSON ListedObjectEntry"]
932 pub fn push_listed_object_entry(&mut self, val: ListedObjectEntry) {
933 self.0.as_array_mut().unwrap().push(val.into());
934 }
935}
936impl ListedObjects {
937 #[doc = "在列表尾部取出 JSON ListedObjectEntry"]
938 pub fn pop_listed_object_entry(&mut self) -> Option<ListedObjectEntry> {
939 self.0.as_array_mut().unwrap().pop().map(ListedObjectEntry::new)
940 }
941}
942impl ResponseBody {
943 #[doc = "获取 条目的数组,不能用来判断是否还有剩余条目"]
944 pub fn get_items(&self) -> ListedObjects {
945 ListedObjects::new(self.0.as_object().unwrap().get("items").cloned().unwrap())
946 }
947}
948impl ResponseBody {
949 #[doc = "设置 条目的数组,不能用来判断是否还有剩余条目"]
950 pub fn set_items(&mut self, new: ListedObjects) -> Option<ListedObjects> {
951 self.0
952 .as_object_mut()
953 .unwrap()
954 .insert("items".to_owned(), new.into())
955 .map(ListedObjects::new)
956 }
957}
958#[doc = "API 调用客户端"]
959#[derive(Debug, Clone)]
960pub struct Client<'client>(&'client qiniu_http_client::HttpClient);
961impl<'client> Client<'client> {
962 pub(super) fn new(http_client: &'client qiniu_http_client::HttpClient) -> Self {
963 Self(http_client)
964 }
965}
966impl<'client> Client<'client> {
967 #[inline]
968 #[doc = "创建一个新的阻塞请求,该方法的异步版本为 [`Self::new_async_request`]"]
969 pub fn new_request<E: qiniu_http_client::EndpointsProvider + 'client>(
970 &self,
971 endpoints_provider: E,
972 credential: impl qiniu_http_client::credential::CredentialProvider + Clone + 'client,
973 ) -> SyncRequestBuilder<'client, E> {
974 RequestBuilder({
975 let mut builder = self.0.get(&[qiniu_http_client::ServiceName::Rsf], endpoints_provider);
976 builder.authorization(qiniu_http_client::Authorization::v2(credential));
977 builder.idempotent(qiniu_http_client::Idempotent::Default);
978 builder.path("list");
979 builder.accept_json();
980 builder
981 })
982 }
983 #[inline]
984 #[cfg(feature = "async")]
985 #[doc = "创建一个新的异步请求"]
986 pub fn new_async_request<E: qiniu_http_client::EndpointsProvider + 'client>(
987 &self,
988 endpoints_provider: E,
989 credential: impl qiniu_http_client::credential::CredentialProvider + Clone + 'client,
990 ) -> AsyncRequestBuilder<'client, E> {
991 RequestBuilder({
992 let mut builder = self
993 .0
994 .async_get(&[qiniu_http_client::ServiceName::Rsf], endpoints_provider);
995 builder.authorization(qiniu_http_client::Authorization::v2(credential));
996 builder.idempotent(qiniu_http_client::Idempotent::Default);
997 builder.path("list");
998 builder.accept_json();
999 builder
1000 })
1001 }
1002}
1003#[derive(Debug)]
1004#[doc = "API 请求构造器"]
1005pub struct RequestBuilder<'req, B, E>(qiniu_http_client::RequestBuilder<'req, B, E>);
1006#[doc = "API 阻塞请求构造器"]
1007pub type SyncRequestBuilder<'req, E> = RequestBuilder<'req, qiniu_http_client::SyncRequestBody<'req>, E>;
1008#[cfg(feature = "async")]
1009#[cfg_attr(feature = "docs", doc(cfg(feature = "async")))]
1010#[doc = "API 异步请求构造器"]
1011pub type AsyncRequestBuilder<'req, E> = RequestBuilder<'req, qiniu_http_client::AsyncRequestBody<'req>, E>;
1012impl<'req, B, E> RequestBuilder<'req, B, E> {
1013 #[inline]
1014 #[doc = "设置是否使用 HTTPS"]
1015 pub fn use_https(&mut self, use_https: bool) -> &mut Self {
1016 self.0.use_https(use_https);
1017 self
1018 }
1019 #[inline]
1020 #[doc = "设置 HTTP 协议版本"]
1021 pub fn version(&mut self, version: qiniu_http_client::http::Version) -> &mut Self {
1022 self.0.version(version);
1023 self
1024 }
1025 #[inline]
1026 #[doc = "设置 HTTP 请求头"]
1027 pub fn headers(
1028 &mut self,
1029 headers: impl Into<std::borrow::Cow<'req, qiniu_http_client::http::HeaderMap>>,
1030 ) -> &mut Self {
1031 self.0.headers(headers);
1032 self
1033 }
1034 #[inline]
1035 #[doc = "添加 HTTP 请求头"]
1036 pub fn set_header(
1037 &mut self,
1038 header_name: impl qiniu_http_client::http::header::IntoHeaderName,
1039 header_value: impl Into<qiniu_http_client::http::HeaderValue>,
1040 ) -> &mut Self {
1041 self.0.set_header(header_name, header_value);
1042 self
1043 }
1044 #[inline]
1045 #[doc = "设置查询参数"]
1046 pub fn query(&mut self, query: impl Into<std::borrow::Cow<'req, str>>) -> &mut Self {
1047 self.0.query(query);
1048 self
1049 }
1050 #[inline]
1051 #[doc = "设置查询参数"]
1052 pub fn query_pairs(&mut self, query_pairs: impl Into<Vec<qiniu_http_client::QueryPair<'req>>>) -> &mut Self {
1053 self.0.query_pairs(query_pairs);
1054 self
1055 }
1056 #[inline]
1057 #[doc = "追加查询参数"]
1058 pub fn append_query_pair(
1059 &mut self,
1060 query_pair_key: impl Into<qiniu_http_client::QueryPairKey<'req>>,
1061 query_pair_value: impl Into<qiniu_http_client::QueryPairValue<'req>>,
1062 ) -> &mut Self {
1063 self.0.append_query_pair(query_pair_key, query_pair_value);
1064 self
1065 }
1066 #[inline]
1067 #[doc = "设置扩展信息"]
1068 pub fn extensions(&mut self, extensions: qiniu_http_client::http::Extensions) -> &mut Self {
1069 self.0.extensions(extensions);
1070 self
1071 }
1072 #[doc = "添加扩展信息"]
1073 #[inline]
1074 pub fn add_extension<T: Send + Sync + 'static>(&mut self, val: T) -> &mut Self {
1075 self.0.add_extension(val);
1076 self
1077 }
1078 #[inline]
1079 #[doc = "上传进度回调函数"]
1080 pub fn on_uploading_progress(
1081 &mut self,
1082 callback: impl Fn(
1083 &dyn qiniu_http_client::SimplifiedCallbackContext,
1084 qiniu_http_client::http::TransferProgressInfo,
1085 ) -> anyhow::Result<()>
1086 + Send
1087 + Sync
1088 + 'req,
1089 ) -> &mut Self {
1090 self.0.on_uploading_progress(callback);
1091 self
1092 }
1093 #[inline]
1094 #[doc = "设置响应状态码回调函数"]
1095 pub fn on_receive_response_status(
1096 &mut self,
1097 callback: impl Fn(
1098 &dyn qiniu_http_client::SimplifiedCallbackContext,
1099 qiniu_http_client::http::StatusCode,
1100 ) -> anyhow::Result<()>
1101 + Send
1102 + Sync
1103 + 'req,
1104 ) -> &mut Self {
1105 self.0.on_receive_response_status(callback);
1106 self
1107 }
1108 #[inline]
1109 #[doc = "设置响应 HTTP 头回调函数"]
1110 pub fn on_receive_response_header(
1111 &mut self,
1112 callback: impl Fn(
1113 &dyn qiniu_http_client::SimplifiedCallbackContext,
1114 &qiniu_http_client::http::HeaderName,
1115 &qiniu_http_client::http::HeaderValue,
1116 ) -> anyhow::Result<()>
1117 + Send
1118 + Sync
1119 + 'req,
1120 ) -> &mut Self {
1121 self.0.on_receive_response_header(callback);
1122 self
1123 }
1124 #[inline]
1125 #[doc = "设置域名解析前回调函数"]
1126 pub fn on_to_resolve_domain(
1127 &mut self,
1128 callback: impl Fn(&mut dyn qiniu_http_client::CallbackContext, &str) -> anyhow::Result<()> + Send + Sync + 'req,
1129 ) -> &mut Self {
1130 self.0.on_to_resolve_domain(callback);
1131 self
1132 }
1133 #[inline]
1134 #[doc = "设置域名解析成功回调函数"]
1135 pub fn on_domain_resolved(
1136 &mut self,
1137 callback: impl Fn(
1138 &mut dyn qiniu_http_client::CallbackContext,
1139 &str,
1140 &qiniu_http_client::ResolveAnswers,
1141 ) -> anyhow::Result<()>
1142 + Send
1143 + Sync
1144 + 'req,
1145 ) -> &mut Self {
1146 self.0.on_domain_resolved(callback);
1147 self
1148 }
1149 #[inline]
1150 #[doc = "设置 IP 地址选择前回调函数"]
1151 pub fn on_to_choose_ips(
1152 &mut self,
1153 callback: impl Fn(&mut dyn qiniu_http_client::CallbackContext, &[qiniu_http_client::IpAddrWithPort]) -> anyhow::Result<()>
1154 + Send
1155 + Sync
1156 + 'req,
1157 ) -> &mut Self {
1158 self.0.on_to_choose_ips(callback);
1159 self
1160 }
1161 #[inline]
1162 #[doc = "设置 IP 地址选择成功回调函数"]
1163 pub fn on_ips_chosen(
1164 &mut self,
1165 callback: impl Fn(
1166 &mut dyn qiniu_http_client::CallbackContext,
1167 &[qiniu_http_client::IpAddrWithPort],
1168 &[qiniu_http_client::IpAddrWithPort],
1169 ) -> anyhow::Result<()>
1170 + Send
1171 + Sync
1172 + 'req,
1173 ) -> &mut Self {
1174 self.0.on_ips_chosen(callback);
1175 self
1176 }
1177 #[inline]
1178 #[doc = "设置 HTTP 请求签名前回调函数"]
1179 pub fn on_before_request_signed(
1180 &mut self,
1181 callback: impl Fn(&mut dyn qiniu_http_client::ExtendedCallbackContext) -> anyhow::Result<()> + Send + Sync + 'req,
1182 ) -> &mut Self {
1183 self.0.on_before_request_signed(callback);
1184 self
1185 }
1186 #[inline]
1187 #[doc = "设置 HTTP 请求前回调函数"]
1188 pub fn on_after_request_signed(
1189 &mut self,
1190 callback: impl Fn(&mut dyn qiniu_http_client::ExtendedCallbackContext) -> anyhow::Result<()> + Send + Sync + 'req,
1191 ) -> &mut Self {
1192 self.0.on_after_request_signed(callback);
1193 self
1194 }
1195 #[inline]
1196 #[doc = "设置响应成功回调函数"]
1197 pub fn on_response(
1198 &mut self,
1199 callback: impl Fn(
1200 &mut dyn qiniu_http_client::ExtendedCallbackContext,
1201 &qiniu_http_client::http::ResponseParts,
1202 ) -> anyhow::Result<()>
1203 + Send
1204 + Sync
1205 + 'req,
1206 ) -> &mut Self {
1207 self.0.on_response(callback);
1208 self
1209 }
1210 #[inline]
1211 #[doc = "设置响应错误回调函数"]
1212 pub fn on_error(
1213 &mut self,
1214 callback: impl Fn(
1215 &mut dyn qiniu_http_client::ExtendedCallbackContext,
1216 &mut qiniu_http_client::ResponseError,
1217 ) -> anyhow::Result<()>
1218 + Send
1219 + Sync
1220 + 'req,
1221 ) -> &mut Self {
1222 self.0.on_error(callback);
1223 self
1224 }
1225 #[inline]
1226 #[doc = "设置退避前回调函数"]
1227 pub fn on_before_backoff(
1228 &mut self,
1229 callback: impl Fn(&mut dyn qiniu_http_client::ExtendedCallbackContext, std::time::Duration) -> anyhow::Result<()>
1230 + Send
1231 + Sync
1232 + 'req,
1233 ) -> &mut Self {
1234 self.0.on_before_backoff(callback);
1235 self
1236 }
1237 #[inline]
1238 #[doc = "设置退避后回调函数"]
1239 pub fn on_after_backoff(
1240 &mut self,
1241 callback: impl Fn(&mut dyn qiniu_http_client::ExtendedCallbackContext, std::time::Duration) -> anyhow::Result<()>
1242 + Send
1243 + Sync
1244 + 'req,
1245 ) -> &mut Self {
1246 self.0.on_after_backoff(callback);
1247 self
1248 }
1249 #[inline]
1250 #[doc = "获取 HTTP 请求构建器部分参数"]
1251 pub fn parts(&self) -> &qiniu_http_client::RequestBuilderParts<'req> {
1252 self.0.parts()
1253 }
1254 #[inline]
1255 #[doc = "获取 HTTP 请求构建器部分参数的可变引用"]
1256 pub fn parts_mut(&mut self) -> &mut qiniu_http_client::RequestBuilderParts<'req> {
1257 self.0.parts_mut()
1258 }
1259}
1260impl<'req, E: qiniu_http_client::EndpointsProvider + Clone + 'req> SyncRequestBuilder<'req, E> {
1261 #[doc = "阻塞发起 HTTP 请求"]
1262 pub fn call(&mut self) -> qiniu_http_client::ApiResult<qiniu_http_client::Response<ResponseBody>> {
1263 let request = &mut self.0;
1264 let response = request.call()?;
1265 let parsed = response.parse_json()?;
1266 Ok(parsed)
1267 }
1268}
1269#[cfg(feature = "async")]
1270impl<'req, E: qiniu_http_client::EndpointsProvider + Clone + 'req> AsyncRequestBuilder<'req, E> {
1271 #[doc = "异步发起 HTTP 请求"]
1272 pub async fn call(&mut self) -> qiniu_http_client::ApiResult<qiniu_http_client::Response<ResponseBody>> {
1273 let request = &mut self.0;
1274 let response = request.call().await?;
1275 let parsed = response.parse_json().await?;
1276 Ok(parsed)
1277 }
1278}