Skip to content

Commit

Permalink
refactor(services/oss): Refactor oss_put_object signatures by using…
Browse files Browse the repository at this point in the history
… OpWrite (#3080)

* refactor(services/oss): Refactor oss_put_object signatures by using OpWrite

* Refactor: cargo fmt checks
  • Loading branch information
sysu-yunz authored Sep 15, 2023
1 parent 87b3867 commit d797f05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
15 changes: 5 additions & 10 deletions core/src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl Accessor for OssBackend {
async fn create_dir(&self, path: &str, _: OpCreateDir) -> Result<RpCreateDir> {
let resp = self
.core
.oss_put_object(path, None, None, None, None, AsyncBody::Empty)
.oss_put_object(path, None, &OpWrite::default(), AsyncBody::Empty)
.await?;
let status = resp.status();

Expand Down Expand Up @@ -556,15 +556,10 @@ impl Accessor for OssBackend {
v.if_none_match(),
v.override_content_disposition(),
)?,
PresignOperation::Write(v) => self.core.oss_put_object_request(
path,
None,
v.content_type(),
v.content_disposition(),
v.cache_control(),
AsyncBody::Empty,
true,
)?,
PresignOperation::Write(v) => {
self.core
.oss_put_object_request(path, None, v, AsyncBody::Empty, true)?
}
};

self.core.sign_query(&mut req, args.expire()).await?;
Expand Down
24 changes: 6 additions & 18 deletions core/src/services/oss/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ impl OssCore {
&self,
path: &str,
size: Option<u64>,
content_type: Option<&str>,
content_disposition: Option<&str>,
cache_control: Option<&str>,
args: &OpWrite,
body: AsyncBody,
is_presign: bool,
) -> Result<Request<AsyncBody>> {
Expand All @@ -166,15 +164,15 @@ impl OssCore {

req = req.header(CONTENT_LENGTH, size.unwrap_or_default());

if let Some(mime) = content_type {
if let Some(mime) = args.content_type() {
req = req.header(CONTENT_TYPE, mime);
}

if let Some(pos) = content_disposition {
if let Some(pos) = args.content_disposition() {
req = req.header(CONTENT_DISPOSITION, pos);
}

if let Some(cache_control) = cache_control {
if let Some(cache_control) = args.cache_control() {
req = req.header(CACHE_CONTROL, cache_control)
}

Expand Down Expand Up @@ -376,20 +374,10 @@ impl OssCore {
&self,
path: &str,
size: Option<u64>,
content_type: Option<&str>,
content_disposition: Option<&str>,
cache_control: Option<&str>,
args: &OpWrite,
body: AsyncBody,
) -> Result<Response<IncomingAsyncBody>> {
let mut req = self.oss_put_object_request(
path,
size,
content_type,
content_disposition,
cache_control,
body,
false,
)?;
let mut req = self.oss_put_object_request(path, size, args, body, false)?;

self.sign(&mut req).await?;
self.send(req).await
Expand Down
12 changes: 3 additions & 9 deletions core/src/services/oss/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ impl OssWriter {
#[async_trait]
impl oio::MultipartUploadWrite for OssWriter {
async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
let mut req = self.core.oss_put_object_request(
&self.path,
Some(size),
self.op.content_type(),
self.op.content_disposition(),
self.op.cache_control(),
body,
false,
)?;
let mut req =
self.core
.oss_put_object_request(&self.path, Some(size), &self.op, body, false)?;

self.core.sign(&mut req).await?;

Expand Down

0 comments on commit d797f05

Please sign in to comment.