aliyun_oss_rs/object/
multipart_copyto_part.rs1use crate::{
2 common::format_gmt,
3 error::{Error, normal_error},
4 request::{Oss, OssRequest},
5};
6use http::Method;
7use time::OffsetDateTime;
8
9pub struct CopyToPart {
13 req: OssRequest,
14}
15impl CopyToPart {
16 pub(super) fn new(
17 oss: Oss,
18 part_number: u32,
19 upload_id: impl ToString,
20 copy_source: impl ToString,
21 ) -> Self {
22 let mut req = OssRequest::new(oss, Method::PUT);
23 req.insert_query("partNumber", part_number);
24 req.insert_query("uploadId", upload_id);
25 req.insert_header("x-oss-copy-source", copy_source);
26 CopyToPart { req }
27 }
28 pub fn set_source_range(mut self, start: usize, end: Option<usize>) -> Self {
32 self.req.insert_header(
33 "x-oss-copy-source-range",
34 format!(
35 "bytes={}-{}",
36 start,
37 end.map(|v| v.to_string()).unwrap_or_else(|| String::new())
38 ),
39 );
40 self
41 }
42 pub fn set_if_modified_since(mut self, if_modified_since: OffsetDateTime) -> Self {
45 self.req.insert_header(
46 "x-oss-copy-source-if-modified-since",
47 format_gmt(if_modified_since),
48 );
49 self
50 }
51 pub fn set_if_unmodified_since(mut self, if_unmodified_since: OffsetDateTime) -> Self {
54 self.req.insert_header(
55 "x-oss-copy-source-if-unmodified-since",
56 format_gmt(if_unmodified_since),
57 );
58 self
59 }
60 pub fn set_if_match(mut self, if_match: impl ToString) -> Self {
64 self.req
65 .insert_header("x-oss-copy-source-if-match", if_match);
66 self
67 }
68 pub fn set_if_none_match(mut self, if_none_match: impl ToString) -> Self {
72 self.req
73 .insert_header("x-oss-copy-source-if-none-match", if_none_match);
74 self
75 }
76 pub async fn send(self) -> Result<String, Error> {
80 let response = self.req.send_to_oss()?.await?;
82 let status_code = response.status();
84 match status_code {
85 code if code.is_success() => {
86 let e_tag = response
87 .headers()
88 .get("ETag")
89 .map(|v| String::from_utf8(v.as_bytes().to_vec()).ok())
90 .flatten()
91 .unwrap_or_else(|| String::new());
92 Ok(e_tag)
93 }
94 _ => Err(normal_error(response).await),
95 }
96 }
97}