fix(ebooks): route targeted files through ebook scanner

This commit is contained in:
rxwatcher
2026-07-22 13:43:57 +02:00
parent b1545ae9f9
commit 7f3b93d1b4
2 changed files with 25 additions and 0 deletions
+6
View File
@@ -1981,6 +1981,12 @@ func (s *Scanner) ScanFile(ctx context.Context, filePath string, folder *models.
}
return s.syncFolderScopedAudioLibraryState(ctx, folder.ID)
}
if librarykind.IsEbook(folder.Type) {
if !SupportsEbookFile(cleanFile) {
return fmt.Errorf("unrecognized ebook extension: %s", strings.ToLower(filepath.Ext(cleanFile)))
}
return s.scanEbookPaths(ctx, folder, []string{cleanFile}, false)
}
// Verify the file extension is recognized.
ext := strings.ToLower(filepath.Ext(cleanFile))
+19
View File
@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"sort"
"strings"
"testing"
"time"
@@ -265,3 +266,21 @@ func TestScanSubtreeEbookLibraryRoutesToEbookScanner(t *testing.T) {
t.Fatal("ScanSubtree ebook result = nil, want empty result")
}
}
func TestScanFileEbookLibraryUsesEbookPipeline(t *testing.T) {
filePath := filepath.Join(t.TempDir(), "book.epub")
if err := os.WriteFile(filePath, []byte("not a real epub"), 0o644); err != nil {
t.Fatalf("write fake ebook: %v", err)
}
err := (&Scanner{}).ScanFile(context.Background(), filePath, &models.MediaFolder{ID: 44, Type: "ebooks"})
if err == nil {
t.Fatal("ScanFile returned nil, want ebook parse failure")
}
if strings.Contains(err.Error(), "unrecognized video extension") {
t.Fatalf("ScanFile used video extension gate: %v", err)
}
if !strings.Contains(err.Error(), "folder_id=44") {
t.Fatalf("error = %q, want ebook scanner aggregate failure", err)
}
}