zsgf_client/apis/
file_api.rs

1/*
2 * 全部  API 文档
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: v1
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 [`file_create_folder`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum FileCreateFolderError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`file_delete`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum FileDeleteError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`file_rename`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum FileRenameError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`file_upload`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum FileUploadError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`files`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum FilesError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// 在指定路径创建文件夹
55pub async fn file_create_folder(configuration: &configuration::Configuration, app_key: &str, path: Option<&str>) -> Result<models::BooleanApiResponse, Error<FileCreateFolderError>> {
56    // add a prefix to parameters to efficiently prevent name collisions
57    let p_app_key = app_key;
58    let p_path = path;
59
60    let uri_str = format!("{}/File/{appKey}/CreateFolder", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
61    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
62
63    if let Some(ref param_value) = p_path {
64        req_builder = req_builder.query(&[("path", &param_value.to_string())]);
65    }
66    if let Some(ref user_agent) = configuration.user_agent {
67        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
68    }
69    if let Some(ref token) = configuration.bearer_access_token {
70        req_builder = req_builder.bearer_auth(token.to_owned());
71    };
72
73    let req = req_builder.build()?;
74    let resp = configuration.client.execute(req).await?;
75
76    let status = resp.status();
77    let content_type = resp
78        .headers()
79        .get("content-type")
80        .and_then(|v| v.to_str().ok())
81        .unwrap_or("application/octet-stream");
82    let content_type = super::ContentType::from(content_type);
83
84    if !status.is_client_error() && !status.is_server_error() {
85        let content = resp.text().await?;
86        match content_type {
87            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
88            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
89            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::BooleanApiResponse`")))),
90        }
91    } else {
92        let content = resp.text().await?;
93        let entity: Option<FileCreateFolderError> = serde_json::from_str(&content).ok();
94        Err(Error::ResponseError(ResponseContent { status, content, entity }))
95    }
96}
97
98/// 根据指定路径删除文件或文件夹
99pub async fn file_delete(configuration: &configuration::Configuration, app_key: &str, path: Option<&str>) -> Result<models::BooleanApiResponse, Error<FileDeleteError>> {
100    // add a prefix to parameters to efficiently prevent name collisions
101    let p_app_key = app_key;
102    let p_path = path;
103
104    let uri_str = format!("{}/File/{appKey}", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
105    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
106
107    if let Some(ref param_value) = p_path {
108        req_builder = req_builder.query(&[("path", &param_value.to_string())]);
109    }
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    if let Some(ref token) = configuration.bearer_access_token {
114        req_builder = req_builder.bearer_auth(token.to_owned());
115    };
116
117    let req = req_builder.build()?;
118    let resp = configuration.client.execute(req).await?;
119
120    let status = resp.status();
121    let content_type = resp
122        .headers()
123        .get("content-type")
124        .and_then(|v| v.to_str().ok())
125        .unwrap_or("application/octet-stream");
126    let content_type = super::ContentType::from(content_type);
127
128    if !status.is_client_error() && !status.is_server_error() {
129        let content = resp.text().await?;
130        match content_type {
131            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
132            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
133            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::BooleanApiResponse`")))),
134        }
135    } else {
136        let content = resp.text().await?;
137        let entity: Option<FileDeleteError> = serde_json::from_str(&content).ok();
138        Err(Error::ResponseError(ResponseContent { status, content, entity }))
139    }
140}
141
142/// 将指定的文件或文件夹重命名
143pub async fn file_rename(configuration: &configuration::Configuration, app_key: &str, source_name: Option<&str>, dest_name: Option<&str>) -> Result<models::BooleanApiResponse, Error<FileRenameError>> {
144    // add a prefix to parameters to efficiently prevent name collisions
145    let p_app_key = app_key;
146    let p_source_name = source_name;
147    let p_dest_name = dest_name;
148
149    let uri_str = format!("{}/File/{appKey}/Rename", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
150    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
151
152    if let Some(ref param_value) = p_source_name {
153        req_builder = req_builder.query(&[("sourceName", &param_value.to_string())]);
154    }
155    if let Some(ref param_value) = p_dest_name {
156        req_builder = req_builder.query(&[("destName", &param_value.to_string())]);
157    }
158    if let Some(ref user_agent) = configuration.user_agent {
159        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
160    }
161    if let Some(ref token) = configuration.bearer_access_token {
162        req_builder = req_builder.bearer_auth(token.to_owned());
163    };
164
165    let req = req_builder.build()?;
166    let resp = configuration.client.execute(req).await?;
167
168    let status = resp.status();
169    let content_type = resp
170        .headers()
171        .get("content-type")
172        .and_then(|v| v.to_str().ok())
173        .unwrap_or("application/octet-stream");
174    let content_type = super::ContentType::from(content_type);
175
176    if !status.is_client_error() && !status.is_server_error() {
177        let content = resp.text().await?;
178        match content_type {
179            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
180            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
181            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::BooleanApiResponse`")))),
182        }
183    } else {
184        let content = resp.text().await?;
185        let entity: Option<FileRenameError> = serde_json::from_str(&content).ok();
186        Err(Error::ResponseError(ResponseContent { status, content, entity }))
187    }
188}
189
190/// 将文件上传到指定路径
191pub async fn file_upload(configuration: &configuration::Configuration, app_key: &str, path: Option<&str>, file: Option<std::path::PathBuf>) -> Result<models::BooleanApiResponse, Error<FileUploadError>> {
192    // add a prefix to parameters to efficiently prevent name collisions
193    let p_app_key = app_key;
194    let p_path = path;
195    let p_file = file;
196
197    let uri_str = format!("{}/File/{appKey}/Upload", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
198    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
199
200    if let Some(ref param_value) = p_path {
201        req_builder = req_builder.query(&[("path", &param_value.to_string())]);
202    }
203    if let Some(ref user_agent) = configuration.user_agent {
204        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
205    }
206    if let Some(ref token) = configuration.bearer_access_token {
207        req_builder = req_builder.bearer_auth(token.to_owned());
208    };
209    let mut multipart_form = reqwest::multipart::Form::new();
210    // TODO: support file upload for 'file' parameter
211    req_builder = req_builder.multipart(multipart_form);
212
213    let req = req_builder.build()?;
214    let resp = configuration.client.execute(req).await?;
215
216    let status = resp.status();
217    let content_type = resp
218        .headers()
219        .get("content-type")
220        .and_then(|v| v.to_str().ok())
221        .unwrap_or("application/octet-stream");
222    let content_type = super::ContentType::from(content_type);
223
224    if !status.is_client_error() && !status.is_server_error() {
225        let content = resp.text().await?;
226        match content_type {
227            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
228            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
229            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::BooleanApiResponse`")))),
230        }
231    } else {
232        let content = resp.text().await?;
233        let entity: Option<FileUploadError> = serde_json::from_str(&content).ok();
234        Err(Error::ResponseError(ResponseContent { status, content, entity }))
235    }
236}
237
238/// 根据指定路径获取文件和文件夹列表
239pub async fn files(configuration: &configuration::Configuration, app_key: &str, path: Option<&str>, skip: Option<i32>, take: Option<i32>) -> Result<models::FileListResultApiResponse, Error<FilesError>> {
240    // add a prefix to parameters to efficiently prevent name collisions
241    let p_app_key = app_key;
242    let p_path = path;
243    let p_skip = skip;
244    let p_take = take;
245
246    let uri_str = format!("{}/File/{appKey}", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
247    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
248
249    if let Some(ref param_value) = p_path {
250        req_builder = req_builder.query(&[("path", &param_value.to_string())]);
251    }
252    if let Some(ref param_value) = p_skip {
253        req_builder = req_builder.query(&[("skip", &param_value.to_string())]);
254    }
255    if let Some(ref param_value) = p_take {
256        req_builder = req_builder.query(&[("take", &param_value.to_string())]);
257    }
258    if let Some(ref user_agent) = configuration.user_agent {
259        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
260    }
261    if let Some(ref token) = configuration.bearer_access_token {
262        req_builder = req_builder.bearer_auth(token.to_owned());
263    };
264
265    let req = req_builder.build()?;
266    let resp = configuration.client.execute(req).await?;
267
268    let status = resp.status();
269    let content_type = resp
270        .headers()
271        .get("content-type")
272        .and_then(|v| v.to_str().ok())
273        .unwrap_or("application/octet-stream");
274    let content_type = super::ContentType::from(content_type);
275
276    if !status.is_client_error() && !status.is_server_error() {
277        let content = resp.text().await?;
278        match content_type {
279            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
280            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FileListResultApiResponse`"))),
281            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::FileListResultApiResponse`")))),
282        }
283    } else {
284        let content = resp.text().await?;
285        let entity: Option<FilesError> = serde_json::from_str(&content).ok();
286        Err(Error::ResponseError(ResponseContent { status, content, entity }))
287    }
288}
289