style: format code
formats code according to `cargo fmt` standards
This commit is contained in:
parent
f3f3478ae0
commit
be326f52ca
2 changed files with 67 additions and 54 deletions
|
@ -108,7 +108,11 @@ impl<'a> Storage {
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn init<T: AsRef<str>>(&mut self, endpoint: Endpoint, storage_zone: T) -> Result<(), Error> {
|
pub fn init<T: AsRef<str>>(
|
||||||
|
&mut self,
|
||||||
|
endpoint: Endpoint,
|
||||||
|
storage_zone: T,
|
||||||
|
) -> Result<(), Error> {
|
||||||
let endpoint: Url = endpoint.try_into()?;
|
let endpoint: Url = endpoint.try_into()?;
|
||||||
let storage_zone = String::from("/") + storage_zone.as_ref() + "/";
|
let storage_zone = String::from("/") + storage_zone.as_ref() + "/";
|
||||||
|
|
||||||
|
@ -137,16 +141,18 @@ impl<'a> Storage {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn upload<T: AsRef<str>>(&self, path: T, file: Bytes) -> Result<(), Error> {
|
pub async fn upload<T: AsRef<str>>(&self, path: T, file: Bytes) -> Result<(), Error> {
|
||||||
let response = self.reqwest.put(self.url.join(path.as_ref())?)
|
let response = self
|
||||||
|
.reqwest
|
||||||
|
.put(self.url.join(path.as_ref())?)
|
||||||
.header("Content-Type", "application/octet-stream")
|
.header("Content-Type", "application/octet-stream")
|
||||||
.body(file)
|
.body(file)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if response.status().as_u16() == 401 {
|
if response.status().as_u16() == 401 {
|
||||||
return Err(Error::Authentication(response.text().await?))
|
return Err(Error::Authentication(response.text().await?));
|
||||||
} else if response.status().as_u16() == 400 {
|
} else if response.status().as_u16() == 400 {
|
||||||
return Err(Error::BadRequest(response.text().await?))
|
return Err(Error::BadRequest(response.text().await?));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -175,15 +181,17 @@ impl<'a> Storage {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn download<T: AsRef<str>>(&self, path: T) -> Result<Bytes, Error> {
|
pub async fn download<T: AsRef<str>>(&self, path: T) -> Result<Bytes, Error> {
|
||||||
let response = self.reqwest.get(self.url.join(path.as_ref())?)
|
let response = self
|
||||||
|
.reqwest
|
||||||
|
.get(self.url.join(path.as_ref())?)
|
||||||
.header("accept", "*/*")
|
.header("accept", "*/*")
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if response.status().as_u16() == 401 {
|
if response.status().as_u16() == 401 {
|
||||||
return Err(Error::Authentication(response.text().await?))
|
return Err(Error::Authentication(response.text().await?));
|
||||||
} else if response.status().as_u16() == 404 {
|
} else if response.status().as_u16() == 404 {
|
||||||
return Err(Error::NotFound(response.text().await?))
|
return Err(Error::NotFound(response.text().await?));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(response.bytes().await?)
|
Ok(response.bytes().await?)
|
||||||
|
@ -207,14 +215,16 @@ impl<'a> Storage {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn delete<T: AsRef<str>>(&self, path: T) -> Result<(), Error> {
|
pub async fn delete<T: AsRef<str>>(&self, path: T) -> Result<(), Error> {
|
||||||
let response = self.reqwest.delete(self.url.join(path.as_ref())?)
|
let response = self
|
||||||
|
.reqwest
|
||||||
|
.delete(self.url.join(path.as_ref())?)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if response.status().as_u16() == 401 {
|
if response.status().as_u16() == 401 {
|
||||||
return Err(Error::Authentication(response.text().await?))
|
return Err(Error::Authentication(response.text().await?));
|
||||||
} else if response.status().as_u16() == 400 {
|
} else if response.status().as_u16() == 400 {
|
||||||
return Err(Error::BadRequest(response.text().await?))
|
return Err(Error::BadRequest(response.text().await?));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -240,14 +250,16 @@ impl<'a> Storage {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn list<T: AsRef<str>>(&self, path: T) -> Result<Vec<ListFile>, Error> {
|
pub async fn list<T: AsRef<str>>(&self, path: T) -> Result<Vec<ListFile>, Error> {
|
||||||
let response = self.reqwest.get(self.url.join(path.as_ref())?)
|
let response = self
|
||||||
|
.reqwest
|
||||||
|
.get(self.url.join(path.as_ref())?)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if response.status().as_u16() == 401 {
|
if response.status().as_u16() == 401 {
|
||||||
return Err(Error::Authentication(response.text().await?))
|
return Err(Error::Authentication(response.text().await?));
|
||||||
} else if response.status().as_u16() == 400 {
|
} else if response.status().as_u16() == 400 {
|
||||||
return Err(Error::BadRequest(response.text().await?))
|
return Err(Error::BadRequest(response.text().await?));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(response.json().await?)
|
Ok(response.json().await?)
|
||||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -19,18 +19,21 @@
|
||||||
//! ```
|
//! ```
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
use reqwest::{header::{HeaderMap, HeaderValue}, Client as RClient};
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
use reqwest::{
|
||||||
|
Client as RClient,
|
||||||
|
header::{HeaderMap, HeaderValue},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
pub mod edge_storage;
|
pub mod edge_storage;
|
||||||
|
pub mod error;
|
||||||
|
|
||||||
/// API Client for bunny
|
/// API Client for bunny
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
/// Used to interact with the Edge Storage API
|
/// Used to interact with the Edge Storage API
|
||||||
pub storage: edge_storage::Storage
|
pub storage: edge_storage::Storage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
|
@ -50,9 +53,7 @@ impl Client {
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.append("AccessKey", HeaderValue::from_str(api_key.as_ref())?);
|
headers.append("AccessKey", HeaderValue::from_str(api_key.as_ref())?);
|
||||||
|
|
||||||
let reqwest = Arc::new(RClient::builder()
|
let reqwest = Arc::new(RClient::builder().default_headers(headers).build()?);
|
||||||
.default_headers(headers)
|
|
||||||
.build()?);
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
storage: edge_storage::Storage {
|
storage: edge_storage::Storage {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue