some docs

This commit is contained in:
Sebastian Hugentobler 2025-07-02 21:51:46 +02:00
parent c067088a32
commit 1314320260
Signed by: shu
SSH key fingerprint: SHA256:ppcx6MlixdNZd5EUM1nkHOKoyQYoJwzuQKXM6J/t66M
6 changed files with 58 additions and 3 deletions

View file

@ -24,83 +24,107 @@ pub struct Calibre {
} }
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when loading the calibre database.
pub enum LoadError { pub enum LoadError {
/// A failure to create the database connection pool.
#[snafu(display("Failed to create database connection pool."))] #[snafu(display("Failed to create database connection pool."))]
CreateDbPool { source: r2d2::Error }, CreateDbPool { source: r2d2::Error },
/// A failure to create the temporary database view.
#[snafu(display("Failed to create temporary database view."))] #[snafu(display("Failed to create temporary database view."))]
TmpDb { source: io::Error }, TmpDb { source: io::Error },
/// A failure to keep the temporary database from being deleted.
#[snafu(display("Failed to keep temporary database from deletion."))] #[snafu(display("Failed to keep temporary database from deletion."))]
PersistTmpDb { source: PersistError }, PersistTmpDb { source: PersistError },
} }
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when accessing the data store.
pub enum DataStoreError { pub enum DataStoreError {
/// A failure to get a database connection from the pool.
#[snafu(display("Failed to get database connection from pool."))] #[snafu(display("Failed to get database connection from pool."))]
GetDbConn { source: r2d2::Error }, GetDbConn { source: r2d2::Error },
/// A failure during a search operation.
#[snafu(display("Failed to search."))] #[snafu(display("Failed to search."))]
Search { source: crate::search::SearchError }, Search { source: crate::search::SearchError },
/// A failure to fetch multiple books.
#[snafu(display("Failed to fetch multiple books."))] #[snafu(display("Failed to fetch multiple books."))]
MultipleBooks { MultipleBooks {
source: data::book::MultipleBooksError, source: data::book::MultipleBooksError,
}, },
/// A failure to fetch recent books.
#[snafu(display("Failed to fetch recent books."))] #[snafu(display("Failed to fetch recent books."))]
RecentBooks { RecentBooks {
source: data::book::RecentBooksError, source: data::book::RecentBooksError,
}, },
/// A failure to fetch a single book.
#[snafu(display("Failed to fetch book."))] #[snafu(display("Failed to fetch book."))]
ScalarBook { source: data::book::ScalarBookError }, ScalarBook { source: data::book::ScalarBookError },
/// A failure to get a series' books.
#[snafu(display("Failed to get a series' books."))] #[snafu(display("Failed to get a series' books."))]
SeriesBooks { source: data::book::SeriesBookError }, SeriesBooks { source: data::book::SeriesBookError },
/// A failure to fetch an author's books.
#[snafu(display("Failed to fetch an author's books."))] #[snafu(display("Failed to fetch an author's books."))]
AuthorBooks { AuthorBooks {
source: data::book::AuthorBooksError, source: data::book::AuthorBooksError,
}, },
/// A failure to check for previous books.
#[snafu(display("Failed to check if there are previous books."))] #[snafu(display("Failed to check if there are previous books."))]
HasPreviousBooks { HasPreviousBooks {
source: data::book::PreviousBooksError, source: data::book::PreviousBooksError,
}, },
/// A failure to check for more books.
#[snafu(display("Failed to check if there are more books."))] #[snafu(display("Failed to check if there are more books."))]
HasMoreBooks { source: data::book::MoreBooksError }, HasMoreBooks { source: data::book::MoreBooksError },
/// A failure to fetch multiple authors.
#[snafu(display("Failed to fetch multiple authors."))] #[snafu(display("Failed to fetch multiple authors."))]
MultipleAuthors { MultipleAuthors {
source: data::author::MultipleAuthorsError, source: data::author::MultipleAuthorsError,
}, },
/// A failure to fetch a single author.
#[snafu(display("Failed to fetch author."))] #[snafu(display("Failed to fetch author."))]
ScalarAuthor { ScalarAuthor {
source: data::author::ScalarAuthorError, source: data::author::ScalarAuthorError,
}, },
/// A failure to fetch a book's author.
#[snafu(display("Failed to fetch book's author."))] #[snafu(display("Failed to fetch book's author."))]
BookAuthor { BookAuthor {
source: data::author::BookAuthorError, source: data::author::BookAuthorError,
}, },
/// A failure to check for previous authors.
#[snafu(display("Failed to check if there are previous authors."))] #[snafu(display("Failed to check if there are previous authors."))]
HasPreviousAuthors { HasPreviousAuthors {
source: data::author::PreviousAuthorsError, source: data::author::PreviousAuthorsError,
}, },
/// A failure to check for more authors.
#[snafu(display("Failed to check if there are more authors."))] #[snafu(display("Failed to check if there are more authors."))]
HasMoreAuthors { HasMoreAuthors {
source: data::author::MoreAuthorsError, source: data::author::MoreAuthorsError,
}, },
/// A failure to fetch multiple series.
#[snafu(display("Failed to fetch multiple series."))] #[snafu(display("Failed to fetch multiple series."))]
MultipleSeries { MultipleSeries {
source: data::series::MultiplSeriesError, source: data::series::MultiplSeriesError,
}, },
/// A failure to fetch a single series.
#[snafu(display("Failed to fetch series."))] #[snafu(display("Failed to fetch series."))]
ScalarSeries { ScalarSeries {
source: data::series::ScalarSeriesError, source: data::series::ScalarSeriesError,
}, },
/// A failure to get the series a book belongs to.
#[snafu(display("Failed to get the series a book belongs to."))] #[snafu(display("Failed to get the series a book belongs to."))]
BookSeries { BookSeries {
source: data::series::SeriesBooksError, source: data::series::SeriesBooksError,
}, },
/// A failure to check for previous series.
#[snafu(display("Failed to check if there are previous series."))] #[snafu(display("Failed to check if there are previous series."))]
HasPreviousSeries { HasPreviousSeries {
source: data::series::PreviousSeriesError, source: data::series::PreviousSeriesError,
}, },
/// A failure to check for more series.
#[snafu(display("Failed to check if there are more series."))] #[snafu(display("Failed to check if there are more series."))]
HasMoreSeries { HasMoreSeries {
source: data::series::MoreSeriesError, source: data::series::MoreSeriesError,

View file

@ -26,17 +26,23 @@ pub struct Pagination<'a> {
} }
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when checking for previous or more items.
pub enum HasPrevOrMoreError { pub enum HasPrevOrMoreError {
/// A failure to prepare the SQL statement.
#[snafu(display("Failed to prepare statement."))] #[snafu(display("Failed to prepare statement."))]
PrepareHasPrevOrMore { source: rusqlite::Error }, PrepareHasPrevOrMore { source: rusqlite::Error },
/// A failure to execute the SQL statement.
#[snafu(display("Failed to execute statement."))] #[snafu(display("Failed to execute statement."))]
ExecuteHasPrevOrMore { source: rusqlite::Error }, ExecuteHasPrevOrMore { source: rusqlite::Error },
} }
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur during pagination.
pub enum PaginationError { pub enum PaginationError {
/// A failure to prepare the SQL statement.
#[snafu(display("Failed to prepare statement."))] #[snafu(display("Failed to prepare statement."))]
PreparePagination { source: rusqlite::Error }, PreparePagination { source: rusqlite::Error },
/// A failure to execute the SQL statement.
#[snafu(display("Failed to execute statement."))] #[snafu(display("Failed to execute statement."))]
ExecutePagination { source: rusqlite::Error }, ExecutePagination { source: rusqlite::Error },
} }

View file

@ -8,7 +8,9 @@ use tokio::io::AsyncRead;
use tokio_util::io::ReaderStream; use tokio_util::io::ReaderStream;
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when downloading a file.
pub enum DownloadError { pub enum DownloadError {
/// A failure to construct the response body.
#[snafu(display("Failed to fetch cover."))] #[snafu(display("Failed to fetch cover."))]
Body { source: http::Error }, Body { source: http::Error },
} }

View file

@ -1,3 +1,4 @@
//! Handle requests for books.
use std::{io, sync::Arc}; use std::{io, sync::Arc};
use axum::{ use axum::{
@ -22,7 +23,9 @@ use crate::{
}; };
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when retrieving books.
pub enum RetrieveError { pub enum RetrieveError {
/// A failure to fetch pagination data.
#[snafu(display("Failed to fetch pagination data."))] #[snafu(display("Failed to fetch pagination data."))]
Books { source: BookError }, Books { source: BookError },
} }
@ -69,11 +72,14 @@ pub async fn handler(
} }
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when fetching a book.
pub enum BookError { pub enum BookError {
/// A failure to fetch pagination data.
#[snafu(display("Failed to fetch pagination data."))] #[snafu(display("Failed to fetch pagination data."))]
Pagination { source: PaginationError }, Pagination { source: PaginationError },
} }
/// Render a paginated list of books.
async fn books( async fn books(
state: &Arc<AppState>, state: &Arc<AppState>,
cursor: Option<&str>, cursor: Option<&str>,
@ -101,13 +107,18 @@ async fn books(
} }
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when downloading a book.
pub enum DownloadError { pub enum DownloadError {
/// A failure to fetch book data.
#[snafu(display("Failed to fetch book data."))] #[snafu(display("Failed to fetch book data."))]
BookData { source: DataStoreError }, BookData { source: DataStoreError },
/// The requested book was not found.
#[snafu(display("No such book."))] #[snafu(display("No such book."))]
NotFound, NotFound,
/// The requested book file was not found.
#[snafu(display("No such book."))] #[snafu(display("No such book."))]
FileNotFound { source: io::Error }, FileNotFound { source: io::Error },
/// A failure to stream the book file.
#[snafu(display("Failed to stream book file."))] #[snafu(display("Failed to stream book file."))]
Stream { source: download::DownloadError }, Stream { source: download::DownloadError },
} }

View file

@ -1,3 +1,4 @@
//! Handle requests for book covers.
use std::{fs::File, io, path::Path as FilePath, sync::Arc}; use std::{fs::File, io, path::Path as FilePath, sync::Arc};
use axum::{ use axum::{
@ -21,9 +22,12 @@ use crate::{
}; };
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when retrieving a cover.
pub enum RetrieveError { pub enum RetrieveError {
/// A failure to fetch the cover.
#[snafu(display("Failed to fetch cover."))] #[snafu(display("Failed to fetch cover."))]
Cover { source: CoverError }, Cover { source: CoverError },
/// A failure to open the cover file.
#[snafu(display("Failed to open cover."))] #[snafu(display("Failed to open cover."))]
CoverOpen { source: io::Error }, CoverOpen { source: io::Error },
} }
@ -88,23 +92,31 @@ pub async fn full(
} }
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when fetching a cover.
pub enum CoverError { pub enum CoverError {
/// A failure to fetch book data.
#[snafu(display("Failed to fetch book data."))] #[snafu(display("Failed to fetch book data."))]
BookData { source: DataStoreError }, BookData { source: DataStoreError },
/// The requested cover was not found.
#[snafu(display("No such cover"))] #[snafu(display("No such cover"))]
NotFound { source: CoverFetchError }, NotFound { source: CoverFetchError },
#[snafu(display("Failed to fetch cover thumbnail."))] /// A failure to stream the cover.
#[snafu(display("Failed to stream cover."))]
StreamCover { source: DownloadError }, StreamCover { source: DownloadError },
} }
#[derive(Debug, Snafu)] #[derive(Debug, Snafu)]
/// Errors that can occur when fetching a cover file.
pub enum CoverFetchError { pub enum CoverFetchError {
/// A failure to fetch the cover thumbnail.
#[snafu(display("Failed to fetch cover thumbnail."))] #[snafu(display("Failed to fetch cover thumbnail."))]
Thumbnail { source: RetrieveThumbnailError }, Thumbnail { source: RetrieveThumbnailError },
/// A failure to open the cover file.
#[snafu(display("Failed to open cover file."))] #[snafu(display("Failed to open cover file."))]
FileOpen { source: io::Error }, FileOpen { source: io::Error },
} }
/// Generic cover handler.
async fn cover<F>( async fn cover<F>(
calibre: &Calibre, calibre: &Calibre,
library_path: &FilePath, library_path: &FilePath,

View file

@ -21,9 +21,9 @@ pub mod data;
pub mod opds; pub mod opds;
pub mod templates; pub mod templates;
// App name from Cargo.toml /// The application name.
const APP_NAME: &str = env!("CARGO_PKG_NAME"); const APP_NAME: &str = env!("CARGO_PKG_NAME");
// Version from Cargo.toml /// The application version.
const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
/// Internal marker data in lieu of a proper `Accept` header. /// Internal marker data in lieu of a proper `Accept` header.