1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::api::{B2Auth, B2DownloadAuth};
use crate::Error;
use reqwest::{Client, Response};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct B2DownloadFileByNameParams {
pub bucket_name: String,
pub file_name: String,
pub authorization: Option<B2DownloadAuth>,
}
pub async fn b2_download_file_by_name(
client: &Client,
auth: &B2Auth,
params: B2DownloadFileByNameParams,
) -> Result<Response, Error> {
let auth_token = match params.authorization {
Some(ref a) => &a.authorization_token,
None => &auth.authorization_token,
};
let resp = match client
.get(&auth.download_url_by_name(¶ms.bucket_name, ¶ms.file_name))
.header(reqwest::header::AUTHORIZATION, auth_token)
.send()
.await
{
Ok(v) => v,
Err(e) => return Err(Error::ReqwestError(e)),
};
if !resp.status().is_success() {
return Err(Error::from_response(resp).await);
}
Ok(resp)
}