This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 1ace92e1 ci: Setup vercel artifacts integration tests (#2197)
1ace92e1 is described below
commit 1ace92e1fd78665af7ae0de59f10769f696a9586
Author: Xuanwo <[email protected]>
AuthorDate: Wed May 3 02:20:12 2023 +0800
ci: Setup vercel artifacts integration tests (#2197)
Signed-off-by: Xuanwo <[email protected]>
---
.env.example | 3 +++
core/src/services/vercel_artifacts/backend.rs | 19 +++++++++++++++----
core/src/services/vercel_artifacts/writer.rs | 2 +-
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/.env.example b/.env.example
index 2b83073a..4d5e605c 100644
--- a/.env.example
+++ b/.env.example
@@ -87,3 +87,6 @@ OPENDAL_WEBHDFS_TEST=false
OPENDAL_WEBHDFS_ROOT=/tmp/opendal/
OPENDAL_WEBHDFS_ENDPOINT=http://127.0.0.1:9870
OPENDAL_WEBHDFS_DELEGATION=<delegation>
+# vercel artifacts
+OPENDAL_VERCEL_ARTIFACTS_TEST=false
+OPENDAL_VERCEL_ARTIFACTS_ACCESS_TOKEN=<token>
diff --git a/core/src/services/vercel_artifacts/backend.rs
b/core/src/services/vercel_artifacts/backend.rs
index c77c810d..b4f63ebf 100644
--- a/core/src/services/vercel_artifacts/backend.rs
+++ b/core/src/services/vercel_artifacts/backend.rs
@@ -59,6 +59,7 @@ impl Accessor for VercelArtifactsBackend {
ma.set_scheme(crate::Scheme::VercelArtifacts)
.set_capability(Capability {
read: true,
+ read_can_next: true,
write: true,
..Default::default()
});
@@ -66,8 +67,8 @@ impl Accessor for VercelArtifactsBackend {
ma
}
- async fn read(&self, path: &str, _args: OpRead) -> Result<(RpRead,
Self::Reader)> {
- let resp = self.vercel_artifacts_get(path).await?;
+ async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead,
Self::Reader)> {
+ let resp = self.vercel_artifacts_get(path, args).await?;
let status = resp.status();
@@ -97,11 +98,19 @@ impl Accessor for VercelArtifactsBackend {
}
impl VercelArtifactsBackend {
- async fn vercel_artifacts_get(&self, hash: &str) ->
Result<Response<IncomingAsyncBody>> {
- let url: String = format!("https://api.vercel.com/v8/artifacts/{}",
hash);
+ async fn vercel_artifacts_get(
+ &self,
+ path: &str,
+ args: OpRead,
+ ) -> Result<Response<IncomingAsyncBody>> {
+ let url: String = format!("https://api.vercel.com/v8/artifacts/{}",
path);
let mut req = Request::get(&url);
+ if !args.range().is_full() {
+ req = req.header(header::RANGE, args.range().to_header());
+ }
+
let auth_header_content = format!("Bearer {}", self.access_token);
req = req.header(header::AUTHORIZATION, auth_header_content);
@@ -123,6 +132,8 @@ impl VercelArtifactsBackend {
let mut req = Request::put(&url);
let auth_header_content = format!("Bearer {}", self.access_token);
+ // Borrowed from
[vercel/remote-cache](https://github.com/vercel/remote-cache/blob/46cbc71346c84ec6c3022ec660ade52a25a20013/packages/remote/src/artifact-request.ts#LL41C34-L41C58)
+ req = req.header(header::CONTENT_TYPE, "application/octet-stream");
req = req.header(header::AUTHORIZATION, auth_header_content);
req = req.header(header::CONTENT_LENGTH, size);
diff --git a/core/src/services/vercel_artifacts/writer.rs
b/core/src/services/vercel_artifacts/writer.rs
index a44ad71a..89ad9a60 100644
--- a/core/src/services/vercel_artifacts/writer.rs
+++ b/core/src/services/vercel_artifacts/writer.rs
@@ -53,7 +53,7 @@ impl oio::Write for VercelArtifactsWriter {
let status = resp.status();
match status {
- StatusCode::OK => {
+ StatusCode::OK | StatusCode::ACCEPTED => {
resp.into_body().consume().await?;
Ok(())
}