Compare commits

..

4 Commits

Author SHA1 Message Date
ec8cc12bf8 fix: Minor bugfix 2025-09-09 22:50:42 +03:00
4a7ed0974c feat: Deduplicate fb2 authors 2025-09-09 22:50:31 +03:00
5dc2cb112d doc: Regenerate AI docs for parsers, cleanup 2025-09-09 21:25:31 +03:00
00dc0e39b9 feat: Save book file path, refactoring
Close #1
2025-09-09 21:16:14 +03:00
10 changed files with 301 additions and 205 deletions

View File

@@ -11,6 +11,7 @@ use crate::domain::book::Book;
use std::collections::VecDeque;
use std::fs;
use std::path::PathBuf;
use crate::application::parsers::Source;
pub struct Loader {
root: PathBuf,
@@ -76,7 +77,7 @@ impl Iterator for LoaderIter {
impl LoaderIter {
fn parse_path(path: &PathBuf) -> Option<Vec<Book>> {
match parsers::parse(&path) {
match parsers::parse(Source{ path: (*path).clone(), reader: None}) {
Ok(books) => return Some(books),
Err(err) => {
match err {

View File

@@ -8,6 +8,7 @@ use std::collections::VecDeque;
use std::ffi::OsStr;
use std::io;
use std::path::PathBuf;
use crate::application::parsers::Source;
const BUFFER_SIZE: usize = 4096;
@@ -72,7 +73,7 @@ impl<'a> LoaderIter<'a> {
return None;
}
match parsers::parse(&path) {
match parsers::parse(Source{path: path.clone(), reader: None}) {
Ok(books) => {
for book in &books {
println!("{}", book);

View File

@@ -3,82 +3,112 @@ use crate::domain::book::Book;
use quick_xml::events::Event;
use quick_xml::Reader;
use std::fs::File;
use std::io::BufReader;
use std::io::{BufRead, BufReader};
use std::path::Path;
/// Parses an XML file located at the given path and extracts information about books.
///
/// This function processes the XML structure using a streaming XML reader to extract details
/// about books, including:
/// - Title
/// - Language
/// - Keywords
/// - Authors (including optional details like first name, last name, middle name, and nickname)
/// - Publication year
/// - Publisher
/// - Description
/// Parses the content of a file at the given path to extract a list of `Book` objects.
///
/// # Arguments
///
/// * `path` - A reference to the file path (`&Path`) of the XML file to parse.
/// * `path` - A reference to a `Path` representing the location of the file to be parsed.
///
/// # Returns
///
/// Returns a `Result` where:
/// - `Ok(Vec<Book>)` contains a vector of `Book` objects constructed from the parsed XML.
/// - `Err(String)` contains an error message if the parsing fails at any stage.
/// * `Ok(Vec<Book>)` - A vector containing the list of `Book` objects on successful parsing.
/// * `Err(String)` - A string containing an error message if the file could not be opened or parsing failed.
///
/// # Errors
///
/// Returns an error in the following scenarios:
/// - Unable to open the file specified by `path`.
/// - Malformed XML data in the file.
/// - Issues during data extraction, such as reading incomplete or invalid values.
/// This function returns an error in the following cases:
/// * If the file at the specified path cannot be opened, the corresponding IO error is converted to a string and returned.
/// * If the parsing logic inside `parse_with_reader` fails, the returned error from that function is propagated.
///
/// # Example
///
/// ```ignore
/// use std::path::Path;
///
/// let path = Path::new("books.txt");
/// let result = parse(path);
///
/// match result {
/// Ok(books) => println!("Parsed {} books", books.len()),
/// Err(err) => eprintln!("Error parsing books: {}", err),
/// }
/// ```
pub fn parse(path: &Path) -> Result<Vec<Book>, String> {
let file = File::open(path).map_err(|e| e.to_string())?;
let reader = BufReader::new(file);
parse_with_reader(Box::new(reader), path)
}
/// Parses an XML document using a buffered reader and extracts book information.
///
/// This function reads an XML document containing book details and maps it to a `Vec<Book>`.
/// It supports parsing various elements such as title, language, keywords, author details,
/// publisher, description, and publication year. Errors during parsing are propagated as strings.
///
/// # Type Parameters
/// - `R`: A type that implements the [`BufRead`](std::io::BufRead) trait for buffered input.
///
/// # Arguments
/// - `reader`: A buffered reader instance (e.g., [`std::io::BufReader`]) to read the XML content.
/// - `path`: A reference to a [`Path`](std::path::Path) representing the source file or data for the book.
///
/// # Returns
/// - `Ok(Vec<Book>)` if parsing was successful, containing a vector of parsed `Book` results.
/// - `Err(String)` if an error occurred during parsing, containing a string description of the error.
///
/// # XML Parsing Details
/// The following XML tags are processed:
/// - `<book-title>`: Extracted as the book's title.
/// - `<lang>`: Extracted as the book's language.
/// - `<keywords>`: Split by commas into individual tags for the book.
/// - `<annotation>`: Extracted into a multiline description for the book.
/// - `<author>`: Processes child elements such as `<first-name>`, `<last-name>`, `<middle-name>`,
/// and `<nickname>` to construct an author's full details.
/// - `<year>`: Extracted as the book's publication year.
/// - `<publisher>`: Extracted as the book's publisher.
///
/// # Behavior
/// - Multiple authors are supported through repeated `<author>` tags.
/// - Whitespace is trimmed from all parsed text.
/// - If no content is available for certain fields (e.g., `<last-name>`), they may remain `None`
/// or their equivalent default.
///
/// # Errors
/// This function returns an error in the following cases:
/// - The XML data contains malformed or invalid content.
/// - Unexpected EOF is encountered during XML parsing.
/// - Any other IO or XML parsing errors occur.
///
/// # Example
/// ```ignore
/// use std::fs::File;
/// use std::io::BufReader;
/// use std::path::Path;
///
/// let file = File::open("books.xml").expect("Failed to open file");
/// let reader = BufReader::new(file);
/// let path = Path::new("books.xml");
/// match parse(&path) {
///
/// let result = parse_with_reader(reader, &path);
/// match result {
/// Ok(books) => {
/// for book in books {
/// println!("Book Title: {}", book.title);
/// println!("Book title: {}", book.title);
/// }
/// },
/// Err(err) => eprintln!("Failed to parse XML file: {}", err),
/// }
/// Err(e) => eprintln!("Error parsing XML: {}", e),
/// }
/// ```
///
/// # XML Structure
///
/// The XML should follow a specific schema with the following relevant elements:
/// - `<book-title>`: Title of the book.
/// - `<lang>`: Language of the book.
/// - `<keywords>`: A comma-separated list of keywords/tags.
/// - `<author>`: Contains subfields `<first-name>`, `<last-name>`, `<middle-name>`, or `<nickname>`.
/// - `<year>`: Year of publication.
/// - `<publisher>`: Publisher's name.
/// - `<annotation>`: Description or annotation of the book.
/// # Dependencies
/// This function relies on an external XML parsing library capable of handling streaming XML,
/// such as `quick-xml`. The `Book` and `author::Author` structs, along with their methods (e.g., `new`),
/// must be defined elsewhere in the codebase.
///
/// # Notes
///
/// - Author data is flexible; if a nickname exists, it will override other name details.
/// - The resulting `Vec<Book>` contains just one book object, as indicated in the implementation.
///
/// # Dependencies
///
/// This function depends on the following crates:
/// - `quick-xml`: For fast XML parsing.
/// - `uuid`: To generate a unique identifier for each book.
/// - `chrono`: To serialize the current timestamp as an RFC3339 string.
///
/// # See Also
///
/// `Book` structure, which represents the parsed data for an individual book.
pub fn parse(path: &Path) -> Result<Vec<Book>, String> {
let file = File::open(path).map_err(|e| e.to_string())?;
let mut reader = Reader::from_reader(BufReader::new(file));
/// - The function assumes that the XML tags match the expected structure. Unrecognized tags are ignored.
/// - It is assumed that the user will extend support for future XML element types as needed.
pub fn parse_with_reader<R: BufRead>(reader: R, path: &Path) -> Result<Vec<Book>, String> {
let mut reader = Reader::from_reader(reader);
let mut buf = Vec::new();
let mut in_title = false;
@@ -87,6 +117,7 @@ pub fn parse(path: &Path) -> Result<Vec<Book>, String> {
let mut in_description = false;
let mut book = Book::new();
book.source = path.into();
loop {
match reader.read_event_into(&mut buf) {
@@ -178,7 +209,8 @@ pub fn parse(path: &Path) -> Result<Vec<Book>, String> {
}
b"year" => {
if let Ok(Event::Text(t)) = reader.read_event_into(&mut buf) {
book.published_at = t.xml_content().map_err(|e| e.to_string())?.into_owned();
book.published_at =
t.xml_content().map_err(|e| e.to_string())?.into_owned();
}
}
b"publisher" => {
@@ -223,5 +255,7 @@ pub fn parse(path: &Path) -> Result<Vec<Book>, String> {
buf.clear();
}
book.author.dedup_by(|a, b| a.uniq_id() == b.uniq_id());
Ok(vec![book])
}

View File

@@ -1,17 +1,13 @@
use std::fmt;
use crate::domain::book::Book;
use std::fmt;
use std::fs::File;
use std::io::BufRead;
use std::path::PathBuf;
mod rs;
mod fb2;
mod rs;
mod zip;
/// Error enumeration representing possible errors that can occur when parsing files.
///
/// This enumeration has the following variants:
/// - `NotSupported`: Indicates that the file format or extension is not supported.
/// - `ParseError`: Contains a `String` representing the error message when a parsing process fails.
#[derive(Debug)]
pub enum Error {
NotSupported,
@@ -27,53 +23,129 @@ impl fmt::Display for Error {
}
}
/// Parses a file at the given path and attempts to convert its contents into a vector of `Book` objects.
/// Represents a source file or location that can be read from.
///
/// This function determines the file type based on its extension and delegates the parsing duties
/// to the appropriate module. Supported file extensions are:
/// - `.rs`: Processed by the `rs` module.
/// - `.fb2`: Processed by the `fb2` module.
/// - `.zip`: Processed by the `zip` module.
/// The `Source` struct encapsulates information about a file or source location, including its
/// path and an optional reader for reading the source's contents. This allows for flexibility
/// in creating `Source` instances where the reading mechanism may be deferred or not immediately available.
///
/// If the file's extension is unsupported or missing, this function returns a `NotSupported` error.
/// # Fields
///
/// # Arguments
///
/// * `path` - A reference to a `PathBuf` that represents the file path to be parsed.
///
/// # Returns
///
/// * `Ok(Vec<Book>)` - A vector of `Book` objects if the file was successfully parsed.
/// * `Err(Error)` - An error if the file could not be parsed, the parsing process encountered
/// an issue, or the file extension is not supported.
///
/// # Errors
///
/// - `Error::ParseError` - If the file parsing fails.
/// - `Error::NotSupported` - If the file's extension is unsupported or missing.
/// * `path` - A `PathBuf` representing the file system path to the source. This path must be valid.
/// * `reader` - An optional boxed dynamic trait object (`Option<Box<dyn BufRead>>`) that represents
/// a buffered reader capable of reading the contents of the source. If `None`, no reader
/// is currently defined or available.
///
/// # Examples
///
/// ```ignore
/// use std::fs::File;
/// use std::io::{BufReader, BufRead};
/// use std::path::PathBuf;
///
/// let path = PathBuf::from("example.rs");
/// let books = parse(&path);
/// match books {
/// Ok(book_list) => println!("Parsed {} books.", book_list.len()),
/// Err(e) => println!("Failed to parse file: {:?}", e),
/// let path = PathBuf::from("example.txt");
/// let file = File::open(&path).expect("Failed to open file");
/// let reader = BufReader::new(file);
///
/// let source = Source {
/// path,
/// reader: Some(Box::new(reader)),
/// };
/// ```
///
/// In the above example, a `Source` instance is created with a valid path and a buffered reader.
///
/// ```ignore
/// use std::path::PathBuf;
///
/// let source = Source {
/// path: PathBuf::from("example.txt"),
/// reader: None,
/// };
/// ```
///
/// In this example, a `Source` instance is created with a path but no reader. This might be useful
/// for cases where reading is deferred to a later point in time.
pub struct Source {
pub path: PathBuf,
pub reader: Option<Box<dyn BufRead>>, // Сделал reader опциональным
}
/// Parses a `Source` to extract a vector of `Book` objects.
///
/// This function handles different file types based on the file's extension.
/// Supported file types and their parsing strategies include:
/// - `.rs`: Uses the `rs::parse` function to handle Rust source files.
/// - `.fb2`: Handles FictionBook 2 (FB2) files. This supports:
/// - Using a provided `reader` (if `source.reader` is given).
/// - Opening and parsing directly from the file otherwise.
/// - `.zip`: Handles ZIP archives. Always opens the file itself as ZIP parsing
/// requires the file to implement the `Seek` trait.
///
/// If the file extension is unsupported or undefined, the function returns
/// an `Error::NotSupported`.
///
/// # Parameters
///
/// - `source`: A `Source` object containing the file path and an optional `reader`
/// for parsing.
///
/// # Returns
///
/// - `Ok(Vec<Book>)`: If the parsing is successful, returns a vector of `Book` objects.
/// - `Err(Error)`: If an error occurs during parsing or if the file type is unsupported.
///
/// # Errors
///
/// - Returns `Error::ParseError` if there is an issue reading or parsing the file.
/// - Returns `Error::NotSupported` if the file type is unsupported.
///
/// # Examples
///
/// ```ignore
/// let source = Source {
/// path: PathBuf::from("example.fb2"),
/// reader: None,
/// };
/// let result = parse(source);
/// match result {
/// Ok(books) => println!("Parsed successfully: {:?}", books),
/// Err(error) => eprintln!("Failed to parse: {:?}", error),
/// }
/// ```
///
/// # Notes
///
/// Ensure that the appropriate parsers (`rs`, `fb2`, `zip`) are properly implemented
/// and handle all required logic for their respective file types to avoid unexpected errors.
pub fn parse(path: &PathBuf) -> Result<Vec<Book>, Error> {
/// - For `.fb2` files, if a `reader` is provided in the `Source` object, it will
/// be used for parsing. Otherwise, the function will open the file and parse it.
/// - `.zip` files require the file to support the `Seek` trait and will always
/// be opened directly from the file system.
///
/// # File Types
///
/// - `.rs`: Rust source files.
/// - `.fb2`: FictionBook 2 files.
/// - `.zip`: ZIP archives.
///
/// # See Also
///
/// - [`rs::parse`](#)
/// - [`fb2::parse`](#)
/// - [`fb2::parse_with_reader`](#)
/// - [`zip::parse`](#)
pub fn parse(source: Source) -> Result<Vec<Book>, Error> {
let path = &source.path;
match path.extension().and_then(|s| s.to_str()) {
Some("rs") => rs::parse(path).map_err(Error::ParseError),
Some("fb2") => fb2::parse(path).map_err(Error::ParseError),
Some("zip") => zip::parse(path).map_err(Error::ParseError),
Some("fb2") => match source.reader {
Some(reader) => fb2::parse_with_reader(reader, path).map_err(Error::ParseError),
None => fb2::parse(path).map_err(Error::ParseError),
},
Some("zip") => {
let file = File::open(path).map_err(|e| Error::ParseError(e.to_string()))?;
zip::parse(file, path).map_err(Error::ParseError)
}
Some(_) | None => Err(Error::NotSupported),
}
}

View File

@@ -2,44 +2,6 @@ use crate::domain::author::Author;
use crate::domain::book::Book;
use std::path::PathBuf;
/// Parses a given file path into a vector containing a `Book` object.
///
/// # Arguments
///
/// * `path` - A reference to a `PathBuf` that represents the file path to be parsed.
///
/// # Returns
///
/// * `Result<Vec<Book>, String>` -
/// - On success, returns a `Vec<Book>` with a single `Book` object populated based on the input path.
/// - On failure, returns an error `String` describing the issue.
///
/// The function performs the following steps:
///
/// 1. Creates a new instance of `Book`.
/// 2. Sets the `title` of the `Book` to the string representation of the input path.
/// 3. Creates a new instance of `Author`.
/// 4. Sets the `first_name` of the `Author` to the string representation of the file extension of `path`.
/// 5. Pushes the `Author` into the `author` vector of the `Book`.
/// 6. Returns a `Vec<Book>` containing the newly created `Book`.
///
/// # Panics
///
/// The function will panic if the input path does not contain a file extension
/// (i.e., when `path.extension()` returns `None`).
///
/// # Example
///
/// ```ignore
/// use std::path::PathBuf;
///
/// let path = PathBuf::from("example.txt");
/// let books = parse(&path).unwrap();
///
/// assert_eq!(books.len(), 1);
/// assert_eq!(books[0].title, "example.txt");
/// assert_eq!(books[0].author[0].first_name, "txt");
/// ```
pub fn parse(path: &PathBuf) -> Result<Vec<Book>, String> {
let mut book = Book::new();
@@ -48,6 +10,7 @@ pub fn parse(path: &PathBuf) -> Result<Vec<Book>, String> {
let mut author = Author::new();
author.first_name = path.extension().unwrap().to_string_lossy().to_string();
book.author.push(author);
book.source = path.into();
return Ok(vec![ book]);
}

View File

@@ -1,72 +1,102 @@
use crate::application::parsers;
use crate::application::parsers::{parse as parse_source, Source};
use crate::domain::book::Book;
use std::fs::File;
use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::io::{BufRead, Cursor, Read};
use std::path::Path;
use zip::ZipArchive;
/// Parses a ZIP archive to extract a collection of `Book` objects.
/// Parses a ZIP archive to extract and process book data.
///
/// This function takes a path to a ZIP archive file, reads its contents, and processes
/// each file within the archive to extract `Book` objects using a custom parser. If any
/// errors occur during file access, archive extraction, or parsing, they are returned as
/// a `String`. On success, it returns a vector of `Book` objects contained in the archive.
/// This function reads a given ZIP archive, processes each file inside, and attempts to parse
/// them into a vector of `Book` objects. Each file in the archive is expected to be in a format
/// compatible with the `parse_source` function.
///
/// # Type Parameters
/// - `R`: A type that implements both [`Read`](std::io::Read) and [`Seek`](std::io::Seek), which allows
/// reading and seeking operations on the input file.
///
/// # Arguments
///
/// * `path` - A reference to a `Path` representing the file system path to the ZIP archive.
/// - `reader`: A reader implementing `Read` and `Seek`, used to access the ZIP archive.
/// - `path`: A reference to a [`Path`](std::path::Path) representing the file system path to the ZIP archive.
///
/// # Returns
///
/// * `Ok(Vec<Book>)` - A vector containing the `Book` objects successfully parsed
/// from the files in the archive.
/// * `Err(String)` - An error message if any step in opening the file, reading the archive,
/// or parsing the files fails.
/// - `Ok(Vec<Book>)`: If parsing is successful, returns a vector of `Book` objects extracted from
/// the ZIP archive.
/// - `Err(String)`: If an error occurs, returns a descriptive error message as a `String`.
///
/// # Errors
///
/// This function returns an error in the following cases:
/// * If the ZIP file cannot be opened.
/// * If the ZIP archive cannot be read.
/// * If an individual file within the archive cannot be accessed.
/// * If the parsing of a file fails.
/// The function may return an error in the following cases:
/// - If the ZIP archive cannot be opened.
/// - If the function encounters issues reading from the ZIP archive or its files.
/// - If a file within the archive cannot be parsed into `Book` objects.
///
/// # Example
///
/// ```ignore
/// use std::fs::File;
/// use std::path::Path;
/// use your_crate::parse;
/// use your_crate::parse_direct;
///
/// let path = Path::new("books_archive.zip");
/// match parse(&path) {
/// Ok(books) => {
/// for book in books {
/// println!("Parsed book: {:?}", book);
/// }
/// }
/// Err(e) => eprintln!("Failed to parse books: {}", e),
/// let file = File::open("test_books.zip").expect("Failed to open file");
/// let path = Path::new("test_books.zip");
///
/// match parse_direct(file, &path) {
/// Ok(books) => println!("Parsed {} books", books.len()),
/// Err(e) => eprintln!("Error parsing archive: {}", e),
/// }
/// ```
///
/// # Dependencies
/// # Implementation Details
/// - The function processes each file inside the archive by reopening the archive for each iteration. This
/// ensures the `ZipArchive` does not consume other files during iteration.
/// - File contents are read into memory as raw bytes and wrapped in a [`BufReader`](std::io::BufRead) for further processing.
/// - Each file's path is dynamically constructed to include a placeholder `#` directory and its original name.
/// - The main parsing is delegated to the `parse_source` function, which returns either parsed books or an error.
///
/// This function relies on the `ZipArchive` for working with ZIP files and a `parsers`
/// module for custom file parsing logic.
pub fn parse(path: &Path) -> Result<Vec<Book>, String> {
let file = File::open(path).map_err(|e| e.to_string())?;
let reader = BufReader::new(file);
let mut archive = ZipArchive::new(reader).map_err(|e| e.to_string())?;
/// # Notes
/// - As the ZIP archive is re-opened for each file, the performance may be impacted for large archives.
/// - The `parse_source` function is expected to be defined elsewhere in the codebase to handle the specific parsing logic.
///
/// # Dependencies
/// - This function depends on the `zip` crate to handle ZIP file operations and a custom `Book` and `Source` structure
/// for processing individual entries.
///
/// # See Also
/// - [`ZipArchive`](zip::read::ZipArchive): Used to interact with the ZIP archive.
/// - `parse_source`: Required function that processes individual entries to extract `Book` data.
pub fn parse<R: Read + std::io::Seek + 'static>(
reader: R,
path: &Path,
) -> Result<Vec<Book>, String> {
let archive = ZipArchive::new(reader).map_err(|e| e.to_string())?;
let mut books: Vec<Book> = Vec::new();
for i in 0..archive.len() {
let file = archive.by_index(i).map_err(|e| e.to_string())?;
let name = file.name().to_string();
// Нам нужно знать путь к архиву для открытия файлов внутри него
let archive_path = path.to_path_buf();
match parsers::parse(&PathBuf::from(name.to_lowercase())) {
for i in 0..archive.len() {
// Открываем архив заново для каждого файла, так как ZipArchive consumes files
let file = File::open(&archive_path).map_err(|e| e.to_string())?;
let mut archive = ZipArchive::new(file).map_err(|e| e.to_string())?;
let mut zip_file = archive.by_index(i).map_err(|e| e.to_string())?;
let name = zip_file.name().to_string();
let file_path = path.to_path_buf().join("#").join(&name);
// Читаем содержимое файла в память и оборачиваем в BufReader
let mut contents = Vec::new();
zip_file
.read_to_end(&mut contents)
.map_err(|e| e.to_string())?;
let file_reader: Box<dyn BufRead> = Box::new(Cursor::new(contents)); // Изменили на BufRead
let source = Source {
path: file_path,
reader: Some(file_reader),
};
match parse_source(source) {
Ok(new_books) => books.extend(new_books),
Err(e) => return Err(e.to_string()),
Err(e) => return Err(format!("Error parsing {}: {}", name, e)),
}
}

View File

@@ -68,13 +68,17 @@ impl Books {
}
pub fn add_books_from_path(&mut self) {
let iter = fs::Loader::new(PathBuf::from(&self.root));
let books = fs::Loader::new(PathBuf::from(&self.root))
.into_iter()
.map(|mut book| {match book.source.strip_prefix(&self.root) {
Ok(path) => book.source = path.to_path_buf(),
Err(err) => eprintln!("strip source prefix: {}", err)
}; book})
.collect();
match self.repo.lock() {
Ok(mut repo) => {
for book in iter {
repo.add(book);
}
repo.bulk_add(books);
}
Err(err) => eprintln!("{}", err),
}

View File

@@ -1,5 +1,6 @@
use crate::domain::author;
use std::fmt;
use std::path::PathBuf;
use chrono::{DateTime, Utc};
use uuid::Uuid;
@@ -14,6 +15,7 @@ pub struct Book {
pub published_at: String,
pub publisher: String,
pub updated: DateTime<Utc>,
pub source: PathBuf
}
impl Book {
@@ -28,6 +30,7 @@ impl Book {
published_at: "".to_string(),
publisher: "".to_string(),
updated: chrono::Utc::now(),
source: PathBuf::new()
}
}
@@ -60,7 +63,7 @@ impl fmt::Display for Book {
.collect::<Vec<_>>()
.join(";");
write!(f, "{} by {}", self.title, authors)
write!(f, "{} by {} at {}", self.title, authors, self.source.to_str().unwrap())
}
}

View File

@@ -74,6 +74,7 @@ struct Book {
published_at: String,
publisher: String,
updated: String,
source: String,
}
impl From<book::Book> for Book {
@@ -88,6 +89,7 @@ impl From<book::Book> for Book {
published_at: book.published_at,
publisher: book.publisher,
updated: book.updated.to_rfc3339(),
source: book.source.as_os_str().to_str().unwrap().to_string(),
}
}
}
@@ -114,6 +116,7 @@ impl Into<book::Book> for Book {
published_at: self.published_at,
publisher: self.publisher,
updated: chrono::DateTime::parse_from_rfc3339(&self.updated).unwrap_or_default().to_utc(),
source: self.source.into(),
}
}
}

View File

@@ -1,19 +1,17 @@
use opds::demo;
use opds::domain::repository::{AuthorFilter, Repository};
use opds::domain::repository::BookFilter;
use opds::domain::repository::{AuthorFilter};
use quick_xml::se::to_string as to_xml_string;
use std::thread::sleep;
use std::time::Duration;
fn main() {
let app = demo();
let filter = BookFilter {
author: Some(AuthorFilter{
author: Some(AuthorFilter {
id: None,
name: None, //Some("rs".to_string()),
}),
title: Some("Сборник".to_string()),
title: Some("пов".to_string()),
language: None,
description: None,
tags: None,
@@ -27,20 +25,7 @@ fn main() {
if let Some(book) = res.entry.iter().next() {
let book = app.repo.lock().unwrap().get(book.id.to_string().clone());
println!("{:?}", book.unwrap().author);
println!("{:?}", book.clone().unwrap().author);
println!("{}", book.unwrap());
}
// sleep(Duration::new(10, 0));
//
// let filter = BookFilter {
// author: None,
// title: Some("foo".to_string()),
// language: None,
// description: None,
// tags: None,
// published_at: None,
// publisher: None,
// updated: None,
// };
// println!("{}", to_xml_string(&app.books.books_feed(filter)).unwrap());
}