dls dlset support
This commit is contained in:
49
src/dls.rs
49
src/dls.rs
@ -45,12 +45,26 @@ impl Client {
|
||||
Host { dls: self, name }
|
||||
}
|
||||
|
||||
pub async fn get_json<T: serde::de::DeserializeOwned>(&self, path: impl Display) -> Result<T> {
|
||||
let req = self.get(&path)?.header("Accept", "application/json");
|
||||
pub async fn sign_dl_set(&self, req: &DownloadSetReq) -> Result<String> {
|
||||
let req = (self.req(Method::POST, "sign-download-set")?).json(req);
|
||||
self.req_json(req).await
|
||||
}
|
||||
pub async fn fetch_dl_set(
|
||||
&self,
|
||||
signed_dlset: &str,
|
||||
kind: &str,
|
||||
name: &str,
|
||||
asset: &str,
|
||||
) -> Result<impl Stream<Item = reqwest::Result<Bytes>>> {
|
||||
let req = self.get(format!(
|
||||
"public/download-set/{kind}/{name}/{asset}?set={signed_dlset}"
|
||||
))?;
|
||||
let resp = do_req(req, &self.token).await?;
|
||||
Ok(resp.bytes_stream())
|
||||
}
|
||||
|
||||
let body = resp.bytes().await.map_err(Error::Read)?;
|
||||
serde_json::from_slice(&body).map_err(Error::Parse)
|
||||
pub async fn get_json<T: serde::de::DeserializeOwned>(&self, path: impl Display) -> Result<T> {
|
||||
self.req_json(self.get(&path)?).await
|
||||
}
|
||||
pub async fn get_bytes(&self, path: impl Display) -> Result<Vec<u8>> {
|
||||
let resp = do_req(self.get(&path)?, &self.token).await?;
|
||||
@ -60,6 +74,16 @@ impl Client {
|
||||
self.req(Method::GET, path)
|
||||
}
|
||||
|
||||
pub async fn req_json<T: serde::de::DeserializeOwned>(
|
||||
&self,
|
||||
req: reqwest::RequestBuilder,
|
||||
) -> Result<T> {
|
||||
let req = req.header("Accept", "application/json");
|
||||
let resp = do_req(req, &self.token).await?;
|
||||
|
||||
let body = resp.bytes().await.map_err(Error::Read)?;
|
||||
serde_json::from_slice(&body).map_err(Error::Parse)
|
||||
}
|
||||
pub fn req(&self, method: Method, path: impl Display) -> Result<reqwest::RequestBuilder> {
|
||||
let uri = format!("{}/{path}", self.base_url);
|
||||
|
||||
@ -184,6 +208,23 @@ pub struct KubeSignReq {
|
||||
pub validity: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct DownloadSetReq {
|
||||
pub expiry: String,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub items: Vec<DownloadSetItem>,
|
||||
}
|
||||
|
||||
#[derive(Clone, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct DownloadSetItem {
|
||||
pub kind: String,
|
||||
pub name: String,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub assets: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct ServerError {
|
||||
#[serde(default)]
|
||||
|
||||
Reference in New Issue
Block a user