Skip to main content

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