opendal/services/vercel_artifacts/
backend.rs1use std::fmt::Debug;
19use std::sync::Arc;
20
21use http::Response;
22use http::StatusCode;
23
24use super::core::VercelArtifactsCore;
25use super::error::parse_error;
26use super::writer::VercelArtifactsWriter;
27use crate::raw::*;
28use crate::*;
29
30#[doc = include_str!("docs.md")]
31#[derive(Clone)]
32pub struct VercelArtifactsBackend {
33 pub core: Arc<VercelArtifactsCore>,
34}
35
36impl Debug for VercelArtifactsBackend {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 f.debug_struct("VercelArtifactsBackend")
39 .field("core", &self.core)
40 .finish()
41 }
42}
43
44impl Access for VercelArtifactsBackend {
45 type Reader = HttpBody;
46 type Writer = oio::OneShotWriter<VercelArtifactsWriter>;
47 type Lister = ();
48 type Deleter = ();
49 type BlockingReader = ();
50 type BlockingWriter = ();
51 type BlockingLister = ();
52 type BlockingDeleter = ();
53
54 fn info(&self) -> Arc<AccessorInfo> {
55 self.core.info.clone()
56 }
57
58 async fn stat(&self, path: &str, _args: OpStat) -> Result<RpStat> {
59 let response = self.core.vercel_artifacts_stat(path).await?;
60
61 let status = response.status();
62
63 match status {
64 StatusCode::OK => {
65 let meta = parse_into_metadata(path, response.headers())?;
66 Ok(RpStat::new(meta))
67 }
68
69 _ => Err(parse_error(response)),
70 }
71 }
72
73 async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
74 let response = self
75 .core
76 .vercel_artifacts_get(path, args.range(), &args)
77 .await?;
78
79 let status = response.status();
80
81 match status {
82 StatusCode::OK | StatusCode::PARTIAL_CONTENT => {
83 Ok((RpRead::new(), response.into_body()))
84 }
85 _ => {
86 let (part, mut body) = response.into_parts();
87 let buf = body.to_buffer().await?;
88 Err(parse_error(Response::from_parts(part, buf)))
89 }
90 }
91 }
92
93 async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {
94 Ok((
95 RpWrite::default(),
96 oio::OneShotWriter::new(VercelArtifactsWriter::new(
97 self.core.clone(),
98 args,
99 path.to_string(),
100 )),
101 ))
102 }
103}