Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
e5931aa5c7
commit
15d323541c
@@ -97,17 +97,33 @@ func (s *Service) FindBook(id string) (*Book, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) CoverBytes(id string) ([]byte, string, 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 err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil, "", nil
|
||||||
|
}
|
||||||
return nil, "", err
|
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 nil, "", nil
|
||||||
}
|
|
||||||
return readEPUBCover(book.Path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func stableID(input string) string {
|
func stableID(input string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user