Skip to main content

clientapi_pbs/apis/
reader_upgrade_api.rs

1/*
2 * Proxmox Backup Server API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pbs.proxmox.com/docs/api-viewer/ for the upstream documentation.
5 *
6 * The version of the OpenAPI document: 9.x
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`reader_upgrade_get_chunk`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ReaderUpgradeGetChunkError {
22    Status400(models::PbsError),
23    Status401(models::PbsError),
24    Status403(models::PbsError),
25    Status404(models::PbsError),
26    Status500(models::PbsError),
27    Status501(models::PbsError),
28    Status503(models::PbsError),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`reader_upgrade_get_download`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ReaderUpgradeGetDownloadError {
36    Status400(models::PbsError),
37    Status401(models::PbsError),
38    Status403(models::PbsError),
39    Status404(models::PbsError),
40    Status500(models::PbsError),
41    Status501(models::PbsError),
42    Status503(models::PbsError),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`reader_upgrade_get_speedtest`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ReaderUpgradeGetSpeedtestError {
50    Status400(models::PbsError),
51    Status401(models::PbsError),
52    Status403(models::PbsError),
53    Status404(models::PbsError),
54    Status500(models::PbsError),
55    Status501(models::PbsError),
56    Status503(models::PbsError),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`reader_upgrade_get_upgrade`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ReaderUpgradeGetUpgradeError {
64    Status400(models::PbsError),
65    Status401(models::PbsError),
66    Status403(models::PbsError),
67    Status404(models::PbsError),
68    Status500(models::PbsError),
69    Status501(models::PbsError),
70    Status503(models::PbsError),
71    UnknownValue(serde_json::Value),
72}
73
74
75/// Download specified chunk.
76pub async fn reader_upgrade_get_chunk(configuration: &configuration::Configuration, digest: &str) -> Result<models::ReaderUpgradeGetChunkResponse, Error<ReaderUpgradeGetChunkError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_query_digest = digest;
79
80    let uri_str = format!("{}/reader/_upgrade_/chunk", configuration.base_path);
81    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
82
83    req_builder = req_builder.query(&[("digest", &p_query_digest.to_string())]);
84    if let Some(ref user_agent) = configuration.user_agent {
85        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86    }
87    if let Some(ref apikey) = configuration.api_key {
88        let key = apikey.key.clone();
89        let value = match apikey.prefix {
90            Some(ref prefix) => format!("{} {}", prefix, key),
91            None => key,
92        };
93        req_builder = req_builder.header("Authorization", value);
94    };
95    if let Some(ref apikey) = configuration.api_key {
96        let key = apikey.key.clone();
97        let value = match apikey.prefix {
98            Some(ref prefix) => format!("{} {}", prefix, key),
99            None => key,
100        };
101        req_builder = req_builder.header("CSRFPreventionToken", value);
102    };
103
104    let req = req_builder.build()?;
105    let resp = configuration.client.execute(req).await?;
106
107    let status = resp.status();
108    let content_type = resp
109        .headers()
110        .get("content-type")
111        .and_then(|v| v.to_str().ok())
112        .unwrap_or("application/octet-stream");
113    let content_type = super::ContentType::from(content_type);
114
115    if !status.is_client_error() && !status.is_server_error() {
116        let content = resp.text().await?;
117        match content_type {
118            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
119            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReaderUpgradeGetChunkResponse`"))),
120            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ReaderUpgradeGetChunkResponse`")))),
121        }
122    } else {
123        let content = resp.text().await?;
124        let entity: Option<ReaderUpgradeGetChunkError> = serde_json::from_str(&content).ok();
125        Err(Error::ResponseError(ResponseContent { status, content, entity }))
126    }
127}
128
129/// Download specified file.
130pub async fn reader_upgrade_get_download(configuration: &configuration::Configuration, file_name: &str) -> Result<models::ReaderUpgradeGetDownloadResponse, Error<ReaderUpgradeGetDownloadError>> {
131    // add a prefix to parameters to efficiently prevent name collisions
132    let p_query_file_name = file_name;
133
134    let uri_str = format!("{}/reader/_upgrade_/download", configuration.base_path);
135    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
136
137    req_builder = req_builder.query(&[("file-name", &p_query_file_name.to_string())]);
138    if let Some(ref user_agent) = configuration.user_agent {
139        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
140    }
141    if let Some(ref apikey) = configuration.api_key {
142        let key = apikey.key.clone();
143        let value = match apikey.prefix {
144            Some(ref prefix) => format!("{} {}", prefix, key),
145            None => key,
146        };
147        req_builder = req_builder.header("Authorization", value);
148    };
149    if let Some(ref apikey) = configuration.api_key {
150        let key = apikey.key.clone();
151        let value = match apikey.prefix {
152            Some(ref prefix) => format!("{} {}", prefix, key),
153            None => key,
154        };
155        req_builder = req_builder.header("CSRFPreventionToken", value);
156    };
157
158    let req = req_builder.build()?;
159    let resp = configuration.client.execute(req).await?;
160
161    let status = resp.status();
162    let content_type = resp
163        .headers()
164        .get("content-type")
165        .and_then(|v| v.to_str().ok())
166        .unwrap_or("application/octet-stream");
167    let content_type = super::ContentType::from(content_type);
168
169    if !status.is_client_error() && !status.is_server_error() {
170        let content = resp.text().await?;
171        match content_type {
172            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
173            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReaderUpgradeGetDownloadResponse`"))),
174            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ReaderUpgradeGetDownloadResponse`")))),
175        }
176    } else {
177        let content = resp.text().await?;
178        let entity: Option<ReaderUpgradeGetDownloadError> = serde_json::from_str(&content).ok();
179        Err(Error::ResponseError(ResponseContent { status, content, entity }))
180    }
181}
182
183/// Test 1M block download speed.
184pub async fn reader_upgrade_get_speedtest(configuration: &configuration::Configuration, ) -> Result<models::ReaderUpgradeGetSpeedtestResponse, Error<ReaderUpgradeGetSpeedtestError>> {
185
186    let uri_str = format!("{}/reader/_upgrade_/speedtest", configuration.base_path);
187    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
188
189    if let Some(ref user_agent) = configuration.user_agent {
190        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
191    }
192    if let Some(ref apikey) = configuration.api_key {
193        let key = apikey.key.clone();
194        let value = match apikey.prefix {
195            Some(ref prefix) => format!("{} {}", prefix, key),
196            None => key,
197        };
198        req_builder = req_builder.header("Authorization", value);
199    };
200    if let Some(ref apikey) = configuration.api_key {
201        let key = apikey.key.clone();
202        let value = match apikey.prefix {
203            Some(ref prefix) => format!("{} {}", prefix, key),
204            None => key,
205        };
206        req_builder = req_builder.header("CSRFPreventionToken", value);
207    };
208
209    let req = req_builder.build()?;
210    let resp = configuration.client.execute(req).await?;
211
212    let status = resp.status();
213    let content_type = resp
214        .headers()
215        .get("content-type")
216        .and_then(|v| v.to_str().ok())
217        .unwrap_or("application/octet-stream");
218    let content_type = super::ContentType::from(content_type);
219
220    if !status.is_client_error() && !status.is_server_error() {
221        let content = resp.text().await?;
222        match content_type {
223            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
224            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReaderUpgradeGetSpeedtestResponse`"))),
225            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ReaderUpgradeGetSpeedtestResponse`")))),
226        }
227    } else {
228        let content = resp.text().await?;
229        let entity: Option<ReaderUpgradeGetSpeedtestError> = serde_json::from_str(&content).ok();
230        Err(Error::ResponseError(ResponseContent { status, content, entity }))
231    }
232}
233
234/// Directory index.
235pub async fn reader_upgrade_get_upgrade(configuration: &configuration::Configuration, ) -> Result<models::ReaderUpgradeGetUpgradeResponse, Error<ReaderUpgradeGetUpgradeError>> {
236
237    let uri_str = format!("{}/reader/_upgrade_", configuration.base_path);
238    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
239
240    if let Some(ref user_agent) = configuration.user_agent {
241        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
242    }
243    if let Some(ref apikey) = configuration.api_key {
244        let key = apikey.key.clone();
245        let value = match apikey.prefix {
246            Some(ref prefix) => format!("{} {}", prefix, key),
247            None => key,
248        };
249        req_builder = req_builder.header("Authorization", value);
250    };
251    if let Some(ref apikey) = configuration.api_key {
252        let key = apikey.key.clone();
253        let value = match apikey.prefix {
254            Some(ref prefix) => format!("{} {}", prefix, key),
255            None => key,
256        };
257        req_builder = req_builder.header("CSRFPreventionToken", value);
258    };
259
260    let req = req_builder.build()?;
261    let resp = configuration.client.execute(req).await?;
262
263    let status = resp.status();
264    let content_type = resp
265        .headers()
266        .get("content-type")
267        .and_then(|v| v.to_str().ok())
268        .unwrap_or("application/octet-stream");
269    let content_type = super::ContentType::from(content_type);
270
271    if !status.is_client_error() && !status.is_server_error() {
272        let content = resp.text().await?;
273        match content_type {
274            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
275            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReaderUpgradeGetUpgradeResponse`"))),
276            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ReaderUpgradeGetUpgradeResponse`")))),
277        }
278    } else {
279        let content = resp.text().await?;
280        let entity: Option<ReaderUpgradeGetUpgradeError> = serde_json::from_str(&content).ok();
281        Err(Error::ResponseError(ResponseContent { status, content, entity }))
282    }
283}
284