From 15d323541cde5c5a76f830f2a1f9b1ad8c4a4f16 Mon Sep 17 00:00:00 2001 From: Arne <1169654+arnef@users.noreply.github.com> Date: Sat, 8 Aug 2026 13:40:23 +0200 Subject: [PATCH] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- internal/library/library.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/internal/library/library.go b/internal/library/library.go index 3e1256d..765a3db 100644 --- a/internal/library/library.go +++ b/internal/library/library.go @@ -97,17 +97,33 @@ func (s *Service) FindBook(id string) (*Book, error) { } func (s *Service) CoverBytes(id string) ([]byte, string, error) { - book, err := s.FindBook(id) + if id == "" { + return nil, "", nil + } + + entries, err := os.ReadDir(s.booksDir) if err != nil { + if os.IsNotExist(err) { + return nil, "", nil + } return nil, "", err } - if book == nil { - return nil, "", nil + + for _, e := range entries { + if e.IsDir() { + continue + } + ext := strings.ToLower(filepath.Ext(e.Name())) + if ext != ".epub" { + continue + } + if stableID(e.Name()) != id { + continue + } + return readEPUBCover(filepath.Join(s.booksDir, e.Name())) } - if book.Format != "epub" { - return nil, "", nil - } - return readEPUBCover(book.Path) + + return nil, "", nil } func stableID(input string) string {