pinakes-core: improve media management features; various configuration improvements

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I2d1f04f13970d21c36067f30bc04a9176a6a6964
This commit is contained in:
raf 2026-02-05 00:54:10 +03:00
commit e02c15490e
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
31 changed files with 1087 additions and 197 deletions

View file

@ -30,12 +30,10 @@ impl OpenLibraryClient {
pub async fn fetch_by_isbn(&self, isbn: &str) -> Result<OpenLibraryBook> {
let url = format!("{}/isbn/{}.json", self.base_url, isbn);
let response = self
.client
.get(&url)
.send()
.await
.map_err(|e| PinakesError::External(format!("OpenLibrary request failed: {}", e)))?;
let response =
self.client.get(&url).send().await.map_err(|e| {
PinakesError::External(format!("OpenLibrary request failed: {}", e))
})?;
if !response.status().is_success() {
return Err(PinakesError::External(format!(
@ -44,15 +42,22 @@ impl OpenLibraryClient {
)));
}
response
.json::<OpenLibraryBook>()
.await
.map_err(|e| PinakesError::External(format!("Failed to parse OpenLibrary response: {}", e)))
response.json::<OpenLibraryBook>().await.map_err(|e| {
PinakesError::External(format!("Failed to parse OpenLibrary response: {}", e))
})
}
/// Search for books by title and author
pub async fn search(&self, title: &str, author: Option<&str>) -> Result<Vec<OpenLibrarySearchResult>> {
let mut url = format!("{}/search.json?title={}", self.base_url, urlencoding::encode(title));
pub async fn search(
&self,
title: &str,
author: Option<&str>,
) -> Result<Vec<OpenLibrarySearchResult>> {
let mut url = format!(
"{}/search.json?title={}",
self.base_url,
urlencoding::encode(title)
);
if let Some(author) = author {
url.push_str(&format!("&author={}", urlencoding::encode(author)));
@ -74,10 +79,9 @@ impl OpenLibraryClient {
)));
}
let search_response: OpenLibrarySearchResponse = response
.json()
.await
.map_err(|e| PinakesError::External(format!("Failed to parse search results: {}", e)))?;
let search_response: OpenLibrarySearchResponse = response.json().await.map_err(|e| {
PinakesError::External(format!("Failed to parse search results: {}", e))
})?;
Ok(search_response.docs)
}
@ -153,9 +157,9 @@ impl OpenLibraryClient {
#[derive(Debug, Clone, Copy)]
pub enum CoverSize {
Small, // 256x256
Medium, // 600x800
Large, // Original
Small, // 256x256
Medium, // 600x800
Large, // Original
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -277,7 +281,8 @@ mod tests {
let string_desc: StringOrObject = serde_json::from_str(r#""Simple description""#).unwrap();
assert_eq!(string_desc.as_str(), "Simple description");
let object_desc: StringOrObject = serde_json::from_str(r#"{"value": "Object description"}"#).unwrap();
let object_desc: StringOrObject =
serde_json::from_str(r#"{"value": "Object description"}"#).unwrap();
assert_eq!(object_desc.as_str(), "Object description");
}
}