Skip to main content

komga_sdk/apis/
import_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 [`analyze_transient_book`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AnalyzeTransientBookError {
22    Status400(models::ValidationErrorResponse),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`get_page_by_transient_book_id`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetPageByTransientBookIdError {
30    Status400(models::ValidationErrorResponse),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`import_books`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ImportBooksError {
38    Status400(models::ValidationErrorResponse),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`scan_transient_books`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ScanTransientBooksError {
46    Status400(models::ValidationErrorResponse),
47    UnknownValue(serde_json::Value),
48}
49
50
51/// Required role: **ADMIN**
52pub async fn analyze_transient_book(configuration: &configuration::Configuration, id: &str) -> Result<models::TransientBookDto, Error<AnalyzeTransientBookError>> {
53    // add a prefix to parameters to efficiently prevent name collisions
54    let p_path_id = id;
55
56    let uri_str = format!("{}/api/v1/transient-books/{id}/analyze", configuration.base_path, id=crate::apis::urlencode(p_path_id));
57    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
58
59    if let Some(ref user_agent) = configuration.user_agent {
60        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61    }
62    if let Some(ref apikey) = configuration.api_key {
63        let key = apikey.key.clone();
64        let value = match apikey.prefix {
65            Some(ref prefix) => format!("{} {}", prefix, key),
66            None => key,
67        };
68        req_builder = req_builder.header("X-API-Key", value);
69    };
70    if let Some(ref auth_conf) = configuration.basic_auth {
71        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
72    };
73
74    let req = req_builder.build()?;
75    let resp = configuration.client.execute(req).await?;
76
77    let status = resp.status();
78    let content_type = resp
79        .headers()
80        .get("content-type")
81        .and_then(|v| v.to_str().ok())
82        .unwrap_or("application/octet-stream");
83    let content_type = super::ContentType::from(content_type);
84
85    if !status.is_client_error() && !status.is_server_error() {
86        let content = resp.text().await?;
87        match content_type {
88            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
89            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TransientBookDto`"))),
90            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::TransientBookDto`")))),
91        }
92    } else {
93        let content = resp.text().await?;
94        let entity: Option<AnalyzeTransientBookError> = serde_json::from_str(&content).ok();
95        Err(Error::ResponseError(ResponseContent { status, content, entity }))
96    }
97}
98
99/// Required role: **ADMIN**
100pub async fn get_page_by_transient_book_id(configuration: &configuration::Configuration, id: &str, page_number: i32) -> Result<String, Error<GetPageByTransientBookIdError>> {
101    // add a prefix to parameters to efficiently prevent name collisions
102    let p_path_id = id;
103    let p_path_page_number = page_number;
104
105    let uri_str = format!("{}/api/v1/transient-books/{id}/pages/{pageNumber}", configuration.base_path, id=crate::apis::urlencode(p_path_id), pageNumber=p_path_page_number);
106    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
107
108    if let Some(ref user_agent) = configuration.user_agent {
109        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
110    }
111    if let Some(ref apikey) = configuration.api_key {
112        let key = apikey.key.clone();
113        let value = match apikey.prefix {
114            Some(ref prefix) => format!("{} {}", prefix, key),
115            None => key,
116        };
117        req_builder = req_builder.header("X-API-Key", value);
118    };
119    if let Some(ref auth_conf) = configuration.basic_auth {
120        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
121    };
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 `String`"))),
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 `String`")))),
140        }
141    } else {
142        let content = resp.text().await?;
143        let entity: Option<GetPageByTransientBookIdError> = serde_json::from_str(&content).ok();
144        Err(Error::ResponseError(ResponseContent { status, content, entity }))
145    }
146}
147
148/// Required role: **ADMIN**
149pub async fn import_books(configuration: &configuration::Configuration, book_import_batch_dto: models::BookImportBatchDto) -> Result<(), Error<ImportBooksError>> {
150    // add a prefix to parameters to efficiently prevent name collisions
151    let p_body_book_import_batch_dto = book_import_batch_dto;
152
153    let uri_str = format!("{}/api/v1/books/import", configuration.base_path);
154    let mut req_builder = configuration.client.request(reqwest::Method::POST, &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    req_builder = req_builder.json(&p_body_book_import_batch_dto);
171
172    let req = req_builder.build()?;
173    let resp = configuration.client.execute(req).await?;
174
175    let status = resp.status();
176
177    if !status.is_client_error() && !status.is_server_error() {
178        Ok(())
179    } else {
180        let content = resp.text().await?;
181        let entity: Option<ImportBooksError> = serde_json::from_str(&content).ok();
182        Err(Error::ResponseError(ResponseContent { status, content, entity }))
183    }
184}
185
186/// Scan provided folder for transient books.  Required role: **ADMIN**
187pub async fn scan_transient_books(configuration: &configuration::Configuration, scan_request_dto: models::ScanRequestDto) -> Result<Vec<models::TransientBookDto>, Error<ScanTransientBooksError>> {
188    // add a prefix to parameters to efficiently prevent name collisions
189    let p_body_scan_request_dto = scan_request_dto;
190
191    let uri_str = format!("{}/api/v1/transient-books", configuration.base_path);
192    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
193
194    if let Some(ref user_agent) = configuration.user_agent {
195        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
196    }
197    if let Some(ref apikey) = configuration.api_key {
198        let key = apikey.key.clone();
199        let value = match apikey.prefix {
200            Some(ref prefix) => format!("{} {}", prefix, key),
201            None => key,
202        };
203        req_builder = req_builder.header("X-API-Key", value);
204    };
205    if let Some(ref auth_conf) = configuration.basic_auth {
206        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
207    };
208    req_builder = req_builder.json(&p_body_scan_request_dto);
209
210    let req = req_builder.build()?;
211    let resp = configuration.client.execute(req).await?;
212
213    let status = resp.status();
214    let content_type = resp
215        .headers()
216        .get("content-type")
217        .and_then(|v| v.to_str().ok())
218        .unwrap_or("application/octet-stream");
219    let content_type = super::ContentType::from(content_type);
220
221    if !status.is_client_error() && !status.is_server_error() {
222        let content = resp.text().await?;
223        match content_type {
224            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
225            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::TransientBookDto&gt;`"))),
226            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::TransientBookDto&gt;`")))),
227        }
228    } else {
229        let content = resp.text().await?;
230        let entity: Option<ScanTransientBooksError> = serde_json::from_str(&content).ok();
231        Err(Error::ResponseError(ResponseContent { status, content, entity }))
232    }
233}
234