replace thiserror with snauf and poem with axum + utoipa
This commit is contained in:
parent
b4a0aadef9
commit
c067088a32
31 changed files with 223 additions and 317 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -313,7 +313,6 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"snafu",
|
"snafu",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror 1.0.69",
|
|
||||||
"time",
|
"time",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ members = [
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
serde = "1.0.219"
|
serde = "1.0.219"
|
||||||
snafu = { version = "0.8.6", features = ["rust_1_81"] }
|
snafu = { version = "0.8.6", features = ["rust_1_81"] }
|
||||||
thiserror = "1.0.61"
|
|
||||||
time = { version = "0.3.41", features = ["macros", "serde", "formatting", "parsing" ] }
|
time = { version = "0.3.41", features = ["macros", "serde", "formatting", "parsing" ] }
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
|
|
|
@ -14,5 +14,4 @@ rusqlite = { version = "0.36.0", features = ["bundled", "time"] }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
snafu = { workspace = true }
|
snafu = { workspace = true }
|
||||||
tempfile = "3.20.0"
|
tempfile = "3.20.0"
|
||||||
thiserror = { workspace = true }
|
|
||||||
time = { workspace = true }
|
time = { workspace = true }
|
||||||
|
|
|
@ -7,13 +7,13 @@ use std::{
|
||||||
|
|
||||||
use r2d2::Pool;
|
use r2d2::Pool;
|
||||||
use r2d2_sqlite::SqliteConnectionManager;
|
use r2d2_sqlite::SqliteConnectionManager;
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
use tempfile::{NamedTempFile, PersistError};
|
use tempfile::{NamedTempFile, PersistError};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data::{self, author::Author, book::Book, pagination::SortOrder, series::Series},
|
data::{self, author::Author, book::Book, pagination::SortOrder, series::Series},
|
||||||
search::search,
|
search::search,
|
||||||
};
|
};
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
|
|
||||||
/// Top level calibre functions, bundling all sub functions in one place and providing secure access to
|
/// Top level calibre functions, bundling all sub functions in one place and providing secure access to
|
||||||
/// the database.
|
/// the database.
|
||||||
|
@ -26,7 +26,7 @@ pub struct Calibre {
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum LoadError {
|
pub enum LoadError {
|
||||||
#[snafu(display("Failed to create database connection pool."))]
|
#[snafu(display("Failed to create database connection pool."))]
|
||||||
DbPool { source: r2d2::Error },
|
CreateDbPool { source: r2d2::Error },
|
||||||
#[snafu(display("Failed to create temporary database view."))]
|
#[snafu(display("Failed to create temporary database view."))]
|
||||||
TmpDb { source: io::Error },
|
TmpDb { source: io::Error },
|
||||||
#[snafu(display("Failed to keep temporary database from deletion."))]
|
#[snafu(display("Failed to keep temporary database from deletion."))]
|
||||||
|
@ -34,171 +34,75 @@ pub enum LoadError {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
#[snafu(display("Failed to search."))]
|
pub enum DataStoreError {
|
||||||
pub struct SearchError {
|
|
||||||
source: crate::search::SearchError,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum BooksError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
#[snafu(display("Failed to get database connection from pool."))]
|
||||||
BooksDbPool { source: r2d2::Error },
|
GetDbConn { source: r2d2::Error },
|
||||||
|
|
||||||
|
#[snafu(display("Failed to search."))]
|
||||||
|
Search { source: crate::search::SearchError },
|
||||||
|
|
||||||
#[snafu(display("Failed to fetch multiple books."))]
|
#[snafu(display("Failed to fetch multiple books."))]
|
||||||
FetchBooks {
|
MultipleBooks {
|
||||||
source: data::book::MultipleBooksError,
|
source: data::book::MultipleBooksError,
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum AuthorsError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
AuthorsDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to fetch multiple authors."))]
|
|
||||||
FetchAuthors {
|
|
||||||
source: data::author::MultipleAuthorsError,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum AuthorBooksError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
AuthorBooksDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to fetch multiple an author's books."))]
|
|
||||||
FetchAuthorBooks {
|
|
||||||
source: data::book::AuthorBooksError,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum RecentBooksError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
RecentBooksDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to fetch recent books."))]
|
#[snafu(display("Failed to fetch recent books."))]
|
||||||
FetchRecentBooks {
|
RecentBooks {
|
||||||
source: data::book::RecentBooksError,
|
source: data::book::RecentBooksError,
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum ScalarBookError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
ScalarBookDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to fetch book."))]
|
#[snafu(display("Failed to fetch book."))]
|
||||||
FetchScalarBook { source: data::book::ScalarBookError },
|
ScalarBook { source: data::book::ScalarBookError },
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum ScalarAuthorError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
ScalarAuthorDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to fetch author."))]
|
|
||||||
FetchScalarAuthor {
|
|
||||||
source: data::author::ScalarAuthorError,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum ScalarSeriesError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
ScalarSeriesDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to fetch series."))]
|
|
||||||
FetchScalarSeries {
|
|
||||||
source: data::series::ScalarSeriesError,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum BookAuthorError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
BookAuthorDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to fetch book's author."))]
|
|
||||||
FetchBookAuthor {
|
|
||||||
source: data::author::BookAuthorError,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum MultipleSeriesError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
MultipleSeriesDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to fetch multiple series."))]
|
|
||||||
FetchMultipleSeries {
|
|
||||||
source: data::series::MultiplSeriesError,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum BookSeriesError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
BookSeriesDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to get the series a book belongs to."))]
|
|
||||||
FetchBookSeries {
|
|
||||||
source: data::series::SeriesBooksError,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum SeriesBooksError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
SeriesBooksDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to get a series' books."))]
|
#[snafu(display("Failed to get a series' books."))]
|
||||||
FetchSeriesBooks { source: data::book::SeriesBookError },
|
SeriesBooks { source: data::book::SeriesBookError },
|
||||||
}
|
#[snafu(display("Failed to fetch an author's books."))]
|
||||||
|
AuthorBooks {
|
||||||
#[derive(Debug, Snafu)]
|
source: data::book::AuthorBooksError,
|
||||||
pub enum HasPreviousAuthorsError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
HasPreviousAuthorsDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to check if there are previous authors."))]
|
|
||||||
FetchHasPreviousAuthors {
|
|
||||||
source: data::author::PreviousAuthorsError,
|
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum HasMoreAuthorsError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
HasMoreAuthorsDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to check if there are previous authors."))]
|
|
||||||
FetchHasMoreAuthors {
|
|
||||||
source: data::author::MoreAuthorsError,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum HasPreviousBooksError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
HasPreviousBooksDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to check if there are previous books."))]
|
#[snafu(display("Failed to check if there are previous books."))]
|
||||||
FetchHasPreviousBooks {
|
HasPreviousBooks {
|
||||||
source: data::book::PreviousBooksError,
|
source: data::book::PreviousBooksError,
|
||||||
},
|
},
|
||||||
}
|
#[snafu(display("Failed to check if there are more books."))]
|
||||||
|
HasMoreBooks { source: data::book::MoreBooksError },
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[snafu(display("Failed to fetch multiple authors."))]
|
||||||
pub enum HasMoreBooksError {
|
MultipleAuthors {
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
source: data::author::MultipleAuthorsError,
|
||||||
HasMoreBooksDbPool { source: r2d2::Error },
|
},
|
||||||
#[snafu(display("Failed to check if there are previous books."))]
|
#[snafu(display("Failed to fetch author."))]
|
||||||
FetchHasMoreBooks { source: data::book::MoreBooksError },
|
ScalarAuthor {
|
||||||
}
|
source: data::author::ScalarAuthorError,
|
||||||
|
},
|
||||||
|
#[snafu(display("Failed to fetch book's author."))]
|
||||||
|
BookAuthor {
|
||||||
|
source: data::author::BookAuthorError,
|
||||||
|
},
|
||||||
|
#[snafu(display("Failed to check if there are previous authors."))]
|
||||||
|
HasPreviousAuthors {
|
||||||
|
source: data::author::PreviousAuthorsError,
|
||||||
|
},
|
||||||
|
#[snafu(display("Failed to check if there are more authors."))]
|
||||||
|
HasMoreAuthors {
|
||||||
|
source: data::author::MoreAuthorsError,
|
||||||
|
},
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[snafu(display("Failed to fetch multiple series."))]
|
||||||
pub enum HasPreviousSeriesError {
|
MultipleSeries {
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
source: data::series::MultiplSeriesError,
|
||||||
HasPreviousSeriesDbPool { source: r2d2::Error },
|
},
|
||||||
|
#[snafu(display("Failed to fetch series."))]
|
||||||
|
ScalarSeries {
|
||||||
|
source: data::series::ScalarSeriesError,
|
||||||
|
},
|
||||||
|
#[snafu(display("Failed to get the series a book belongs to."))]
|
||||||
|
BookSeries {
|
||||||
|
source: data::series::SeriesBooksError,
|
||||||
|
},
|
||||||
#[snafu(display("Failed to check if there are previous series."))]
|
#[snafu(display("Failed to check if there are previous series."))]
|
||||||
FetchHasPreviousSeries {
|
HasPreviousSeries {
|
||||||
source: data::series::PreviousSeriesError,
|
source: data::series::PreviousSeriesError,
|
||||||
},
|
},
|
||||||
}
|
#[snafu(display("Failed to check if there are more series."))]
|
||||||
|
HasMoreSeries {
|
||||||
#[derive(Debug, Snafu)]
|
|
||||||
pub enum HasMoreSeriesError {
|
|
||||||
#[snafu(display("Failed to get database connection from pool."))]
|
|
||||||
HasMoreSeriesDbPool { source: r2d2::Error },
|
|
||||||
#[snafu(display("Failed to check if there are previous series."))]
|
|
||||||
FetchHasMoreSeries {
|
|
||||||
source: data::series::MoreSeriesError,
|
source: data::series::MoreSeriesError,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -208,7 +112,7 @@ impl Calibre {
|
||||||
/// Fail if the database file can not be opened or not be found.
|
/// Fail if the database file can not be opened or not be found.
|
||||||
pub fn load(path: &Path) -> Result<Self, LoadError> {
|
pub fn load(path: &Path) -> Result<Self, LoadError> {
|
||||||
let manager = SqliteConnectionManager::file(path);
|
let manager = SqliteConnectionManager::file(path);
|
||||||
let pool = r2d2::Pool::new(manager).context(DbPoolSnafu)?;
|
let pool = r2d2::Pool::new(manager).context(CreateDbPoolSnafu)?;
|
||||||
|
|
||||||
let tmpfile = NamedTempFile::new().context(TmpDbSnafu)?;
|
let tmpfile = NamedTempFile::new().context(TmpDbSnafu)?;
|
||||||
let (_, search_db_path) = tmpfile.keep().context(PersistTmpDbSnafu)?;
|
let (_, search_db_path) = tmpfile.keep().context(PersistTmpDbSnafu)?;
|
||||||
|
@ -222,7 +126,7 @@ impl Calibre {
|
||||||
/// Full text search with a query.
|
/// Full text search with a query.
|
||||||
///
|
///
|
||||||
/// See https://www.sqlite.org/fts5.html#full_text_query_syntax for syntax.
|
/// See https://www.sqlite.org/fts5.html#full_text_query_syntax for syntax.
|
||||||
pub fn search(&self, query: &str) -> Result<Vec<Book>, SearchError> {
|
pub fn search(&self, query: &str) -> Result<Vec<Book>, DataStoreError> {
|
||||||
search(query, &self.pool, &self.search_db_path).context(SearchSnafu)
|
search(query, &self.pool, &self.search_db_path).context(SearchSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,9 +137,9 @@ impl Calibre {
|
||||||
limit: u64,
|
limit: u64,
|
||||||
cursor: Option<&str>,
|
cursor: Option<&str>,
|
||||||
sort_order: &SortOrder,
|
sort_order: &SortOrder,
|
||||||
) -> Result<Vec<Book>, BooksError> {
|
) -> Result<Vec<Book>, DataStoreError> {
|
||||||
let conn = self.pool.get().context(BooksDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Book::multiple(&conn, limit, cursor, sort_order).context(FetchBooksSnafu)
|
Book::multiple(&conn, limit, cursor, sort_order).context(MultipleBooksSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch author data from calibre, starting at `cursor`, fetching up to an amount of `limit` and
|
/// Fetch author data from calibre, starting at `cursor`, fetching up to an amount of `limit` and
|
||||||
|
@ -245,9 +149,9 @@ impl Calibre {
|
||||||
limit: u64,
|
limit: u64,
|
||||||
cursor: Option<&str>,
|
cursor: Option<&str>,
|
||||||
sort_order: &SortOrder,
|
sort_order: &SortOrder,
|
||||||
) -> Result<Vec<Author>, AuthorsError> {
|
) -> Result<Vec<Author>, DataStoreError> {
|
||||||
let conn = self.pool.get().context(AuthorsDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Author::multiple(&conn, limit, cursor, sort_order).context(FetchAuthorsSnafu)
|
Author::multiple(&conn, limit, cursor, sort_order).context(MultipleAuthorsSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch books for an author specified by `author_id`, paginate the books by starting at `cursor`,
|
/// Fetch books for an author specified by `author_id`, paginate the books by starting at `cursor`,
|
||||||
|
@ -258,28 +162,27 @@ impl Calibre {
|
||||||
limit: u64,
|
limit: u64,
|
||||||
cursor: Option<&str>,
|
cursor: Option<&str>,
|
||||||
sort_order: SortOrder,
|
sort_order: SortOrder,
|
||||||
) -> Result<Vec<Book>, AuthorBooksError> {
|
) -> Result<Vec<Book>, DataStoreError> {
|
||||||
let conn = self.pool.get().context(AuthorBooksDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Book::author_books(&conn, author_id, limit, cursor, sort_order)
|
Book::author_books(&conn, author_id, limit, cursor, sort_order).context(AuthorBooksSnafu)
|
||||||
.context(FetchAuthorBooksSnafu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get recent books up to a limit of `limit`.
|
/// Get recent books up to a limit of `limit`.
|
||||||
pub fn recent_books(&self, limit: u64) -> Result<Vec<Book>, RecentBooksError> {
|
pub fn recent_books(&self, limit: u64) -> Result<Vec<Book>, DataStoreError> {
|
||||||
let conn = self.pool.get().context(RecentBooksDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Book::recents(&conn, limit).context(FetchRecentBooksSnafu)
|
Book::recents(&conn, limit).context(RecentBooksSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a single book, specified `id`.
|
/// Get a single book, specified `id`.
|
||||||
pub fn scalar_book(&self, id: u64) -> Result<Book, ScalarBookError> {
|
pub fn scalar_book(&self, id: u64) -> Result<Book, DataStoreError> {
|
||||||
let conn = self.pool.get().context(ScalarBookDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Book::scalar_book(&conn, id).context(FetchScalarBookSnafu)
|
Book::scalar_book(&conn, id).context(ScalarBookSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the author to a book with id `id`.
|
/// Get the author to a book with id `id`.
|
||||||
pub fn book_author(&self, id: u64) -> Result<Author, BookAuthorError> {
|
pub fn book_author(&self, id: u64) -> Result<Author, DataStoreError> {
|
||||||
let conn = self.pool.get().context(BookAuthorDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Author::book_author(&conn, id).context(FetchBookAuthorSnafu)
|
Author::book_author(&conn, id).context(BookAuthorSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch series data from calibre, starting at `cursor`, fetching up to an amount of `limit` and
|
/// Fetch series data from calibre, starting at `cursor`, fetching up to an amount of `limit` and
|
||||||
|
@ -289,69 +192,69 @@ impl Calibre {
|
||||||
limit: u64,
|
limit: u64,
|
||||||
cursor: Option<&str>,
|
cursor: Option<&str>,
|
||||||
sort_order: &SortOrder,
|
sort_order: &SortOrder,
|
||||||
) -> Result<Vec<Series>, MultipleSeriesError> {
|
) -> Result<Vec<Series>, DataStoreError> {
|
||||||
let conn = self.pool.get().context(MultipleSeriesDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Series::multiple(&conn, limit, cursor, sort_order).context(FetchMultipleSeriesSnafu)
|
Series::multiple(&conn, limit, cursor, sort_order).context(MultipleSeriesSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the series a book with id `id` is in, as well as the book's position within the series.
|
/// Get the series a book with id `id` is in, as well as the book's position within the series.
|
||||||
pub fn book_series(&self, id: u64) -> Result<Option<(Series, f64)>, BookSeriesError> {
|
pub fn book_series(&self, id: u64) -> Result<Option<(Series, f64)>, DataStoreError> {
|
||||||
let conn = self.pool.get().context(BookSeriesDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Series::book_series(&conn, id).context(FetchBookSeriesSnafu)
|
Series::book_series(&conn, id).context(BookSeriesSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all books belonging to the series with id `id`.
|
/// Get all books belonging to the series with id `id`.
|
||||||
pub fn series_books(&self, id: u64) -> Result<Vec<Book>, SeriesBooksError> {
|
pub fn series_books(&self, id: u64) -> Result<Vec<Book>, DataStoreError> {
|
||||||
let conn = self.pool.get().context(SeriesBooksDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Book::series_books(&conn, id).context(FetchSeriesBooksSnafu)
|
Book::series_books(&conn, id).context(SeriesBooksSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if there are more authors before the specified cursor.
|
/// Check if there are more authors before the specified cursor.
|
||||||
pub fn has_previous_authors(&self, author_sort: &str) -> Result<bool, HasPreviousAuthorsError> {
|
pub fn has_previous_authors(&self, author_sort: &str) -> Result<bool, DataStoreError> {
|
||||||
let conn = self.pool.get().context(HasPreviousAuthorsDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Author::has_previous_authors(&conn, author_sort).context(FetchHasPreviousAuthorsSnafu)
|
Author::has_previous_authors(&conn, author_sort).context(HasPreviousAuthorsSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if there are more authors after the specified cursor.
|
/// Check if there are more authors after the specified cursor.
|
||||||
pub fn has_more_authors(&self, author_sort: &str) -> Result<bool, HasMoreAuthorsError> {
|
pub fn has_more_authors(&self, author_sort: &str) -> Result<bool, DataStoreError> {
|
||||||
let conn = self.pool.get().context(HasMoreAuthorsDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Author::has_more_authors(&conn, author_sort).context(FetchHasMoreAuthorsSnafu)
|
Author::has_more_authors(&conn, author_sort).context(HasMoreAuthorsSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if there are more books before the specified cursor.
|
/// Check if there are more books before the specified cursor.
|
||||||
pub fn has_previous_books(&self, book_sort: &str) -> Result<bool, HasPreviousBooksError> {
|
pub fn has_previous_books(&self, book_sort: &str) -> Result<bool, DataStoreError> {
|
||||||
let conn = self.pool.get().context(HasPreviousBooksDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Book::has_previous_books(&conn, book_sort).context(FetchHasPreviousBooksSnafu)
|
Book::has_previous_books(&conn, book_sort).context(HasPreviousBooksSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if there are more books after the specified cursor.
|
/// Check if there are more books after the specified cursor.
|
||||||
pub fn has_more_books(&self, book_sort: &str) -> Result<bool, HasMoreBooksError> {
|
pub fn has_more_books(&self, book_sort: &str) -> Result<bool, DataStoreError> {
|
||||||
let conn = self.pool.get().context(HasMoreBooksDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Book::has_more_books(&conn, book_sort).context(FetchHasMoreBooksSnafu)
|
Book::has_more_books(&conn, book_sort).context(HasMoreBooksSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if there are more series before the specified cursor.
|
/// Check if there are more series before the specified cursor.
|
||||||
pub fn has_previous_series(&self, series_sort: &str) -> Result<bool, HasPreviousSeriesError> {
|
pub fn has_previous_series(&self, series_sort: &str) -> Result<bool, DataStoreError> {
|
||||||
let conn = self.pool.get().context(HasPreviousSeriesDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Series::has_previous_series(&conn, series_sort).context(FetchHasPreviousSeriesSnafu)
|
Series::has_previous_series(&conn, series_sort).context(HasPreviousSeriesSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if there are more series after the specified cursor.
|
/// Check if there are more series after the specified cursor.
|
||||||
pub fn has_more_series(&self, series_sort: &str) -> Result<bool, HasMoreSeriesError> {
|
pub fn has_more_series(&self, series_sort: &str) -> Result<bool, DataStoreError> {
|
||||||
let conn = self.pool.get().context(HasMoreSeriesDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Series::has_more_series(&conn, series_sort).context(FetchHasMoreSeriesSnafu)
|
Series::has_more_series(&conn, series_sort).context(HasMoreSeriesSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch a single author with id `id`.
|
/// Fetch a single author with id `id`.
|
||||||
pub fn scalar_author(&self, id: u64) -> Result<Author, ScalarAuthorError> {
|
pub fn scalar_author(&self, id: u64) -> Result<Author, DataStoreError> {
|
||||||
let conn = self.pool.get().context(ScalarAuthorDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Author::scalar_author(&conn, id).context(FetchScalarAuthorSnafu)
|
Author::scalar_author(&conn, id).context(ScalarAuthorSnafu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch a single series with id `id`.
|
/// Fetch a single series with id `id`.
|
||||||
pub fn scalar_series(&self, id: u64) -> Result<Series, ScalarSeriesError> {
|
pub fn scalar_series(&self, id: u64) -> Result<Series, DataStoreError> {
|
||||||
let conn = self.pool.get().context(ScalarSeriesDbPoolSnafu)?;
|
let conn = self.pool.get().context(GetDbConnSnafu)?;
|
||||||
Series::scalar_series(&conn, id).context(FetchScalarSeriesSnafu)
|
Series::scalar_series(&conn, id).context(ScalarSeriesSnafu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
calibre-db/src/data.rs
Normal file
5
calibre-db/src/data.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
pub mod author;
|
||||||
|
pub mod book;
|
||||||
|
pub mod error;
|
||||||
|
pub mod pagination;
|
||||||
|
pub mod series;
|
|
@ -1,10 +1,11 @@
|
||||||
//! Author data.
|
//! Author data.
|
||||||
|
|
||||||
use super::pagination::{HasPrevOrMoreError, Pagination, PaginationError, SortOrder};
|
|
||||||
use rusqlite::{Connection, Row, named_params};
|
use rusqlite::{Connection, Row, named_params};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
|
use super::pagination::{HasPrevOrMoreError, Pagination, PaginationError, SortOrder};
|
||||||
|
|
||||||
/// Author in calibre.
|
/// Author in calibre.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct Author {
|
pub struct Author {
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
use rusqlite::{Connection, Row, named_params};
|
use rusqlite::{Connection, Row, named_params};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use super::pagination::{HasPrevOrMoreError, Pagination, PaginationError, SortOrder};
|
use super::pagination::{HasPrevOrMoreError, Pagination, PaginationError, SortOrder};
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
|
|
||||||
/// Book in calibre.
|
/// Book in calibre.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
use rusqlite::{Connection, Row, named_params};
|
use rusqlite::{Connection, Row, named_params};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
use super::pagination::{HasPrevOrMoreError, Pagination, PaginationError, SortOrder};
|
use super::pagination::{HasPrevOrMoreError, Pagination, PaginationError, SortOrder};
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
|
|
||||||
/// Series in calibre.
|
/// Series in calibre.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
|
|
@ -1,13 +1,6 @@
|
||||||
//! Read data from a calibre library, leveraging its SQLite metadata database.
|
//! Read data from a calibre library, leveraging its SQLite metadata database.
|
||||||
|
|
||||||
pub mod calibre;
|
pub mod calibre;
|
||||||
pub mod search;
|
|
||||||
|
|
||||||
/// Data structs for the calibre database.
|
/// Data structs for the calibre database.
|
||||||
pub mod data {
|
pub mod data;
|
||||||
pub mod author;
|
pub mod search;
|
||||||
pub mod book;
|
|
||||||
pub mod error;
|
|
||||||
pub mod pagination;
|
|
||||||
pub mod series;
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use ignore::Walk;
|
use ignore::Walk;
|
||||||
use zip::{write::SimpleFileOptions, CompressionMethod};
|
use zip::{CompressionMethod, write::SimpleFileOptions};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let out_dir = env::var("OUT_DIR")?;
|
let out_dir = env::var("OUT_DIR")?;
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use calibre_db::{
|
use calibre_db::{
|
||||||
calibre::{AuthorBooksError, Calibre, ScalarAuthorError},
|
calibre::{Calibre, DataStoreError},
|
||||||
data::author::Author,
|
data::author::Author,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::data::book::Book;
|
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
use super::SortOrder;
|
use super::SortOrder;
|
||||||
|
use crate::data::book::Book;
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum SingleAuthorError {
|
pub enum SingleAuthorError {
|
||||||
#[snafu(display("Failed to fetch author data."))]
|
#[snafu(display("Failed to fetch author data."))]
|
||||||
AuthorData { source: ScalarAuthorError },
|
AuthorData { source: DataStoreError },
|
||||||
#[snafu(display("Failed to fetch books from author."))]
|
#[snafu(display("Failed to fetch books from author."))]
|
||||||
BookData { source: AuthorBooksError },
|
BookData { source: DataStoreError },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn single(
|
pub async fn single(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use calibre_db::calibre::{Calibre, RecentBooksError};
|
use calibre_db::calibre::{Calibre, DataStoreError};
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
use crate::data::book::Book;
|
use crate::data::book::Book;
|
||||||
|
@ -8,7 +8,7 @@ use crate::data::book::Book;
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum RecentBooksError {
|
pub enum RecentBooksError {
|
||||||
#[snafu(display("Failed to fetch recent books."))]
|
#[snafu(display("Failed to fetch recent books."))]
|
||||||
RecentBooks { source: RecentBooksError },
|
RecentBooks { source: DataStoreError },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn recent(calibre: &Calibre, library_path: &Path) -> Result<Vec<Book>, RecentBooksError> {
|
pub async fn recent(calibre: &Calibre, library_path: &Path) -> Result<Vec<Book>, RecentBooksError> {
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
response::{Html, IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
|
use tera::Context;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::{
|
||||||
SortOrder, TAG,
|
SortOrder, TAG,
|
||||||
|
@ -11,13 +19,6 @@ use crate::{
|
||||||
http_error,
|
http_error,
|
||||||
templates::TEMPLATES,
|
templates::TEMPLATES,
|
||||||
};
|
};
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::StatusCode,
|
|
||||||
response::{Html, IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
use tera::Context;
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum RetrieveError {
|
pub enum RetrieveError {
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
use std::{io, sync::Arc};
|
use std::{io, sync::Arc};
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
response::Response,
|
||||||
|
};
|
||||||
|
use calibre_db::calibre::DataStoreError;
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
|
use tokio::fs::File;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::{
|
||||||
SortOrder, TAG, download,
|
SortOrder, TAG, download,
|
||||||
|
@ -11,14 +20,6 @@ use crate::{
|
||||||
http_error,
|
http_error,
|
||||||
opds::media_type::MediaType,
|
opds::media_type::MediaType,
|
||||||
};
|
};
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::StatusCode,
|
|
||||||
response::Response,
|
|
||||||
};
|
|
||||||
use calibre_db::calibre::ScalarBookError;
|
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
use tokio::fs::File;
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum RetrieveError {
|
pub enum RetrieveError {
|
||||||
|
@ -102,7 +103,7 @@ async fn books(
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum DownloadError {
|
pub enum DownloadError {
|
||||||
#[snafu(display("Failed to fetch book data."))]
|
#[snafu(display("Failed to fetch book data."))]
|
||||||
BookData { source: ScalarBookError },
|
BookData { source: DataStoreError },
|
||||||
#[snafu(display("No such book."))]
|
#[snafu(display("No such book."))]
|
||||||
NotFound,
|
NotFound,
|
||||||
#[snafu(display("No such book."))]
|
#[snafu(display("No such book."))]
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
|
use std::{fs::File, io, path::Path as FilePath, sync::Arc};
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::Response,
|
response::Response,
|
||||||
};
|
};
|
||||||
use calibre_db::calibre::{Calibre, ScalarBookError};
|
use calibre_db::calibre::{Calibre, DataStoreError};
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
use std::{fs::File, io, path::Path as FilePath, sync::Arc};
|
|
||||||
use tokio::fs::File as AsyncFile;
|
use tokio::fs::File as AsyncFile;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -89,7 +90,7 @@ pub async fn full(
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum CoverError {
|
pub enum CoverError {
|
||||||
#[snafu(display("Failed to fetch book data."))]
|
#[snafu(display("Failed to fetch book data."))]
|
||||||
BookData { source: ScalarBookError },
|
BookData { source: DataStoreError },
|
||||||
#[snafu(display("No such cover"))]
|
#[snafu(display("No such cover"))]
|
||||||
NotFound { source: CoverFetchError },
|
NotFound { source: CoverFetchError },
|
||||||
#[snafu(display("Failed to fetch cover thumbnail."))]
|
#[snafu(display("Failed to fetch cover thumbnail."))]
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::StatusCode,
|
||||||
|
response::{Html, IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
|
use tera::Context;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{
|
api::{
|
||||||
SortOrder, TAG,
|
SortOrder, TAG,
|
||||||
|
@ -11,13 +19,6 @@ use crate::{
|
||||||
http_error,
|
http_error,
|
||||||
templates::TEMPLATES,
|
templates::TEMPLATES,
|
||||||
};
|
};
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::StatusCode,
|
|
||||||
response::{Html, IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
use tera::Context;
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum RetrieveError {
|
pub enum RetrieveError {
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::{StatusCode, header},
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use calibre_db::{calibre::DataStoreError, data::author::Author as DbAuthor};
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
APP_NAME,
|
APP_NAME,
|
||||||
api::{
|
api::{
|
||||||
|
@ -14,19 +23,11 @@ use crate::{
|
||||||
relation::Relation,
|
relation::Relation,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::{StatusCode, header},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use calibre_db::{calibre::AuthorsError, data::author::Author as DbAuthor};
|
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
use time::OffsetDateTime;
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum AuthorsError {
|
pub enum AuthorsError {
|
||||||
#[snafu(display("Failed to fetch author data."))]
|
#[snafu(display("Failed to fetch author data."))]
|
||||||
Data { source: AuthorsError },
|
Data { source: DataStoreError },
|
||||||
#[snafu(display("Failed to render author data."))]
|
#[snafu(display("Failed to render author data."))]
|
||||||
Render { source: AsXmlError },
|
Render { source: AsXmlError },
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
extract::State,
|
||||||
|
http::{StatusCode, header},
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use calibre_db::calibre::DataStoreError;
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
APP_NAME,
|
APP_NAME,
|
||||||
api::{
|
api::{
|
||||||
|
@ -14,19 +23,11 @@ use crate::{
|
||||||
relation::Relation,
|
relation::Relation,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use axum::{
|
|
||||||
extract::State,
|
|
||||||
http::{StatusCode, header},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use calibre_db::calibre::BooksError;
|
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
use time::OffsetDateTime;
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum OdpsBooksError {
|
pub enum OdpsBooksError {
|
||||||
#[snafu(display("Failed to fetch book data."))]
|
#[snafu(display("Failed to fetch book data."))]
|
||||||
Data { source: BooksError },
|
Data { source: DataStoreError },
|
||||||
#[snafu(display("Failed to render book data."))]
|
#[snafu(display("Failed to render book data."))]
|
||||||
Render { source: RenderError },
|
Render { source: RenderError },
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
extract::State,
|
||||||
|
http::{StatusCode, header},
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
APP_NAME,
|
APP_NAME,
|
||||||
api::{
|
api::{
|
||||||
|
@ -14,13 +22,6 @@ use crate::{
|
||||||
relation::Relation,
|
relation::Relation,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use axum::{
|
|
||||||
extract::State,
|
|
||||||
http::{StatusCode, header},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
use time::OffsetDateTime;
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum RecentError {
|
pub enum RecentError {
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
extract::{Query, State},
|
||||||
|
http::{StatusCode, header},
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
|
use super::books::{RenderError, render_books};
|
||||||
use crate::{
|
use crate::{
|
||||||
APP_NAME,
|
APP_NAME,
|
||||||
api::{
|
api::{
|
||||||
|
@ -14,15 +23,6 @@ use crate::{
|
||||||
search::{OpenSearchDescription, Url},
|
search::{OpenSearchDescription, Url},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use axum::{
|
|
||||||
extract::{Query, State},
|
|
||||||
http::{StatusCode, header},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use serde::Deserialize;
|
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
|
|
||||||
use super::books::{RenderError, render_books};
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum SearchError {
|
pub enum SearchError {
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use axum::{
|
||||||
|
extract::{Path, State},
|
||||||
|
http::{StatusCode, header},
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use calibre_db::calibre::DataStoreError;
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
APP_NAME,
|
APP_NAME,
|
||||||
api::{
|
api::{
|
||||||
|
@ -14,19 +23,11 @@ use crate::{
|
||||||
relation::Relation,
|
relation::Relation,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use axum::{
|
|
||||||
extract::{Path, State},
|
|
||||||
http::{StatusCode, header},
|
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use calibre_db::calibre::MultipleSeriesError;
|
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
use time::OffsetDateTime;
|
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum SeriesError {
|
pub enum SeriesError {
|
||||||
#[snafu(display("Failed to fetch series data."))]
|
#[snafu(display("Failed to fetch series data."))]
|
||||||
Data { source: MultipleSeriesError },
|
Data { source: DataStoreError },
|
||||||
#[snafu(display("Failed to render series data."))]
|
#[snafu(display("Failed to render series data."))]
|
||||||
Render { source: AsXmlError },
|
Render { source: AsXmlError },
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
//! Deal with cursor pagination.
|
//! Deal with cursor pagination.
|
||||||
|
|
||||||
use crate::templates::TEMPLATES;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use axum::response::{Html, IntoResponse, Response};
|
use axum::response::{Html, IntoResponse, Response};
|
||||||
use calibre_db::data::error::DataStoreError;
|
use calibre_db::calibre::DataStoreError;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
use std::fmt::Debug;
|
|
||||||
use tera::Context;
|
use tera::Context;
|
||||||
|
|
||||||
|
use crate::templates::TEMPLATES;
|
||||||
|
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
pub enum PaginationError {
|
pub enum PaginationError {
|
||||||
#[snafu(display("Failed to fetch pagination data."))]
|
#[snafu(display("Failed to fetch pagination data."))]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use calibre_db::{calibre::Calibre, data::error::DataStoreError};
|
use calibre_db::calibre::{Calibre, DataStoreError};
|
||||||
|
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
use crate::data::book::Book;
|
use crate::data::book::Book;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use calibre_db::{
|
use calibre_db::{
|
||||||
calibre::Calibre,
|
calibre::{Calibre, DataStoreError},
|
||||||
data::{error::DataStoreError, series::Series},
|
data::series::Series,
|
||||||
};
|
};
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
|
fmt::Write,
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io,
|
io,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
@ -12,7 +13,6 @@ use sha2::{
|
||||||
digest::{generic_array::GenericArray, typenum::U32},
|
digest::{generic_array::GenericArray, typenum::U32},
|
||||||
};
|
};
|
||||||
use snafu::{ResultExt, Snafu};
|
use snafu::{ResultExt, Snafu};
|
||||||
use std::fmt::Write;
|
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
/// Errors from converting a hash to its string representation.
|
/// Errors from converting a hash to its string representation.
|
||||||
|
|
|
@ -2,15 +2,14 @@
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env, fs, io,
|
env, fs, io,
|
||||||
net::SocketAddr,
|
net::{SocketAddr, ToSocketAddrs},
|
||||||
net::ToSocketAddrs,
|
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use snafu::{ResultExt, Snafu};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use crate::cli::Cli;
|
use crate::cli::Cli;
|
||||||
use snafu::{ResultExt, Snafu};
|
|
||||||
|
|
||||||
/// Errors from loading application configuration.
|
/// Errors from loading application configuration.
|
||||||
#[derive(Debug, Snafu)]
|
#[derive(Debug, Snafu)]
|
||||||
|
|
|
@ -33,6 +33,9 @@ mod tests {
|
||||||
fn serialize() {
|
fn serialize() {
|
||||||
let author = init();
|
let author = init();
|
||||||
let xml = to_string(&author).unwrap();
|
let xml = to_string(&author).unwrap();
|
||||||
assert_eq!(xml, "<author><name>Rohal der Weise</name><uri>https://de.wiki-aventurica.de/wiki/Rohal_der_Weise</uri><email>rohal@aventurien.de</email></author>");
|
assert_eq!(
|
||||||
|
xml,
|
||||||
|
"<author><name>Rohal der Weise</name><uri>https://de.wiki-aventurica.de/wiki/Rohal_der_Weise</uri><email>rohal@aventurien.de</email></author>"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,10 @@ use calibre_db::data::{author::Author as DbAuthor, series::Series};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use crate::{data::book::Book, APP_NAME};
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
author::Author, content::Content, link::Link, media_type::MediaType, relation::Relation,
|
author::Author, content::Content, link::Link, media_type::MediaType, relation::Relation,
|
||||||
};
|
};
|
||||||
|
use crate::{APP_NAME, data::book::Book};
|
||||||
|
|
||||||
/// Fundamental piece of OPDS, holding information about entries (for example a book).
|
/// Fundamental piece of OPDS, holding information about entries (for example a book).
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
@ -126,9 +125,8 @@ mod tests {
|
||||||
use quick_xml::se::to_string;
|
use quick_xml::se::to_string;
|
||||||
use time::macros::datetime;
|
use time::macros::datetime;
|
||||||
|
|
||||||
use crate::opds::{content::Content, media_type::MediaType, relation::Relation};
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::opds::{content::Content, media_type::MediaType, relation::Relation};
|
||||||
|
|
||||||
fn init() -> Entry {
|
fn init() -> Entry {
|
||||||
Entry {
|
Entry {
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::data::book::{Book, Format};
|
|
||||||
|
|
||||||
use super::{media_type::MediaType, relation::Relation};
|
use super::{media_type::MediaType, relation::Relation};
|
||||||
|
use crate::data::book::{Book, Format};
|
||||||
|
|
||||||
/// Link element in OPDS.
|
/// Link element in OPDS.
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
@ -32,13 +31,13 @@ pub struct Link {
|
||||||
/// Convert a format from a book into a link where it is downloadable.
|
/// Convert a format from a book into a link where it is downloadable.
|
||||||
impl From<(&Book, (&Format, &str))> for Link {
|
impl From<(&Book, (&Format, &str))> for Link {
|
||||||
fn from(value: (&Book, (&Format, &str))) -> Self {
|
fn from(value: (&Book, (&Format, &str))) -> Self {
|
||||||
let format = value.1 .0.clone();
|
let format = value.1.0.clone();
|
||||||
let media_type: MediaType = format.into();
|
let media_type: MediaType = format.into();
|
||||||
Self {
|
Self {
|
||||||
href: format!("/book/{}/{}", value.0.data.id, value.1 .0),
|
href: format!("/book/{}/{}", value.0.data.id, value.1.0),
|
||||||
media_type,
|
media_type,
|
||||||
rel: media_type.into(),
|
rel: media_type.into(),
|
||||||
title: Some(value.1 .0 .0.clone()),
|
title: Some(value.1.0.0.clone()),
|
||||||
count: None,
|
count: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@ use quick_xml::{
|
||||||
se::to_string,
|
se::to_string,
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use snafu::ResultExt;
|
||||||
|
|
||||||
use super::error::{
|
use super::error::{
|
||||||
AsXmlError, BytesToUtf8Snafu, ReadXmlEventSnafu, ToStringSnafu, WriteXmlEventSnafu,
|
AsXmlError, BytesToUtf8Snafu, ReadXmlEventSnafu, ToStringSnafu, WriteXmlEventSnafu,
|
||||||
};
|
};
|
||||||
use snafu::ResultExt;
|
|
||||||
|
|
||||||
/// Url pointing to a location.
|
/// Url pointing to a location.
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue