Skip to main content

geoengine_api_client/apis/
uploads_api.rs

1/*
2 * Geo Engine API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * Contact: dev@geoengine.de
7 * Generated by: https://openapi-generator.tech
8 */
9
10
11use reqwest;
12use serde::{Deserialize, Serialize, de::Error as _};
13use crate::{apis::ResponseContent, models};
14use super::{Error, configuration, ContentType};
15use tokio::fs::File as TokioFile;
16use tokio_util::codec::{BytesCodec, FramedRead};
17
18
19/// struct for typed errors of method [`list_upload_file_layers_handler`]
20#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(untagged)]
22pub enum ListUploadFileLayersHandlerError {
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`list_upload_files_handler`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ListUploadFilesHandlerError {
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`upload_handler`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum UploadHandlerError {
37    UnknownValue(serde_json::Value),
38}
39
40
41pub async fn list_upload_file_layers_handler(configuration: &configuration::Configuration, upload_id: &str, file_name: &str) -> Result<models::UploadFileLayersResponse, Error<ListUploadFileLayersHandlerError>> {
42    // add a prefix to parameters to efficiently prevent name collisions
43    let p_path_upload_id = upload_id;
44    let p_path_file_name = file_name;
45
46    let uri_str = format!("{}/uploads/{upload_id}/files/{file_name}/layers", configuration.base_path, upload_id=crate::apis::urlencode(p_path_upload_id), file_name=crate::apis::urlencode(p_path_file_name));
47    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
48
49    if let Some(ref user_agent) = configuration.user_agent {
50        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
51    }
52    if let Some(ref token) = configuration.bearer_access_token {
53        req_builder = req_builder.bearer_auth(token.to_owned());
54    };
55
56    let req = req_builder.build()?;
57    let resp = configuration.client.execute(req).await?;
58
59    let status = resp.status();
60    let content_type = resp
61        .headers()
62        .get("content-type")
63        .and_then(|v| v.to_str().ok())
64        .unwrap_or("application/octet-stream");
65    let content_type = super::ContentType::from(content_type);
66
67    if !status.is_client_error() && !status.is_server_error() {
68        let content = resp.text().await?;
69        match content_type {
70            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
71            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UploadFileLayersResponse`"))),
72            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::UploadFileLayersResponse`")))),
73        }
74    } else {
75        let content = resp.text().await?;
76        let entity: Option<ListUploadFileLayersHandlerError> = serde_json::from_str(&content).ok();
77        Err(Error::ResponseError(ResponseContent { status, content, entity }))
78    }
79}
80
81pub async fn list_upload_files_handler(configuration: &configuration::Configuration, upload_id: &str) -> Result<models::UploadFilesResponse, Error<ListUploadFilesHandlerError>> {
82    // add a prefix to parameters to efficiently prevent name collisions
83    let p_path_upload_id = upload_id;
84
85    let uri_str = format!("{}/uploads/{upload_id}/files", configuration.base_path, upload_id=crate::apis::urlencode(p_path_upload_id));
86    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
87
88    if let Some(ref user_agent) = configuration.user_agent {
89        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
90    }
91    if let Some(ref token) = configuration.bearer_access_token {
92        req_builder = req_builder.bearer_auth(token.to_owned());
93    };
94
95    let req = req_builder.build()?;
96    let resp = configuration.client.execute(req).await?;
97
98    let status = resp.status();
99    let content_type = resp
100        .headers()
101        .get("content-type")
102        .and_then(|v| v.to_str().ok())
103        .unwrap_or("application/octet-stream");
104    let content_type = super::ContentType::from(content_type);
105
106    if !status.is_client_error() && !status.is_server_error() {
107        let content = resp.text().await?;
108        match content_type {
109            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
110            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UploadFilesResponse`"))),
111            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::UploadFilesResponse`")))),
112        }
113    } else {
114        let content = resp.text().await?;
115        let entity: Option<ListUploadFilesHandlerError> = serde_json::from_str(&content).ok();
116        Err(Error::ResponseError(ResponseContent { status, content, entity }))
117    }
118}
119
120pub async fn upload_handler(configuration: &configuration::Configuration, files_left_square_bracket_right_square_bracket: Vec<std::path::PathBuf>) -> Result<models::IdResponse, Error<UploadHandlerError>> {
121    // add a prefix to parameters to efficiently prevent name collisions
122    let p_form_files_left_square_bracket_right_square_bracket = files_left_square_bracket_right_square_bracket;
123
124    let uri_str = format!("{}/upload", configuration.base_path);
125    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
126
127    if let Some(ref user_agent) = configuration.user_agent {
128        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129    }
130    if let Some(ref token) = configuration.bearer_access_token {
131        req_builder = req_builder.bearer_auth(token.to_owned());
132    };
133    let mut multipart_form = reqwest::multipart::Form::new();
134    for value in &p_form_files_left_square_bracket_right_square_bracket {
135        let file = TokioFile::open(value).await?;
136        let stream = FramedRead::new(file, BytesCodec::new());
137        let file_name = value.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
138        let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
139        multipart_form = multipart_form.part("files[]", file_part);
140    }
141    req_builder = req_builder.multipart(multipart_form);
142
143    let req = req_builder.build()?;
144    let resp = configuration.client.execute(req).await?;
145
146    let status = resp.status();
147    let content_type = resp
148        .headers()
149        .get("content-type")
150        .and_then(|v| v.to_str().ok())
151        .unwrap_or("application/octet-stream");
152    let content_type = super::ContentType::from(content_type);
153
154    if !status.is_client_error() && !status.is_server_error() {
155        let content = resp.text().await?;
156        match content_type {
157            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
158            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::IdResponse`"))),
159            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::IdResponse`")))),
160        }
161    } else {
162        let content = resp.text().await?;
163        let entity: Option<UploadHandlerError> = serde_json::from_str(&content).ok();
164        Err(Error::ResponseError(ResponseContent { status, content, entity }))
165    }
166}
167