netlify_rust/apis/
file_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetSiteFileByPathNameError {
22 DefaultResponse(crate::models::Error),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ListSiteFilesError {
30 DefaultResponse(crate::models::Error),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum UploadDeployFileError {
38 DefaultResponse(crate::models::Error),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn get_site_file_by_path_name(configuration: &configuration::Configuration, site_id: &str, file_path: &str) -> Result<std::path::PathBuf, Error<GetSiteFileByPathNameError>> {
44
45 let local_var_client = &configuration.client;
46
47 let local_var_uri_str = format!("{}/sites/{site_id}/files/{file_path}", configuration.base_path, site_id=crate::apis::urlencode(site_id), file_path=crate::apis::urlencode(file_path));
48 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
49
50 if let Some(ref local_var_user_agent) = configuration.user_agent {
51 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
52 }
53 if let Some(ref local_var_token) = configuration.oauth_access_token {
54 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
55 };
56
57 let local_var_req = local_var_req_builder.build()?;
58 let local_var_resp = local_var_client.execute(local_var_req).await?;
59
60 let local_var_status = local_var_resp.status();
61 let local_var_content = local_var_resp.text().await?;
62
63 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
64 serde_json::from_str(&local_var_content).map_err(Error::from)
65 } else {
66 let local_var_entity: Option<GetSiteFileByPathNameError> = serde_json::from_str(&local_var_content).ok();
67 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
68 Err(Error::ResponseError(local_var_error))
69 }
70}
71
72pub async fn list_site_files(configuration: &configuration::Configuration, site_id: &str) -> Result<Vec<std::path::PathBuf>, Error<ListSiteFilesError>> {
73
74 let local_var_client = &configuration.client;
75
76 let local_var_uri_str = format!("{}/sites/{site_id}/files", configuration.base_path, site_id=crate::apis::urlencode(site_id));
77 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
78
79 if let Some(ref local_var_user_agent) = configuration.user_agent {
80 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
81 }
82 if let Some(ref local_var_token) = configuration.oauth_access_token {
83 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
84 };
85
86 let local_var_req = local_var_req_builder.build()?;
87 let local_var_resp = local_var_client.execute(local_var_req).await?;
88
89 let local_var_status = local_var_resp.status();
90 let local_var_content = local_var_resp.text().await?;
91
92 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
93 serde_json::from_str(&local_var_content).map_err(Error::from)
94 } else {
95 let local_var_entity: Option<ListSiteFilesError> = serde_json::from_str(&local_var_content).ok();
96 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
97 Err(Error::ResponseError(local_var_error))
98 }
99}
100
101pub async fn upload_deploy_file(configuration: &configuration::Configuration, deploy_id: &str, path: &str, file_body: std::path::PathBuf, size: Option<i32>) -> Result<std::path::PathBuf, Error<UploadDeployFileError>> {
102
103 let local_var_client = &configuration.client;
104
105 let local_var_uri_str = format!("{}/deploys/{deploy_id}/files/{path}", configuration.base_path, deploy_id=crate::apis::urlencode(deploy_id), path=crate::apis::urlencode(path));
106 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
107
108 if let Some(ref local_var_str) = size {
109 local_var_req_builder = local_var_req_builder.query(&[("size", &local_var_str.to_string())]);
110 }
111 if let Some(ref local_var_user_agent) = configuration.user_agent {
112 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
113 }
114 if let Some(ref local_var_token) = configuration.oauth_access_token {
115 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
116 };
117 local_var_req_builder = local_var_req_builder.json(&file_body);
118
119 let local_var_req = local_var_req_builder.build()?;
120 let local_var_resp = local_var_client.execute(local_var_req).await?;
121
122 let local_var_status = local_var_resp.status();
123 let local_var_content = local_var_resp.text().await?;
124
125 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
126 serde_json::from_str(&local_var_content).map_err(Error::from)
127 } else {
128 let local_var_entity: Option<UploadDeployFileError> = serde_json::from_str(&local_var_content).ok();
129 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
130 Err(Error::ResponseError(local_var_error))
131 }
132}
133