Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading