Skip to main content

komga_sdk/apis/
users_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 [`add_user`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddUserError {
22    Status400(models::ValidationErrorResponse),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_user_by_id`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteUserByIdError {
30    Status400(models::ValidationErrorResponse),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_authentication_activity`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetAuthenticationActivityError {
38    Status400(models::ValidationErrorResponse),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_latest_authentication_activity_by_user_id`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetLatestAuthenticationActivityByUserIdError {
46    Status400(models::ValidationErrorResponse),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`get_users`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetUsersError {
54    Status400(models::ValidationErrorResponse),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`update_password_by_user_id`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum UpdatePasswordByUserIdError {
62    Status400(models::ValidationErrorResponse),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`update_user_by_id`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum UpdateUserByIdError {
70    Status400(models::ValidationErrorResponse),
71    UnknownValue(serde_json::Value),
72}
73
74
75/// Required role: **ADMIN**
76pub async fn add_user(configuration: &configuration::Configuration, user_creation_dto: models::UserCreationDto) -> Result<models::UserDto, Error<AddUserError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_body_user_creation_dto = user_creation_dto;
79
80    let uri_str = format!("{}/api/v2/users", configuration.base_path);
81    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
82
83    if let Some(ref user_agent) = configuration.user_agent {
84        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85    }
86    if let Some(ref apikey) = configuration.api_key {
87        let key = apikey.key.clone();
88        let value = match apikey.prefix {
89            Some(ref prefix) => format!("{} {}", prefix, key),
90            None => key,
91        };
92        req_builder = req_builder.header("X-API-Key", value);
93    };
94    if let Some(ref auth_conf) = configuration.basic_auth {
95        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
96    };
97    req_builder = req_builder.json(&p_body_user_creation_dto);
98
99    let req = req_builder.build()?;
100    let resp = configuration.client.execute(req).await?;
101
102    let status = resp.status();
103    let content_type = resp
104        .headers()
105        .get("content-type")
106        .and_then(|v| v.to_str().ok())
107        .unwrap_or("application/octet-stream");
108    let content_type = super::ContentType::from(content_type);
109
110    if !status.is_client_error() && !status.is_server_error() {
111        let content = resp.text().await?;
112        match content_type {
113            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
114            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserDto`"))),
115            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::UserDto`")))),
116        }
117    } else {
118        let content = resp.text().await?;
119        let entity: Option<AddUserError> = serde_json::from_str(&content).ok();
120        Err(Error::ResponseError(ResponseContent { status, content, entity }))
121    }
122}
123
124/// Required role: **ADMIN**
125pub async fn delete_user_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteUserByIdError>> {
126    // add a prefix to parameters to efficiently prevent name collisions
127    let p_path_id = id;
128
129    let uri_str = format!("{}/api/v2/users/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
130    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
131
132    if let Some(ref user_agent) = configuration.user_agent {
133        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134    }
135    if let Some(ref apikey) = configuration.api_key {
136        let key = apikey.key.clone();
137        let value = match apikey.prefix {
138            Some(ref prefix) => format!("{} {}", prefix, key),
139            None => key,
140        };
141        req_builder = req_builder.header("X-API-Key", value);
142    };
143    if let Some(ref auth_conf) = configuration.basic_auth {
144        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
145    };
146
147    let req = req_builder.build()?;
148    let resp = configuration.client.execute(req).await?;
149
150    let status = resp.status();
151
152    if !status.is_client_error() && !status.is_server_error() {
153        Ok(())
154    } else {
155        let content = resp.text().await?;
156        let entity: Option<DeleteUserByIdError> = serde_json::from_str(&content).ok();
157        Err(Error::ResponseError(ResponseContent { status, content, entity }))
158    }
159}
160
161/// Required role: **ADMIN**
162pub async fn get_authentication_activity(configuration: &configuration::Configuration, unpaged: Option<bool>, page: Option<i32>, size: Option<i32>, sort: Option<Vec<String>>) -> Result<models::PageAuthenticationActivityDto, Error<GetAuthenticationActivityError>> {
163    // add a prefix to parameters to efficiently prevent name collisions
164    let p_query_unpaged = unpaged;
165    let p_query_page = page;
166    let p_query_size = size;
167    let p_query_sort = sort;
168
169    let uri_str = format!("{}/api/v2/users/authentication-activity", configuration.base_path);
170    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
171
172    if let Some(ref param_value) = p_query_unpaged {
173        req_builder = req_builder.query(&[("unpaged", &param_value.to_string())]);
174    }
175    if let Some(ref param_value) = p_query_page {
176        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
177    }
178    if let Some(ref param_value) = p_query_size {
179        req_builder = req_builder.query(&[("size", &param_value.to_string())]);
180    }
181    if let Some(ref param_value) = p_query_sort {
182        req_builder = match "multi" {
183            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("sort".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
184            _ => req_builder.query(&[("sort", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
185        };
186    }
187    if let Some(ref user_agent) = configuration.user_agent {
188        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189    }
190    if let Some(ref apikey) = configuration.api_key {
191        let key = apikey.key.clone();
192        let value = match apikey.prefix {
193            Some(ref prefix) => format!("{} {}", prefix, key),
194            None => key,
195        };
196        req_builder = req_builder.header("X-API-Key", value);
197    };
198    if let Some(ref auth_conf) = configuration.basic_auth {
199        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
200    };
201
202    let req = req_builder.build()?;
203    let resp = configuration.client.execute(req).await?;
204
205    let status = resp.status();
206    let content_type = resp
207        .headers()
208        .get("content-type")
209        .and_then(|v| v.to_str().ok())
210        .unwrap_or("application/octet-stream");
211    let content_type = super::ContentType::from(content_type);
212
213    if !status.is_client_error() && !status.is_server_error() {
214        let content = resp.text().await?;
215        match content_type {
216            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
217            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PageAuthenticationActivityDto`"))),
218            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::PageAuthenticationActivityDto`")))),
219        }
220    } else {
221        let content = resp.text().await?;
222        let entity: Option<GetAuthenticationActivityError> = serde_json::from_str(&content).ok();
223        Err(Error::ResponseError(ResponseContent { status, content, entity }))
224    }
225}
226
227/// Required role: **ADMIN**
228pub async fn get_latest_authentication_activity_by_user_id(configuration: &configuration::Configuration, id: &str, apikey_id: Option<&str>) -> Result<models::AuthenticationActivityDto, Error<GetLatestAuthenticationActivityByUserIdError>> {
229    // add a prefix to parameters to efficiently prevent name collisions
230    let p_path_id = id;
231    let p_query_apikey_id = apikey_id;
232
233    let uri_str = format!("{}/api/v2/users/{id}/authentication-activity/latest", configuration.base_path, id=crate::apis::urlencode(p_path_id));
234    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
235
236    if let Some(ref param_value) = p_query_apikey_id {
237        req_builder = req_builder.query(&[("apikey_id", &param_value.to_string())]);
238    }
239    if let Some(ref user_agent) = configuration.user_agent {
240        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
241    }
242    if let Some(ref apikey) = configuration.api_key {
243        let key = apikey.key.clone();
244        let value = match apikey.prefix {
245            Some(ref prefix) => format!("{} {}", prefix, key),
246            None => key,
247        };
248        req_builder = req_builder.header("X-API-Key", value);
249    };
250    if let Some(ref auth_conf) = configuration.basic_auth {
251        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
252    };
253
254    let req = req_builder.build()?;
255    let resp = configuration.client.execute(req).await?;
256
257    let status = resp.status();
258    let content_type = resp
259        .headers()
260        .get("content-type")
261        .and_then(|v| v.to_str().ok())
262        .unwrap_or("application/octet-stream");
263    let content_type = super::ContentType::from(content_type);
264
265    if !status.is_client_error() && !status.is_server_error() {
266        let content = resp.text().await?;
267        match content_type {
268            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
269            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AuthenticationActivityDto`"))),
270            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::AuthenticationActivityDto`")))),
271        }
272    } else {
273        let content = resp.text().await?;
274        let entity: Option<GetLatestAuthenticationActivityByUserIdError> = serde_json::from_str(&content).ok();
275        Err(Error::ResponseError(ResponseContent { status, content, entity }))
276    }
277}
278
279/// Required role: **ADMIN**
280pub async fn get_users(configuration: &configuration::Configuration, ) -> Result<Vec<models::UserDto>, Error<GetUsersError>> {
281
282    let uri_str = format!("{}/api/v2/users", configuration.base_path);
283    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
284
285    if let Some(ref user_agent) = configuration.user_agent {
286        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
287    }
288    if let Some(ref apikey) = configuration.api_key {
289        let key = apikey.key.clone();
290        let value = match apikey.prefix {
291            Some(ref prefix) => format!("{} {}", prefix, key),
292            None => key,
293        };
294        req_builder = req_builder.header("X-API-Key", value);
295    };
296    if let Some(ref auth_conf) = configuration.basic_auth {
297        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
298    };
299
300    let req = req_builder.build()?;
301    let resp = configuration.client.execute(req).await?;
302
303    let status = resp.status();
304    let content_type = resp
305        .headers()
306        .get("content-type")
307        .and_then(|v| v.to_str().ok())
308        .unwrap_or("application/octet-stream");
309    let content_type = super::ContentType::from(content_type);
310
311    if !status.is_client_error() && !status.is_server_error() {
312        let content = resp.text().await?;
313        match content_type {
314            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
315            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::UserDto&gt;`"))),
316            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::UserDto&gt;`")))),
317        }
318    } else {
319        let content = resp.text().await?;
320        let entity: Option<GetUsersError> = serde_json::from_str(&content).ok();
321        Err(Error::ResponseError(ResponseContent { status, content, entity }))
322    }
323}
324
325/// Required role: **ADMIN**
326pub async fn update_password_by_user_id(configuration: &configuration::Configuration, id: &str, password_update_dto: models::PasswordUpdateDto) -> Result<(), Error<UpdatePasswordByUserIdError>> {
327    // add a prefix to parameters to efficiently prevent name collisions
328    let p_path_id = id;
329    let p_body_password_update_dto = password_update_dto;
330
331    let uri_str = format!("{}/api/v2/users/{id}/password", configuration.base_path, id=crate::apis::urlencode(p_path_id));
332    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
333
334    if let Some(ref user_agent) = configuration.user_agent {
335        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
336    }
337    if let Some(ref apikey) = configuration.api_key {
338        let key = apikey.key.clone();
339        let value = match apikey.prefix {
340            Some(ref prefix) => format!("{} {}", prefix, key),
341            None => key,
342        };
343        req_builder = req_builder.header("X-API-Key", value);
344    };
345    if let Some(ref auth_conf) = configuration.basic_auth {
346        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
347    };
348    req_builder = req_builder.json(&p_body_password_update_dto);
349
350    let req = req_builder.build()?;
351    let resp = configuration.client.execute(req).await?;
352
353    let status = resp.status();
354
355    if !status.is_client_error() && !status.is_server_error() {
356        Ok(())
357    } else {
358        let content = resp.text().await?;
359        let entity: Option<UpdatePasswordByUserIdError> = serde_json::from_str(&content).ok();
360        Err(Error::ResponseError(ResponseContent { status, content, entity }))
361    }
362}
363
364/// Required role: **ADMIN**
365pub async fn update_user_by_id(configuration: &configuration::Configuration, id: &str, user_update_dto: models::UserUpdateDto) -> Result<(), Error<UpdateUserByIdError>> {
366    // add a prefix to parameters to efficiently prevent name collisions
367    let p_path_id = id;
368    let p_body_user_update_dto = user_update_dto;
369
370    let uri_str = format!("{}/api/v2/users/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
371    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
372
373    if let Some(ref user_agent) = configuration.user_agent {
374        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
375    }
376    if let Some(ref apikey) = configuration.api_key {
377        let key = apikey.key.clone();
378        let value = match apikey.prefix {
379            Some(ref prefix) => format!("{} {}", prefix, key),
380            None => key,
381        };
382        req_builder = req_builder.header("X-API-Key", value);
383    };
384    if let Some(ref auth_conf) = configuration.basic_auth {
385        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
386    };
387    req_builder = req_builder.json(&p_body_user_update_dto);
388
389    let req = req_builder.build()?;
390    let resp = configuration.client.execute(req).await?;
391
392    let status = resp.status();
393
394    if !status.is_client_error() && !status.is_server_error() {
395        Ok(())
396    } else {
397        let content = resp.text().await?;
398        let entity: Option<UpdateUserByIdError> = serde_json::from_str(&content).ok();
399        Err(Error::ResponseError(ResponseContent { status, content, entity }))
400    }
401}
402