Skip to main content

komga_sdk/apis/
client_settings_api.rs

1/*
2 * Komga API
3 *
4 * Komga REST API.  ## Reference  Check the API reference: - on the [Komga website](https://komga.org/docs/openapi/komga-api) - on any running Komga instance at `/swagger-ui.html` - on [GitHub](https://raw.githubusercontent.com/gotson/komga/refs/heads/master/komga/docs/openapi.json)  ## Authentication  Most endpoints require authentication. Authentication is done using either: - Basic Authentication - Passing an API Key in the `X-API-Key` header  ## Sessions  Upon successful authentication, a session is created, and can be reused.  - By default, a `KOMGA-SESSION` cookie is set via `Set-Cookie` response header. This works well for browsers and clients that can handle cookies. - If you specify a header `X-Auth-Token` during authentication, the session ID will be returned via this same header. You can then pass that header again for subsequent requests to reuse the session.  If you need to set the session cookie later on, you can call `/api/v1/login/set-cookie` with `X-Auth-Token`. The response will contain the `Set-Cookie` header.  ## Remember Me  During authentication, if a request parameter `remember-me` is passed and set to `true`, the server will also return a `komga-remember-me` cookie. This cookie will be used to login automatically even if the session has expired.  ## Logout  You can explicitly logout an existing session by calling `/api/logout`. This would return a `204`.  ## Deprecation  API endpoints marked as deprecated will be removed in the next major version.
5 *
6 * The version of the OpenAPI document: 1.23.4
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 [`delete_global_settings`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteGlobalSettingsError {
22    Status400(models::ValidationErrorResponse),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_user_settings`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteUserSettingsError {
30    Status400(models::ValidationErrorResponse),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_global_settings`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetGlobalSettingsError {
38    Status400(models::ValidationErrorResponse),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_user_settings`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetUserSettingsError {
46    Status400(models::ValidationErrorResponse),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`save_global_setting`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum SaveGlobalSettingError {
54    Status400(models::ValidationErrorResponse),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`save_user_setting`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum SaveUserSettingError {
62    Status400(models::ValidationErrorResponse),
63    UnknownValue(serde_json::Value),
64}
65
66
67/// Setting key should be a valid lowercase namespace string like 'application.domain.key'  Required role: **ADMIN**
68pub async fn delete_global_settings(configuration: &configuration::Configuration, request_body: Vec<String>) -> Result<(), Error<DeleteGlobalSettingsError>> {
69    // add a prefix to parameters to efficiently prevent name collisions
70    let p_body_request_body = request_body;
71
72    let uri_str = format!("{}/api/v1/client-settings/global", configuration.base_path);
73    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
74
75    if let Some(ref user_agent) = configuration.user_agent {
76        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77    }
78    if let Some(ref apikey) = configuration.api_key {
79        let key = apikey.key.clone();
80        let value = match apikey.prefix {
81            Some(ref prefix) => format!("{} {}", prefix, key),
82            None => key,
83        };
84        req_builder = req_builder.header("X-API-Key", value);
85    };
86    if let Some(ref auth_conf) = configuration.basic_auth {
87        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
88    };
89    req_builder = req_builder.json(&p_body_request_body);
90
91    let req = req_builder.build()?;
92    let resp = configuration.client.execute(req).await?;
93
94    let status = resp.status();
95
96    if !status.is_client_error() && !status.is_server_error() {
97        Ok(())
98    } else {
99        let content = resp.text().await?;
100        let entity: Option<DeleteGlobalSettingsError> = serde_json::from_str(&content).ok();
101        Err(Error::ResponseError(ResponseContent { status, content, entity }))
102    }
103}
104
105/// Setting key should be a valid lowercase namespace string like 'application.domain.key'
106pub async fn delete_user_settings(configuration: &configuration::Configuration, request_body: Vec<String>) -> Result<(), Error<DeleteUserSettingsError>> {
107    // add a prefix to parameters to efficiently prevent name collisions
108    let p_body_request_body = request_body;
109
110    let uri_str = format!("{}/api/v1/client-settings/user", configuration.base_path);
111    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
112
113    if let Some(ref user_agent) = configuration.user_agent {
114        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
115    }
116    if let Some(ref apikey) = configuration.api_key {
117        let key = apikey.key.clone();
118        let value = match apikey.prefix {
119            Some(ref prefix) => format!("{} {}", prefix, key),
120            None => key,
121        };
122        req_builder = req_builder.header("X-API-Key", value);
123    };
124    if let Some(ref auth_conf) = configuration.basic_auth {
125        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
126    };
127    req_builder = req_builder.json(&p_body_request_body);
128
129    let req = req_builder.build()?;
130    let resp = configuration.client.execute(req).await?;
131
132    let status = resp.status();
133
134    if !status.is_client_error() && !status.is_server_error() {
135        Ok(())
136    } else {
137        let content = resp.text().await?;
138        let entity: Option<DeleteUserSettingsError> = serde_json::from_str(&content).ok();
139        Err(Error::ResponseError(ResponseContent { status, content, entity }))
140    }
141}
142
143/// For unauthenticated users, only settings with 'allowUnauthorized=true' will be returned.
144pub async fn get_global_settings(configuration: &configuration::Configuration, ) -> Result<std::collections::HashMap<String, models::ClientSettingDto>, Error<GetGlobalSettingsError>> {
145
146    let uri_str = format!("{}/api/v1/client-settings/global/list", configuration.base_path);
147    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
148
149    if let Some(ref user_agent) = configuration.user_agent {
150        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
151    }
152
153    let req = req_builder.build()?;
154    let resp = configuration.client.execute(req).await?;
155
156    let status = resp.status();
157    let content_type = resp
158        .headers()
159        .get("content-type")
160        .and_then(|v| v.to_str().ok())
161        .unwrap_or("application/octet-stream");
162    let content_type = super::ContentType::from(content_type);
163
164    if !status.is_client_error() && !status.is_server_error() {
165        let content = resp.text().await?;
166        match content_type {
167            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
168            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap&lt;String, models::ClientSettingDto&gt;`"))),
169            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap&lt;String, models::ClientSettingDto&gt;`")))),
170        }
171    } else {
172        let content = resp.text().await?;
173        let entity: Option<GetGlobalSettingsError> = serde_json::from_str(&content).ok();
174        Err(Error::ResponseError(ResponseContent { status, content, entity }))
175    }
176}
177
178pub async fn get_user_settings(configuration: &configuration::Configuration, ) -> Result<std::collections::HashMap<String, models::ClientSettingDto>, Error<GetUserSettingsError>> {
179
180    let uri_str = format!("{}/api/v1/client-settings/user/list", configuration.base_path);
181    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
182
183    if let Some(ref user_agent) = configuration.user_agent {
184        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
185    }
186    if let Some(ref apikey) = configuration.api_key {
187        let key = apikey.key.clone();
188        let value = match apikey.prefix {
189            Some(ref prefix) => format!("{} {}", prefix, key),
190            None => key,
191        };
192        req_builder = req_builder.header("X-API-Key", value);
193    };
194    if let Some(ref auth_conf) = configuration.basic_auth {
195        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
196    };
197
198    let req = req_builder.build()?;
199    let resp = configuration.client.execute(req).await?;
200
201    let status = resp.status();
202    let content_type = resp
203        .headers()
204        .get("content-type")
205        .and_then(|v| v.to_str().ok())
206        .unwrap_or("application/octet-stream");
207    let content_type = super::ContentType::from(content_type);
208
209    if !status.is_client_error() && !status.is_server_error() {
210        let content = resp.text().await?;
211        match content_type {
212            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
213            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap&lt;String, models::ClientSettingDto&gt;`"))),
214            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap&lt;String, models::ClientSettingDto&gt;`")))),
215        }
216    } else {
217        let content = resp.text().await?;
218        let entity: Option<GetUserSettingsError> = serde_json::from_str(&content).ok();
219        Err(Error::ResponseError(ResponseContent { status, content, entity }))
220    }
221}
222
223/// Setting key should be a valid lowercase namespace string like 'application.domain.key'  Required role: **ADMIN**
224pub async fn save_global_setting(configuration: &configuration::Configuration, request_body: std::collections::HashMap<String, models::ClientSettingGlobalUpdateDto>) -> Result<(), Error<SaveGlobalSettingError>> {
225    // add a prefix to parameters to efficiently prevent name collisions
226    let p_body_request_body = request_body;
227
228    let uri_str = format!("{}/api/v1/client-settings/global", configuration.base_path);
229    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
230
231    if let Some(ref user_agent) = configuration.user_agent {
232        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233    }
234    if let Some(ref apikey) = configuration.api_key {
235        let key = apikey.key.clone();
236        let value = match apikey.prefix {
237            Some(ref prefix) => format!("{} {}", prefix, key),
238            None => key,
239        };
240        req_builder = req_builder.header("X-API-Key", value);
241    };
242    if let Some(ref auth_conf) = configuration.basic_auth {
243        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
244    };
245    req_builder = req_builder.json(&p_body_request_body);
246
247    let req = req_builder.build()?;
248    let resp = configuration.client.execute(req).await?;
249
250    let status = resp.status();
251
252    if !status.is_client_error() && !status.is_server_error() {
253        Ok(())
254    } else {
255        let content = resp.text().await?;
256        let entity: Option<SaveGlobalSettingError> = serde_json::from_str(&content).ok();
257        Err(Error::ResponseError(ResponseContent { status, content, entity }))
258    }
259}
260
261/// Setting key should be a valid lowercase namespace string like 'application.domain.key'
262pub async fn save_user_setting(configuration: &configuration::Configuration, request_body: std::collections::HashMap<String, models::ClientSettingUserUpdateDto>) -> Result<(), Error<SaveUserSettingError>> {
263    // add a prefix to parameters to efficiently prevent name collisions
264    let p_body_request_body = request_body;
265
266    let uri_str = format!("{}/api/v1/client-settings/user", configuration.base_path);
267    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
268
269    if let Some(ref user_agent) = configuration.user_agent {
270        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
271    }
272    if let Some(ref apikey) = configuration.api_key {
273        let key = apikey.key.clone();
274        let value = match apikey.prefix {
275            Some(ref prefix) => format!("{} {}", prefix, key),
276            None => key,
277        };
278        req_builder = req_builder.header("X-API-Key", value);
279    };
280    if let Some(ref auth_conf) = configuration.basic_auth {
281        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
282    };
283    req_builder = req_builder.json(&p_body_request_body);
284
285    let req = req_builder.build()?;
286    let resp = configuration.client.execute(req).await?;
287
288    let status = resp.status();
289
290    if !status.is_client_error() && !status.is_server_error() {
291        Ok(())
292    } else {
293        let content = resp.text().await?;
294        let entity: Option<SaveUserSettingError> = serde_json::from_str(&content).ok();
295        Err(Error::ResponseError(ResponseContent { status, content, entity }))
296    }
297}
298