Skip to main content

komga_sdk/apis/
libraries_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_library`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddLibraryError {
22    Status400(models::ValidationErrorResponse),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_library_by_id`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteLibraryByIdError {
30    Status400(models::ValidationErrorResponse),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_libraries`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetLibrariesError {
38    Status400(models::ValidationErrorResponse),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_library_by_id`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetLibraryByIdError {
46    Status400(models::ValidationErrorResponse),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`library_analyze`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum LibraryAnalyzeError {
54    Status400(models::ValidationErrorResponse),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`library_empty_trash`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum LibraryEmptyTrashError {
62    Status400(models::ValidationErrorResponse),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`library_refresh_metadata`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum LibraryRefreshMetadataError {
70    Status400(models::ValidationErrorResponse),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`library_scan`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum LibraryScanError {
78    Status400(models::ValidationErrorResponse),
79    UnknownValue(serde_json::Value),
80}
81
82/// struct for typed errors of method [`update_library_by_id`]
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum UpdateLibraryByIdError {
86    Status400(models::ValidationErrorResponse),
87    UnknownValue(serde_json::Value),
88}
89
90/// struct for typed errors of method [`update_library_by_id_deprecated`]
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum UpdateLibraryByIdDeprecatedError {
94    Status400(models::ValidationErrorResponse),
95    UnknownValue(serde_json::Value),
96}
97
98
99/// Required role: **ADMIN**
100pub async fn add_library(configuration: &configuration::Configuration, library_creation_dto: models::LibraryCreationDto) -> Result<models::LibraryDto, Error<AddLibraryError>> {
101    // add a prefix to parameters to efficiently prevent name collisions
102    let p_body_library_creation_dto = library_creation_dto;
103
104    let uri_str = format!("{}/api/v1/libraries", configuration.base_path);
105    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
106
107    if let Some(ref user_agent) = configuration.user_agent {
108        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
109    }
110    if let Some(ref apikey) = configuration.api_key {
111        let key = apikey.key.clone();
112        let value = match apikey.prefix {
113            Some(ref prefix) => format!("{} {}", prefix, key),
114            None => key,
115        };
116        req_builder = req_builder.header("X-API-Key", value);
117    };
118    if let Some(ref auth_conf) = configuration.basic_auth {
119        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
120    };
121    req_builder = req_builder.json(&p_body_library_creation_dto);
122
123    let req = req_builder.build()?;
124    let resp = configuration.client.execute(req).await?;
125
126    let status = resp.status();
127    let content_type = resp
128        .headers()
129        .get("content-type")
130        .and_then(|v| v.to_str().ok())
131        .unwrap_or("application/octet-stream");
132    let content_type = super::ContentType::from(content_type);
133
134    if !status.is_client_error() && !status.is_server_error() {
135        let content = resp.text().await?;
136        match content_type {
137            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
138            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LibraryDto`"))),
139            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::LibraryDto`")))),
140        }
141    } else {
142        let content = resp.text().await?;
143        let entity: Option<AddLibraryError> = serde_json::from_str(&content).ok();
144        Err(Error::ResponseError(ResponseContent { status, content, entity }))
145    }
146}
147
148/// Required role: **ADMIN**
149pub async fn delete_library_by_id(configuration: &configuration::Configuration, library_id: &str) -> Result<(), Error<DeleteLibraryByIdError>> {
150    // add a prefix to parameters to efficiently prevent name collisions
151    let p_path_library_id = library_id;
152
153    let uri_str = format!("{}/api/v1/libraries/{libraryId}", configuration.base_path, libraryId=crate::apis::urlencode(p_path_library_id));
154    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
155
156    if let Some(ref user_agent) = configuration.user_agent {
157        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
158    }
159    if let Some(ref apikey) = configuration.api_key {
160        let key = apikey.key.clone();
161        let value = match apikey.prefix {
162            Some(ref prefix) => format!("{} {}", prefix, key),
163            None => key,
164        };
165        req_builder = req_builder.header("X-API-Key", value);
166    };
167    if let Some(ref auth_conf) = configuration.basic_auth {
168        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
169    };
170
171    let req = req_builder.build()?;
172    let resp = configuration.client.execute(req).await?;
173
174    let status = resp.status();
175
176    if !status.is_client_error() && !status.is_server_error() {
177        Ok(())
178    } else {
179        let content = resp.text().await?;
180        let entity: Option<DeleteLibraryByIdError> = serde_json::from_str(&content).ok();
181        Err(Error::ResponseError(ResponseContent { status, content, entity }))
182    }
183}
184
185/// The libraries are filtered based on the current user's permissions
186pub async fn get_libraries(configuration: &configuration::Configuration, ) -> Result<Vec<models::LibraryDto>, Error<GetLibrariesError>> {
187
188    let uri_str = format!("{}/api/v1/libraries", configuration.base_path);
189    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
190
191    if let Some(ref user_agent) = configuration.user_agent {
192        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
193    }
194    if let Some(ref apikey) = configuration.api_key {
195        let key = apikey.key.clone();
196        let value = match apikey.prefix {
197            Some(ref prefix) => format!("{} {}", prefix, key),
198            None => key,
199        };
200        req_builder = req_builder.header("X-API-Key", value);
201    };
202    if let Some(ref auth_conf) = configuration.basic_auth {
203        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
204    };
205
206    let req = req_builder.build()?;
207    let resp = configuration.client.execute(req).await?;
208
209    let status = resp.status();
210    let content_type = resp
211        .headers()
212        .get("content-type")
213        .and_then(|v| v.to_str().ok())
214        .unwrap_or("application/octet-stream");
215    let content_type = super::ContentType::from(content_type);
216
217    if !status.is_client_error() && !status.is_server_error() {
218        let content = resp.text().await?;
219        match content_type {
220            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
221            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::LibraryDto&gt;`"))),
222            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::LibraryDto&gt;`")))),
223        }
224    } else {
225        let content = resp.text().await?;
226        let entity: Option<GetLibrariesError> = serde_json::from_str(&content).ok();
227        Err(Error::ResponseError(ResponseContent { status, content, entity }))
228    }
229}
230
231pub async fn get_library_by_id(configuration: &configuration::Configuration, library_id: &str) -> Result<models::LibraryDto, Error<GetLibraryByIdError>> {
232    // add a prefix to parameters to efficiently prevent name collisions
233    let p_path_library_id = library_id;
234
235    let uri_str = format!("{}/api/v1/libraries/{libraryId}", configuration.base_path, libraryId=crate::apis::urlencode(p_path_library_id));
236    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
237
238    if let Some(ref user_agent) = configuration.user_agent {
239        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
240    }
241    if let Some(ref apikey) = configuration.api_key {
242        let key = apikey.key.clone();
243        let value = match apikey.prefix {
244            Some(ref prefix) => format!("{} {}", prefix, key),
245            None => key,
246        };
247        req_builder = req_builder.header("X-API-Key", value);
248    };
249    if let Some(ref auth_conf) = configuration.basic_auth {
250        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
251    };
252
253    let req = req_builder.build()?;
254    let resp = configuration.client.execute(req).await?;
255
256    let status = resp.status();
257    let content_type = resp
258        .headers()
259        .get("content-type")
260        .and_then(|v| v.to_str().ok())
261        .unwrap_or("application/octet-stream");
262    let content_type = super::ContentType::from(content_type);
263
264    if !status.is_client_error() && !status.is_server_error() {
265        let content = resp.text().await?;
266        match content_type {
267            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
268            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::LibraryDto`"))),
269            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::LibraryDto`")))),
270        }
271    } else {
272        let content = resp.text().await?;
273        let entity: Option<GetLibraryByIdError> = serde_json::from_str(&content).ok();
274        Err(Error::ResponseError(ResponseContent { status, content, entity }))
275    }
276}
277
278/// Required role: **ADMIN**
279pub async fn library_analyze(configuration: &configuration::Configuration, library_id: &str) -> Result<(), Error<LibraryAnalyzeError>> {
280    // add a prefix to parameters to efficiently prevent name collisions
281    let p_path_library_id = library_id;
282
283    let uri_str = format!("{}/api/v1/libraries/{libraryId}/analyze", configuration.base_path, libraryId=crate::apis::urlencode(p_path_library_id));
284    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
285
286    if let Some(ref user_agent) = configuration.user_agent {
287        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
288    }
289    if let Some(ref apikey) = configuration.api_key {
290        let key = apikey.key.clone();
291        let value = match apikey.prefix {
292            Some(ref prefix) => format!("{} {}", prefix, key),
293            None => key,
294        };
295        req_builder = req_builder.header("X-API-Key", value);
296    };
297    if let Some(ref auth_conf) = configuration.basic_auth {
298        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
299    };
300
301    let req = req_builder.build()?;
302    let resp = configuration.client.execute(req).await?;
303
304    let status = resp.status();
305
306    if !status.is_client_error() && !status.is_server_error() {
307        Ok(())
308    } else {
309        let content = resp.text().await?;
310        let entity: Option<LibraryAnalyzeError> = serde_json::from_str(&content).ok();
311        Err(Error::ResponseError(ResponseContent { status, content, entity }))
312    }
313}
314
315/// Required role: **ADMIN**
316pub async fn library_empty_trash(configuration: &configuration::Configuration, library_id: &str) -> Result<(), Error<LibraryEmptyTrashError>> {
317    // add a prefix to parameters to efficiently prevent name collisions
318    let p_path_library_id = library_id;
319
320    let uri_str = format!("{}/api/v1/libraries/{libraryId}/empty-trash", configuration.base_path, libraryId=crate::apis::urlencode(p_path_library_id));
321    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
322
323    if let Some(ref user_agent) = configuration.user_agent {
324        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
325    }
326    if let Some(ref apikey) = configuration.api_key {
327        let key = apikey.key.clone();
328        let value = match apikey.prefix {
329            Some(ref prefix) => format!("{} {}", prefix, key),
330            None => key,
331        };
332        req_builder = req_builder.header("X-API-Key", value);
333    };
334    if let Some(ref auth_conf) = configuration.basic_auth {
335        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
336    };
337
338    let req = req_builder.build()?;
339    let resp = configuration.client.execute(req).await?;
340
341    let status = resp.status();
342
343    if !status.is_client_error() && !status.is_server_error() {
344        Ok(())
345    } else {
346        let content = resp.text().await?;
347        let entity: Option<LibraryEmptyTrashError> = serde_json::from_str(&content).ok();
348        Err(Error::ResponseError(ResponseContent { status, content, entity }))
349    }
350}
351
352/// Required role: **ADMIN**
353pub async fn library_refresh_metadata(configuration: &configuration::Configuration, library_id: &str) -> Result<(), Error<LibraryRefreshMetadataError>> {
354    // add a prefix to parameters to efficiently prevent name collisions
355    let p_path_library_id = library_id;
356
357    let uri_str = format!("{}/api/v1/libraries/{libraryId}/metadata/refresh", configuration.base_path, libraryId=crate::apis::urlencode(p_path_library_id));
358    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
359
360    if let Some(ref user_agent) = configuration.user_agent {
361        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
362    }
363    if let Some(ref apikey) = configuration.api_key {
364        let key = apikey.key.clone();
365        let value = match apikey.prefix {
366            Some(ref prefix) => format!("{} {}", prefix, key),
367            None => key,
368        };
369        req_builder = req_builder.header("X-API-Key", value);
370    };
371    if let Some(ref auth_conf) = configuration.basic_auth {
372        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
373    };
374
375    let req = req_builder.build()?;
376    let resp = configuration.client.execute(req).await?;
377
378    let status = resp.status();
379
380    if !status.is_client_error() && !status.is_server_error() {
381        Ok(())
382    } else {
383        let content = resp.text().await?;
384        let entity: Option<LibraryRefreshMetadataError> = serde_json::from_str(&content).ok();
385        Err(Error::ResponseError(ResponseContent { status, content, entity }))
386    }
387}
388
389/// Required role: **ADMIN**
390pub async fn library_scan(configuration: &configuration::Configuration, library_id: &str, deep: Option<bool>) -> Result<(), Error<LibraryScanError>> {
391    // add a prefix to parameters to efficiently prevent name collisions
392    let p_path_library_id = library_id;
393    let p_query_deep = deep;
394
395    let uri_str = format!("{}/api/v1/libraries/{libraryId}/scan", configuration.base_path, libraryId=crate::apis::urlencode(p_path_library_id));
396    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
397
398    if let Some(ref param_value) = p_query_deep {
399        req_builder = req_builder.query(&[("deep", &param_value.to_string())]);
400    }
401    if let Some(ref user_agent) = configuration.user_agent {
402        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
403    }
404    if let Some(ref apikey) = configuration.api_key {
405        let key = apikey.key.clone();
406        let value = match apikey.prefix {
407            Some(ref prefix) => format!("{} {}", prefix, key),
408            None => key,
409        };
410        req_builder = req_builder.header("X-API-Key", value);
411    };
412    if let Some(ref auth_conf) = configuration.basic_auth {
413        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
414    };
415
416    let req = req_builder.build()?;
417    let resp = configuration.client.execute(req).await?;
418
419    let status = resp.status();
420
421    if !status.is_client_error() && !status.is_server_error() {
422        Ok(())
423    } else {
424        let content = resp.text().await?;
425        let entity: Option<LibraryScanError> = serde_json::from_str(&content).ok();
426        Err(Error::ResponseError(ResponseContent { status, content, entity }))
427    }
428}
429
430/// You can omit fields you don't want to update  Required role: **ADMIN**
431pub async fn update_library_by_id(configuration: &configuration::Configuration, library_id: &str, library_update_dto: models::LibraryUpdateDto) -> Result<(), Error<UpdateLibraryByIdError>> {
432    // add a prefix to parameters to efficiently prevent name collisions
433    let p_path_library_id = library_id;
434    let p_body_library_update_dto = library_update_dto;
435
436    let uri_str = format!("{}/api/v1/libraries/{libraryId}", configuration.base_path, libraryId=crate::apis::urlencode(p_path_library_id));
437    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
438
439    if let Some(ref user_agent) = configuration.user_agent {
440        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
441    }
442    if let Some(ref apikey) = configuration.api_key {
443        let key = apikey.key.clone();
444        let value = match apikey.prefix {
445            Some(ref prefix) => format!("{} {}", prefix, key),
446            None => key,
447        };
448        req_builder = req_builder.header("X-API-Key", value);
449    };
450    if let Some(ref auth_conf) = configuration.basic_auth {
451        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
452    };
453    req_builder = req_builder.json(&p_body_library_update_dto);
454
455    let req = req_builder.build()?;
456    let resp = configuration.client.execute(req).await?;
457
458    let status = resp.status();
459
460    if !status.is_client_error() && !status.is_server_error() {
461        Ok(())
462    } else {
463        let content = resp.text().await?;
464        let entity: Option<UpdateLibraryByIdError> = serde_json::from_str(&content).ok();
465        Err(Error::ResponseError(ResponseContent { status, content, entity }))
466    }
467}
468
469/// Use PATCH /api/v1/libraries/{libraryId} instead. Deprecated since 1.3.0.  Required role: **ADMIN**
470pub async fn update_library_by_id_deprecated(configuration: &configuration::Configuration, library_id: &str, library_update_dto: models::LibraryUpdateDto) -> Result<(), Error<UpdateLibraryByIdDeprecatedError>> {
471    // add a prefix to parameters to efficiently prevent name collisions
472    let p_path_library_id = library_id;
473    let p_body_library_update_dto = library_update_dto;
474
475    let uri_str = format!("{}/api/v1/libraries/{libraryId}", configuration.base_path, libraryId=crate::apis::urlencode(p_path_library_id));
476    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
477
478    if let Some(ref user_agent) = configuration.user_agent {
479        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
480    }
481    if let Some(ref apikey) = configuration.api_key {
482        let key = apikey.key.clone();
483        let value = match apikey.prefix {
484            Some(ref prefix) => format!("{} {}", prefix, key),
485            None => key,
486        };
487        req_builder = req_builder.header("X-API-Key", value);
488    };
489    if let Some(ref auth_conf) = configuration.basic_auth {
490        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
491    };
492    req_builder = req_builder.json(&p_body_library_update_dto);
493
494    let req = req_builder.build()?;
495    let resp = configuration.client.execute(req).await?;
496
497    let status = resp.status();
498
499    if !status.is_client_error() && !status.is_server_error() {
500        Ok(())
501    } else {
502        let content = resp.text().await?;
503        let entity: Option<UpdateLibraryByIdDeprecatedError> = serde_json::from_str(&content).ok();
504        Err(Error::ResponseError(ResponseContent { status, content, entity }))
505    }
506}
507