Skip to content

refactor(services/aliyun_drive): Move raw request to core #6089

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

Merged
merged 11 commits into from
Apr 27, 2025
22 changes: 4 additions & 18 deletions core/src/services/aliyun_drive/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub struct AliyunDriveBackend {
}

impl Access for AliyunDriveBackend {
type Reader = HttpBody;
type Reader = Buffer;
type Writer = AliyunDriveWriter;
type Lister = oio::PageLister<AliyunDriveLister>;
type Deleter = oio::OneShotDeleter<AliyunDriveDeleter>;
Expand Down Expand Up @@ -370,23 +370,9 @@ impl Access for AliyunDriveBackend {
serde_json::from_reader(res.reader()).map_err(new_json_serialize_error)?;

let download_url = self.core.get_download_url(&file.file_id).await?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this as @erickguan suggested #6089 (comment)

let req = Request::get(&download_url)
.header(header::RANGE, args.range().to_header())
.body(Buffer::new())
.map_err(new_request_build_error)?;

let resp = self.core.info.http_client().fetch(req).await?;
let status = resp.status();
match status {
StatusCode::OK | StatusCode::PARTIAL_CONTENT => {
Ok((RpRead::default(), resp.into_body()))
}
_ => {
let (part, mut body) = resp.into_parts();
let buf = body.to_buffer().await?;
Err(parse_error(Response::from_parts(part, buf)))
}
}
let buf = self.core.download(&download_url, args.range()).await?;

Ok((RpRead::default(), buf))
}

async fn delete(&self) -> Result<(RpDelete, Self::Deleter)> {
Expand Down
8 changes: 8 additions & 0 deletions core/src/services/aliyun_drive/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,14 @@ impl AliyunDriveCore {
self.send(req, token.as_deref()).await
}

pub async fn download(&self, download_url: &str, range: BytesRange) -> Result<Buffer> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to how upload method is done

let req = Request::get(download_url)
.header(header::RANGE, range.to_header())
.body(Buffer::new())
.map_err(new_request_build_error)?;
self.send(req, None).await
}

pub async fn upload(&self, upload_url: &str, body: Buffer) -> Result<Buffer> {
let req = Request::put(upload_url)
// Inject operation to the request.
Expand Down
Loading