This is an automated email from the ASF dual-hosted git repository.
suyanhanx pushed a commit to branch gdrive
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/gdrive by this push:
new 203ecf9d9 remove unused part
203ecf9d9 is described below
commit 203ecf9d98cd707cdf5780090cd6dffebb81d47e
Author: suyanhanx <[email protected]>
AuthorDate: Mon Aug 21 18:12:49 2023 +0800
remove unused part
Signed-off-by: suyanhanx <[email protected]>
---
core/src/services/gdrive/core.rs | 135 ---------------------------------------
1 file changed, 135 deletions(-)
diff --git a/core/src/services/gdrive/core.rs b/core/src/services/gdrive/core.rs
index 642467b9f..cd816c7b7 100644
--- a/core/src/services/gdrive/core.rs
+++ b/core/src/services/gdrive/core.rs
@@ -402,141 +402,6 @@ impl GdriveCore {
self.client.send(req).await
}
- /// Start an upload session.
- ///
- /// ## Notes
- ///
- /// - If we know the size of the file, we should provide it here.
- pub async fn gdrive_upload_initial_request(
- &self,
- path: &str,
- size: Option<u64>,
- ) -> Result<Response<IncomingAsyncBody>> {
- let parent = self.ensure_parent_path(path).await?;
-
- let url =
"https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable";
-
- let file_name = path.split('/').filter(|&x|
!x.is_empty()).last().unwrap();
-
- let bs = serde_json::to_vec(&json!({
- "name": file_name,
- "parents": [parent],
- }))
- .map_err(|e| {
- Error::new(
- ErrorKind::Unexpected,
- &format!("failed to serialize json(upload initial request):
{}", e),
- )
- })?;
-
- let mut req = Request::post(url)
- .header(header::CONTENT_TYPE, "application/json; charset=UTF-8")
- .header(header::CONTENT_LENGTH, bs.len());
-
- if let Some(size) = size {
- req = req.header("X-Upload-Content-Length", size);
- }
-
- let mut req = req
- .body(AsyncBody::Bytes(bytes::Bytes::from(bs)))
- .map_err(new_request_build_error)?;
-
- req = self.sign(req);
-
- self.client.send(req).await
- }
-
- /// Upload a part.
- /// It's important to know the size of the part and the position of the
part in the whole file.
- ///
- /// ## Notes
- ///
- /// - If don't know the whole size of the file,
- /// it will be replaced by `*` in `content-range` header automatically.
- /// - Please keep the whole size of the file consistent during the upload.
- pub async fn gdrive_upload_part_request(
- &self,
- target: &str,
- size: u64,
- position: u64,
- whole_size: Option<u64>,
- body: AsyncBody,
- ) -> Result<Response<IncomingAsyncBody>> {
- let mut req = Request::put(target)
- .header("Content-Length", size)
- .header(
- "Content-Range",
- format!(
- "bytes {}-{}/{}",
- position,
- position + size - 1,
- match whole_size {
- Some(ws) => ws.to_string(),
- _ => "*".to_string(),
- }
- ),
- )
- .body(body)
- .map_err(new_request_build_error)?;
-
- req = self.sign(req);
-
- self.client.send(req).await
- }
-
- /// Finish the upload.
- ///
- /// For Google Drive, to finish an upload session, we should send a
request to the upload session
- /// has received the whole file.
- ///
- /// So if we don't know the size of the file, when we have uploaded the
whole file, we should
- /// tell the server that the upload session has received the whole file.
- ///
- /// It could be done by sending a request to the upload session with the
size of the file we have
- /// uploaded.
- /// So the server will know that the upload session has received the whole
file.
- /// We can count the size of all parts we have uploaded by ourselves.
- ///
- /// ## Notes
- ///
- /// **It's no need to call this if we know the size of the file.**
- ///
- /// When we know the file size,
- /// we can indicate the total size in the Content-range header during the
upload,
- /// and this allows the server to know that it has received all parts,
- /// like `Content-range: bytes 0-1023/1024`.
- pub async fn gdrive_finish_upload_request(
- &self,
- target: &str,
- size: u64,
- ) -> Result<Response<IncomingAsyncBody>> {
- let mut req = Request::put(target)
- .header("Content-Length", 0)
- .header("Content-Range", format!("bytes */{}", size))
- .body(AsyncBody::Empty)
- .map_err(new_request_build_error)?;
-
- req = self.sign(req);
-
- self.client.send(req).await
- }
-
- /// Cancel the upload.
- /// Similar to the delete operation, but the target is an upload session.
- pub async fn gdrive_cancel_upload_request(
- &self,
- target: &str,
- ) -> Result<Response<IncomingAsyncBody>> {
- let mut req = Request::delete(target)
- .header("Content-Length", 0)
- .body(AsyncBody::Empty)
- .map_err(new_request_build_error)?;
-
- req = self.sign(req);
-
- self.client.send(req).await
- }
-
fn sign<T>(&self, mut req: Request<T>) -> Request<T> {
let auth_header_content = format!("Bearer {}", self.access_token);
req.headers_mut().insert(