Skip to main content

komga_sdk/apis/
readlists_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 [`create_read_list`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateReadListError {
22    Status400(models::ValidationErrorResponse),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_read_list_by_id`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteReadListByIdError {
30    Status400(models::ValidationErrorResponse),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`download_read_list_as_zip`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum DownloadReadListAsZipError {
38    Status400(models::ValidationErrorResponse),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_read_list_by_id`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetReadListByIdError {
46    Status400(models::ValidationErrorResponse),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`get_read_lists`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetReadListsError {
54    Status400(models::ValidationErrorResponse),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`update_read_list_by_id`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum UpdateReadListByIdError {
62    Status400(models::ValidationErrorResponse),
63    UnknownValue(serde_json::Value),
64}
65
66
67/// Required role: **ADMIN**
68pub async fn create_read_list(configuration: &configuration::Configuration, read_list_creation_dto: models::ReadListCreationDto) -> Result<models::ReadListDto, Error<CreateReadListError>> {
69    // add a prefix to parameters to efficiently prevent name collisions
70    let p_body_read_list_creation_dto = read_list_creation_dto;
71
72    let uri_str = format!("{}/api/v1/readlists", configuration.base_path);
73    let mut req_builder = configuration.client.request(reqwest::Method::POST, &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_read_list_creation_dto);
90
91    let req = req_builder.build()?;
92    let resp = configuration.client.execute(req).await?;
93
94    let status = resp.status();
95    let content_type = resp
96        .headers()
97        .get("content-type")
98        .and_then(|v| v.to_str().ok())
99        .unwrap_or("application/octet-stream");
100    let content_type = super::ContentType::from(content_type);
101
102    if !status.is_client_error() && !status.is_server_error() {
103        let content = resp.text().await?;
104        match content_type {
105            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
106            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReadListDto`"))),
107            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::ReadListDto`")))),
108        }
109    } else {
110        let content = resp.text().await?;
111        let entity: Option<CreateReadListError> = serde_json::from_str(&content).ok();
112        Err(Error::ResponseError(ResponseContent { status, content, entity }))
113    }
114}
115
116/// Required role: **ADMIN**
117pub async fn delete_read_list_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteReadListByIdError>> {
118    // add a prefix to parameters to efficiently prevent name collisions
119    let p_path_id = id;
120
121    let uri_str = format!("{}/api/v1/readlists/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
122    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
123
124    if let Some(ref user_agent) = configuration.user_agent {
125        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
126    }
127    if let Some(ref apikey) = configuration.api_key {
128        let key = apikey.key.clone();
129        let value = match apikey.prefix {
130            Some(ref prefix) => format!("{} {}", prefix, key),
131            None => key,
132        };
133        req_builder = req_builder.header("X-API-Key", value);
134    };
135    if let Some(ref auth_conf) = configuration.basic_auth {
136        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
137    };
138
139    let req = req_builder.build()?;
140    let resp = configuration.client.execute(req).await?;
141
142    let status = resp.status();
143
144    if !status.is_client_error() && !status.is_server_error() {
145        Ok(())
146    } else {
147        let content = resp.text().await?;
148        let entity: Option<DeleteReadListByIdError> = serde_json::from_str(&content).ok();
149        Err(Error::ResponseError(ResponseContent { status, content, entity }))
150    }
151}
152
153/// Download the whole readlist as a ZIP file.  Required role: **FILE_DOWNLOAD**
154pub async fn download_read_list_as_zip(configuration: &configuration::Configuration, id: &str) -> Result<serde_json::Value, Error<DownloadReadListAsZipError>> {
155    // add a prefix to parameters to efficiently prevent name collisions
156    let p_path_id = id;
157
158    let uri_str = format!("{}/api/v1/readlists/{id}/file", configuration.base_path, id=crate::apis::urlencode(p_path_id));
159    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
160
161    if let Some(ref user_agent) = configuration.user_agent {
162        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
163    }
164    if let Some(ref apikey) = configuration.api_key {
165        let key = apikey.key.clone();
166        let value = match apikey.prefix {
167            Some(ref prefix) => format!("{} {}", prefix, key),
168            None => key,
169        };
170        req_builder = req_builder.header("X-API-Key", value);
171    };
172    if let Some(ref auth_conf) = configuration.basic_auth {
173        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
174    };
175
176    let req = req_builder.build()?;
177    let resp = configuration.client.execute(req).await?;
178
179    let status = resp.status();
180    let content_type = resp
181        .headers()
182        .get("content-type")
183        .and_then(|v| v.to_str().ok())
184        .unwrap_or("application/octet-stream");
185    let content_type = super::ContentType::from(content_type);
186
187    if !status.is_client_error() && !status.is_server_error() {
188        let content = resp.text().await?;
189        match content_type {
190            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
191            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
192            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
193        }
194    } else {
195        let content = resp.text().await?;
196        let entity: Option<DownloadReadListAsZipError> = serde_json::from_str(&content).ok();
197        Err(Error::ResponseError(ResponseContent { status, content, entity }))
198    }
199}
200
201pub async fn get_read_list_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::ReadListDto, Error<GetReadListByIdError>> {
202    // add a prefix to parameters to efficiently prevent name collisions
203    let p_path_id = id;
204
205    let uri_str = format!("{}/api/v1/readlists/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
206    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
207
208    if let Some(ref user_agent) = configuration.user_agent {
209        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
210    }
211    if let Some(ref apikey) = configuration.api_key {
212        let key = apikey.key.clone();
213        let value = match apikey.prefix {
214            Some(ref prefix) => format!("{} {}", prefix, key),
215            None => key,
216        };
217        req_builder = req_builder.header("X-API-Key", value);
218    };
219    if let Some(ref auth_conf) = configuration.basic_auth {
220        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
221    };
222
223    let req = req_builder.build()?;
224    let resp = configuration.client.execute(req).await?;
225
226    let status = resp.status();
227    let content_type = resp
228        .headers()
229        .get("content-type")
230        .and_then(|v| v.to_str().ok())
231        .unwrap_or("application/octet-stream");
232    let content_type = super::ContentType::from(content_type);
233
234    if !status.is_client_error() && !status.is_server_error() {
235        let content = resp.text().await?;
236        match content_type {
237            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
238            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ReadListDto`"))),
239            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::ReadListDto`")))),
240        }
241    } else {
242        let content = resp.text().await?;
243        let entity: Option<GetReadListByIdError> = serde_json::from_str(&content).ok();
244        Err(Error::ResponseError(ResponseContent { status, content, entity }))
245    }
246}
247
248pub async fn get_read_lists(configuration: &configuration::Configuration, search: Option<&str>, library_id: Option<Vec<String>>, unpaged: Option<bool>, page: Option<i32>, size: Option<i32>) -> Result<models::PageReadListDto, Error<GetReadListsError>> {
249    // add a prefix to parameters to efficiently prevent name collisions
250    let p_query_search = search;
251    let p_query_library_id = library_id;
252    let p_query_unpaged = unpaged;
253    let p_query_page = page;
254    let p_query_size = size;
255
256    let uri_str = format!("{}/api/v1/readlists", configuration.base_path);
257    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
258
259    if let Some(ref param_value) = p_query_search {
260        req_builder = req_builder.query(&[("search", &param_value.to_string())]);
261    }
262    if let Some(ref param_value) = p_query_library_id {
263        req_builder = match "multi" {
264            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("library_id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
265            _ => req_builder.query(&[("library_id", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
266        };
267    }
268    if let Some(ref param_value) = p_query_unpaged {
269        req_builder = req_builder.query(&[("unpaged", &param_value.to_string())]);
270    }
271    if let Some(ref param_value) = p_query_page {
272        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
273    }
274    if let Some(ref param_value) = p_query_size {
275        req_builder = req_builder.query(&[("size", &param_value.to_string())]);
276    }
277    if let Some(ref user_agent) = configuration.user_agent {
278        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
279    }
280    if let Some(ref apikey) = configuration.api_key {
281        let key = apikey.key.clone();
282        let value = match apikey.prefix {
283            Some(ref prefix) => format!("{} {}", prefix, key),
284            None => key,
285        };
286        req_builder = req_builder.header("X-API-Key", value);
287    };
288    if let Some(ref auth_conf) = configuration.basic_auth {
289        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
290    };
291
292    let req = req_builder.build()?;
293    let resp = configuration.client.execute(req).await?;
294
295    let status = resp.status();
296    let content_type = resp
297        .headers()
298        .get("content-type")
299        .and_then(|v| v.to_str().ok())
300        .unwrap_or("application/octet-stream");
301    let content_type = super::ContentType::from(content_type);
302
303    if !status.is_client_error() && !status.is_server_error() {
304        let content = resp.text().await?;
305        match content_type {
306            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
307            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PageReadListDto`"))),
308            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::PageReadListDto`")))),
309        }
310    } else {
311        let content = resp.text().await?;
312        let entity: Option<GetReadListsError> = serde_json::from_str(&content).ok();
313        Err(Error::ResponseError(ResponseContent { status, content, entity }))
314    }
315}
316
317/// Required role: **ADMIN**
318pub async fn update_read_list_by_id(configuration: &configuration::Configuration, id: &str, read_list_update_dto: models::ReadListUpdateDto) -> Result<(), Error<UpdateReadListByIdError>> {
319    // add a prefix to parameters to efficiently prevent name collisions
320    let p_path_id = id;
321    let p_body_read_list_update_dto = read_list_update_dto;
322
323    let uri_str = format!("{}/api/v1/readlists/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
324    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
325
326    if let Some(ref user_agent) = configuration.user_agent {
327        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
328    }
329    if let Some(ref apikey) = configuration.api_key {
330        let key = apikey.key.clone();
331        let value = match apikey.prefix {
332            Some(ref prefix) => format!("{} {}", prefix, key),
333            None => key,
334        };
335        req_builder = req_builder.header("X-API-Key", value);
336    };
337    if let Some(ref auth_conf) = configuration.basic_auth {
338        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
339    };
340    req_builder = req_builder.json(&p_body_read_list_update_dto);
341
342    let req = req_builder.build()?;
343    let resp = configuration.client.execute(req).await?;
344
345    let status = resp.status();
346
347    if !status.is_client_error() && !status.is_server_error() {
348        Ok(())
349    } else {
350        let content = resp.text().await?;
351        let entity: Option<UpdateReadListByIdError> = serde_json::from_str(&content).ok();
352        Err(Error::ResponseError(ResponseContent { status, content, entity }))
353    }
354}
355