From b0035a511b13b03c4c73b0cfad488dbab541e01e Mon Sep 17 00:00:00 2001 From: A Farzat Date: Tue, 3 Mar 2026 10:28:20 +0300 Subject: Add file download logic All files in file_entries are downloaded according to their full_path. --- src/epub.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/epub.rs (limited to 'src/epub.rs') diff --git a/src/epub.rs b/src/epub.rs new file mode 100644 index 0000000..0c0bc74 --- /dev/null +++ b/src/epub.rs @@ -0,0 +1,34 @@ +use crate::models::FileEntry; +use anyhow::Result; +use reqwest::Client; +use std::path::Path; +use tokio::{ + fs::{self, File}, + io::AsyncWriteExt, +}; + +pub async fn download_all_files( + client: &Client, + file_entries: &[FileEntry], + dest_root: &Path, +) -> Result<()> { + for entry in file_entries { + let dest_path = dest_root.join(&entry.full_path); + + if let Some(parent_dir) = dest_path.parent() { + fs::create_dir_all(parent_dir).await?; + } + + let mut file = File::create(dest_path).await?; + let bytes = client + .get(&entry.url) + .send() + .await? + .error_for_status()? + .bytes() + .await?; + + file.write_all(&bytes).await?; + } + Ok(()) +} -- cgit v1.2.3-70-g09d2