Skip to main content

komga_sdk/apis/
collection_poster_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
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`add_user_uploaded_collection_thumbnail`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AddUserUploadedCollectionThumbnailError {
20    Status400(models::ValidationErrorResponse),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`delete_user_uploaded_collection_thumbnail`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum DeleteUserUploadedCollectionThumbnailError {
28    Status400(models::ValidationErrorResponse),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_collection_thumbnail`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetCollectionThumbnailError {
36    Status400(models::ValidationErrorResponse),
37    DefaultResponse(std::path::PathBuf),
38    UnknownValue(serde_json::Value),
39}
40
41/// struct for typed errors of method [`get_collection_thumbnail_by_id`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum GetCollectionThumbnailByIdError {
45    Status400(models::ValidationErrorResponse),
46    DefaultResponse(std::path::PathBuf),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`get_collection_thumbnails`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetCollectionThumbnailsError {
54    Status400(models::ValidationErrorResponse),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`mark_collection_thumbnail_selected`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum MarkCollectionThumbnailSelectedError {
62    Status400(models::ValidationErrorResponse),
63    UnknownValue(serde_json::Value),
64}
65
66/// Required role: **ADMIN**
67pub async fn add_user_uploaded_collection_thumbnail(
68    configuration: &configuration::Configuration,
69    id: &str,
70    file: std::path::PathBuf,
71    selected: Option<bool>,
72) -> Result<models::ThumbnailSeriesCollectionDto, Error<AddUserUploadedCollectionThumbnailError>> {
73    // add a prefix to parameters to efficiently prevent name collisions
74    let p_path_id = id;
75    let p_form_file = file;
76    let p_query_selected = selected;
77
78    let uri_str = format!(
79        "{}/api/v1/collections/{id}/thumbnails",
80        configuration.base_path,
81        id = crate::apis::urlencode(p_path_id)
82    );
83    let mut req_builder = configuration
84        .client
85        .request(reqwest::Method::POST, &uri_str);
86
87    if let Some(ref param_value) = p_query_selected {
88        req_builder = req_builder.query(&[("selected", &param_value.to_string())]);
89    }
90    if let Some(ref user_agent) = configuration.user_agent {
91        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92    }
93    if let Some(ref apikey) = configuration.api_key {
94        let key = apikey.key.clone();
95        let value = match apikey.prefix {
96            Some(ref prefix) => format!("{} {}", prefix, key),
97            None => key,
98        };
99        req_builder = req_builder.header("X-API-Key", value);
100    };
101    if let Some(ref auth_conf) = configuration.basic_auth {
102        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
103    };
104    let mut multipart_form = reqwest::multipart::Form::new();
105    // Support file upload for 'file' parameter
106    let file_name = p_form_file
107        .file_name()
108        .and_then(|os_str| os_str.to_str())
109        .unwrap_or("thumbnail");
110    let file_bytes = tokio::fs::read(&p_form_file).await?;
111    let part = reqwest::multipart::Part::bytes(file_bytes).file_name(file_name.to_string());
112    multipart_form = multipart_form.part("file", part);
113    req_builder = req_builder.multipart(multipart_form);
114
115    let req = req_builder.build()?;
116    let resp = configuration.client.execute(req).await?;
117
118    let status = resp.status();
119    let content_type = resp
120        .headers()
121        .get("content-type")
122        .and_then(|v| v.to_str().ok())
123        .unwrap_or("application/octet-stream");
124    let content_type = super::ContentType::from(content_type);
125
126    if !status.is_client_error() && !status.is_server_error() {
127        let content = resp.text().await?;
128        match content_type {
129            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
130            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ThumbnailSeriesCollectionDto`"))),
131            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::ThumbnailSeriesCollectionDto`")))),
132        }
133    } else {
134        let content = resp.text().await?;
135        let entity: Option<AddUserUploadedCollectionThumbnailError> =
136            serde_json::from_str(&content).ok();
137        Err(Error::ResponseError(ResponseContent {
138            status,
139            content,
140            entity,
141        }))
142    }
143}
144
145/// Required role: **ADMIN**
146pub async fn delete_user_uploaded_collection_thumbnail(
147    configuration: &configuration::Configuration,
148    id: &str,
149    thumbnail_id: &str,
150) -> Result<(), Error<DeleteUserUploadedCollectionThumbnailError>> {
151    // add a prefix to parameters to efficiently prevent name collisions
152    let p_path_id = id;
153    let p_path_thumbnail_id = thumbnail_id;
154
155    let uri_str = format!(
156        "{}/api/v1/collections/{id}/thumbnails/{thumbnailId}",
157        configuration.base_path,
158        id = crate::apis::urlencode(p_path_id),
159        thumbnailId = crate::apis::urlencode(p_path_thumbnail_id)
160    );
161    let mut req_builder = configuration
162        .client
163        .request(reqwest::Method::DELETE, &uri_str);
164
165    if let Some(ref user_agent) = configuration.user_agent {
166        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
167    }
168    if let Some(ref apikey) = configuration.api_key {
169        let key = apikey.key.clone();
170        let value = match apikey.prefix {
171            Some(ref prefix) => format!("{} {}", prefix, key),
172            None => key,
173        };
174        req_builder = req_builder.header("X-API-Key", value);
175    };
176    if let Some(ref auth_conf) = configuration.basic_auth {
177        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
178    };
179
180    let req = req_builder.build()?;
181    let resp = configuration.client.execute(req).await?;
182
183    let status = resp.status();
184
185    if !status.is_client_error() && !status.is_server_error() {
186        Ok(())
187    } else {
188        let content = resp.text().await?;
189        let entity: Option<DeleteUserUploadedCollectionThumbnailError> =
190            serde_json::from_str(&content).ok();
191        Err(Error::ResponseError(ResponseContent {
192            status,
193            content,
194            entity,
195        }))
196    }
197}
198
199pub async fn get_collection_thumbnail(
200    configuration: &configuration::Configuration,
201    id: &str,
202) -> Result<std::path::PathBuf, Error<GetCollectionThumbnailError>> {
203    // add a prefix to parameters to efficiently prevent name collisions
204    let p_path_id = id;
205
206    let uri_str = format!(
207        "{}/api/v1/collections/{id}/thumbnail",
208        configuration.base_path,
209        id = crate::apis::urlencode(p_path_id)
210    );
211    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
212
213    if let Some(ref user_agent) = configuration.user_agent {
214        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
215    }
216    if let Some(ref apikey) = configuration.api_key {
217        let key = apikey.key.clone();
218        let value = match apikey.prefix {
219            Some(ref prefix) => format!("{} {}", prefix, key),
220            None => key,
221        };
222        req_builder = req_builder.header("X-API-Key", value);
223    };
224    if let Some(ref auth_conf) = configuration.basic_auth {
225        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
226    };
227
228    let req = req_builder.build()?;
229    let resp = configuration.client.execute(req).await?;
230
231    let status = resp.status();
232    let content_type = resp
233        .headers()
234        .get("content-type")
235        .and_then(|v| v.to_str().ok())
236        .unwrap_or("application/octet-stream");
237    let content_type = super::ContentType::from(content_type);
238
239    if !status.is_client_error() && !status.is_server_error() {
240        let content = resp.text().await?;
241        match content_type {
242            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
243            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::path::PathBuf`"))),
244            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::path::PathBuf`")))),
245        }
246    } else {
247        let content = resp.text().await?;
248        let entity: Option<GetCollectionThumbnailError> = serde_json::from_str(&content).ok();
249        Err(Error::ResponseError(ResponseContent {
250            status,
251            content,
252            entity,
253        }))
254    }
255}
256
257pub async fn get_collection_thumbnail_by_id(
258    configuration: &configuration::Configuration,
259    id: &str,
260    thumbnail_id: &str,
261) -> Result<std::path::PathBuf, Error<GetCollectionThumbnailByIdError>> {
262    // add a prefix to parameters to efficiently prevent name collisions
263    let p_path_id = id;
264    let p_path_thumbnail_id = thumbnail_id;
265
266    let uri_str = format!(
267        "{}/api/v1/collections/{id}/thumbnails/{thumbnailId}",
268        configuration.base_path,
269        id = crate::apis::urlencode(p_path_id),
270        thumbnailId = crate::apis::urlencode(p_path_thumbnail_id)
271    );
272    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
273
274    if let Some(ref user_agent) = configuration.user_agent {
275        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
276    }
277    if let Some(ref apikey) = configuration.api_key {
278        let key = apikey.key.clone();
279        let value = match apikey.prefix {
280            Some(ref prefix) => format!("{} {}", prefix, key),
281            None => key,
282        };
283        req_builder = req_builder.header("X-API-Key", value);
284    };
285    if let Some(ref auth_conf) = configuration.basic_auth {
286        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
287    };
288
289    let req = req_builder.build()?;
290    let resp = configuration.client.execute(req).await?;
291
292    let status = resp.status();
293    let content_type = resp
294        .headers()
295        .get("content-type")
296        .and_then(|v| v.to_str().ok())
297        .unwrap_or("application/octet-stream");
298    let content_type = super::ContentType::from(content_type);
299
300    if !status.is_client_error() && !status.is_server_error() {
301        let content = resp.text().await?;
302        match content_type {
303            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
304            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::path::PathBuf`"))),
305            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::path::PathBuf`")))),
306        }
307    } else {
308        let content = resp.text().await?;
309        let entity: Option<GetCollectionThumbnailByIdError> = serde_json::from_str(&content).ok();
310        Err(Error::ResponseError(ResponseContent {
311            status,
312            content,
313            entity,
314        }))
315    }
316}
317
318pub async fn get_collection_thumbnails(
319    configuration: &configuration::Configuration,
320    id: &str,
321) -> Result<Vec<models::ThumbnailSeriesCollectionDto>, Error<GetCollectionThumbnailsError>> {
322    // add a prefix to parameters to efficiently prevent name collisions
323    let p_path_id = id;
324
325    let uri_str = format!(
326        "{}/api/v1/collections/{id}/thumbnails",
327        configuration.base_path,
328        id = crate::apis::urlencode(p_path_id)
329    );
330    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
331
332    if let Some(ref user_agent) = configuration.user_agent {
333        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
334    }
335    if let Some(ref apikey) = configuration.api_key {
336        let key = apikey.key.clone();
337        let value = match apikey.prefix {
338            Some(ref prefix) => format!("{} {}", prefix, key),
339            None => key,
340        };
341        req_builder = req_builder.header("X-API-Key", value);
342    };
343    if let Some(ref auth_conf) = configuration.basic_auth {
344        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
345    };
346
347    let req = req_builder.build()?;
348    let resp = configuration.client.execute(req).await?;
349
350    let status = resp.status();
351    let content_type = resp
352        .headers()
353        .get("content-type")
354        .and_then(|v| v.to_str().ok())
355        .unwrap_or("application/octet-stream");
356    let content_type = super::ContentType::from(content_type);
357
358    if !status.is_client_error() && !status.is_server_error() {
359        let content = resp.text().await?;
360        match content_type {
361            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
362            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::ThumbnailSeriesCollectionDto&gt;`"))),
363            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::ThumbnailSeriesCollectionDto&gt;`")))),
364        }
365    } else {
366        let content = resp.text().await?;
367        let entity: Option<GetCollectionThumbnailsError> = serde_json::from_str(&content).ok();
368        Err(Error::ResponseError(ResponseContent {
369            status,
370            content,
371            entity,
372        }))
373    }
374}
375
376/// Required role: **ADMIN**
377pub async fn mark_collection_thumbnail_selected(
378    configuration: &configuration::Configuration,
379    id: &str,
380    thumbnail_id: &str,
381) -> Result<(), Error<MarkCollectionThumbnailSelectedError>> {
382    // add a prefix to parameters to efficiently prevent name collisions
383    let p_path_id = id;
384    let p_path_thumbnail_id = thumbnail_id;
385
386    let uri_str = format!(
387        "{}/api/v1/collections/{id}/thumbnails/{thumbnailId}/selected",
388        configuration.base_path,
389        id = crate::apis::urlencode(p_path_id),
390        thumbnailId = crate::apis::urlencode(p_path_thumbnail_id)
391    );
392    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
393
394    if let Some(ref user_agent) = configuration.user_agent {
395        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
396    }
397    if let Some(ref apikey) = configuration.api_key {
398        let key = apikey.key.clone();
399        let value = match apikey.prefix {
400            Some(ref prefix) => format!("{} {}", prefix, key),
401            None => key,
402        };
403        req_builder = req_builder.header("X-API-Key", value);
404    };
405    if let Some(ref auth_conf) = configuration.basic_auth {
406        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
407    };
408
409    let req = req_builder.build()?;
410    let resp = configuration.client.execute(req).await?;
411
412    let status = resp.status();
413
414    if !status.is_client_error() && !status.is_server_error() {
415        Ok(())
416    } else {
417        let content = resp.text().await?;
418        let entity: Option<MarkCollectionThumbnailSelectedError> =
419            serde_json::from_str(&content).ok();
420        Err(Error::ResponseError(ResponseContent {
421            status,
422            content,
423            entity,
424        }))
425    }
426}