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