From a349fd340fc63c476358237dbcaafb6ed4a2c521 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sun, 8 Mar 2026 21:47:32 +0300 Subject: Remove unused models, fields, and endpoints If they are ever needed again, they can be added back. Also set API endpoints fields to Url type instead of String. --- src/main.rs | 24 +++--------------------- src/models.rs | 30 +++--------------------------- 2 files changed, 6 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 7b73bf3..8712d4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use std::path::PathBuf; use crate::epub::{create_epub_archive, download_all_files}; use crate::http_client::build_authenticated_client; -use crate::models::{Chapter, EpubResponse, FileEntry, Paginated, SpineItem, TocNode}; +use crate::models::{Chapter, EpubResponse, FileEntry, Paginated}; use anyhow::{Context, Result, anyhow}; use clap::Parser; use directories::{BaseDirs, UserDirs}; @@ -44,24 +44,8 @@ async fn fetch_epub_data(client: &Client, bookid: &str) -> Result Ok(response) } -/// Fetches a direct array endpoint (no pagination, simple list). -async fn fetch_direct_array(client: &Client, url: &str) -> Result> -where - T: serde::de::DeserializeOwned, -{ - let response = client - .get(url) - .send() - .await? - .error_for_status()? - .json::>() - .await - .context("Failed to deserialize API response")?; - Ok(response) -} - /// Fetch a paginated API. -async fn fetch_all_pages(client: &reqwest::Client, mut url: String) -> Result> +async fn fetch_all_pages(client: &reqwest::Client, mut url: url::Url) -> Result> where T: serde::de::DeserializeOwned, { @@ -69,7 +53,7 @@ where loop { // GET current URL and deserialize into Paginated. let response = client - .get(&url) + .get(url) .send() .await? .error_for_status()? @@ -144,8 +128,6 @@ async fn main() -> Result<()> { let chapters: HashMap = chapters.into_iter().map(|c| (c.ourn.clone(), c)).collect(); let file_entries: Vec = fetch_all_pages(&client, epub_data.files.clone()).await?; - let spine_items: Vec = fetch_all_pages(&client, epub_data.spine.clone()).await?; - let toc_vec: Vec = fetch_direct_array(&client, &epub_data.table_of_contents).await?; let epub_root = data_root.join("files").join(&args.bookid); if !args.skip_download { diff --git a/src/models.rs b/src/models.rs index 5f92d03..806d746 100644 --- a/src/models.rs +++ b/src/models.rs @@ -5,7 +5,7 @@ use url::Url; /// Generic Model for paginated API. #[derive(Debug, serde::Deserialize)] pub struct Paginated { - pub next: Option, + pub next: Option, pub results: Vec, } @@ -15,10 +15,8 @@ pub struct EpubResponse { pub publication_date: String, pub title: String, pub descriptions: Descriptions, - pub chapters: String, // This is a URL to the chapters list - pub files: String, // This is a URL to the resource files - pub spine: String, // This is a URL to the spine list - pub table_of_contents: String, // This is a URL to the table of contents + pub chapters: Url, + pub files: Url, pub language: String, } @@ -34,7 +32,6 @@ pub struct Descriptions { pub struct Chapter { pub ourn: String, pub title: String, - pub is_skippable: bool, pub related_assets: ChapRelAssets, } @@ -51,26 +48,5 @@ pub struct FileEntry { pub url: Url, pub full_path: RelativePathBuf, pub media_type: String, - pub filename: String, pub filename_ext: String, - pub kind: String, -} - -/// Model for spine API. -#[derive(Debug, Deserialize)] -pub struct SpineItem { - pub ourn: String, - pub reference_id: String, - pub title: String, -} - -/// Model for table of contents API. -#[derive(Debug, Deserialize)] -pub struct TocNode { - pub depth: u32, - pub reference_id: String, - pub ourn: String, - pub fragment: String, - pub title: String, - pub children: Vec, } -- cgit v1.2.3-70-g09d2