feat: add series support for book organization

API:
- Add /libraries/{id}/series endpoint to list series with book counts
- Add series filter to /books endpoint
- Fix SeriesItem to return first_book_id properly (using CTE with ROW_NUMBER)

Indexer:
- Parse series from parent folder name relative to library root
- Store series in database when indexing books

Backoffice:
- Add Books page with grid view, search, and pagination
- Add Series page showing series with cover images
- Add Library books page filtered by series
- Add book detail page
- Add Series column in libraries list with clickable link
- Create BookCard component for reusable book display
- Add CSS styles for books grid, series grid, and book details
- Add proxy API route for book cover images (fixing CORS issues)

Parser:
- Add series field to ParsedMetadata
- Extract series from file path relative to library root

Books without a parent folder are categorized as 'unclassified' series.
This commit is contained in:
2026-03-05 22:58:28 +01:00
parent 3ad1d57db6
commit d33a4b02d8
12 changed files with 944 additions and 16 deletions

View File

@@ -21,6 +21,7 @@ impl BookFormat {
#[derive(Debug, Clone)]
pub struct ParsedMetadata {
pub title: String,
pub series: Option<String>,
pub page_count: Option<i32>,
}
@@ -34,23 +35,47 @@ pub fn detect_format(path: &Path) -> Option<BookFormat> {
}
}
pub fn parse_metadata(path: &Path, format: BookFormat) -> Result<ParsedMetadata> {
pub fn parse_metadata(
path: &Path,
format: BookFormat,
library_root: &Path,
) -> Result<ParsedMetadata> {
let title = path
.file_stem()
.map(|s| s.to_string_lossy().to_string())
.unwrap_or_else(|| "Untitled".to_string());
// Determine series from parent folder relative to library root
let series = path.parent().and_then(|parent| {
// Get the relative path from library root to parent
let relative = parent.strip_prefix(library_root).ok()?;
// If relative path is not empty, use first component as series
let first_component = relative.components().next()?;
let series_name = first_component.as_os_str().to_string_lossy().to_string();
// Only if series_name is not empty
if series_name.is_empty() {
None
} else {
Some(series_name)
}
});
let page_count = match format {
BookFormat::Cbz => parse_cbz_page_count(path).ok(),
BookFormat::Cbr => parse_cbr_page_count(path).ok(),
BookFormat::Pdf => parse_pdf_page_count(path).ok(),
};
Ok(ParsedMetadata { title, page_count })
Ok(ParsedMetadata {
title,
series,
page_count,
})
}
fn parse_cbz_page_count(path: &Path) -> Result<i32> {
let file = std::fs::File::open(path).with_context(|| format!("cannot open cbz: {}", path.display()))?;
let file = std::fs::File::open(path)
.with_context(|| format!("cannot open cbz: {}", path.display()))?;
let mut archive = zip::ZipArchive::new(file).context("invalid cbz archive")?;
let mut count: i32 = 0;
for i in 0..archive.len() {
@@ -83,7 +108,8 @@ fn parse_cbr_page_count(path: &Path) -> Result<i32> {
}
fn parse_pdf_page_count(path: &Path) -> Result<i32> {
let doc = lopdf::Document::load(path).with_context(|| format!("cannot open pdf: {}", path.display()))?;
let doc = lopdf::Document::load(path)
.with_context(|| format!("cannot open pdf: {}", path.display()))?;
Ok(doc.get_pages().len() as i32)
}