diff --git a/internal/handlers/opds.go b/internal/handlers/opds.go index 1827ab6..84b0764 100644 --- a/internal/handlers/opds.go +++ b/internal/handlers/opds.go @@ -402,7 +402,11 @@ func (h *OPDSHandler) DownloadBook(c echo.Context) error { } } else { if h.conversionService != nil { - converted, err := h.conversionService.ConvertEPUBToKEPUB(c.Request().Context(), pgtype.UUID{Bytes: bookUUID, Valid: true}, mediaItem.FilePath) + resolvedPath, err := h.libraryService.ResolveMediaPath(c.Request().Context(), mediaItem.LibraryID, mediaItem.FilePath) + if err != nil { + return c.JSON(http.StatusNotFound, map[string]string{"error": "file not found"}) + } + converted, err := h.conversionService.ConvertEPUBToKEPUB(c.Request().Context(), pgtype.UUID{Bytes: bookUUID, Valid: true}, resolvedPath) if err != nil { return c.JSON(http.StatusInternalServerError, map[string]string{"error": fmt.Sprintf("KEPUB conversion failed: %v", err)}) } @@ -410,7 +414,10 @@ func (h *OPDSHandler) DownloadBook(c echo.Context) error { fileSha256 = converted.SHA256 mimeType = "application/vnd.kobo+xml+zip" } else { - filePath = mediaItem.FilePath + filePath, err = h.libraryService.ResolveMediaPath(c.Request().Context(), mediaItem.LibraryID, mediaItem.FilePath) + if err != nil { + return c.JSON(http.StatusNotFound, map[string]string{"error": "file not found"}) + } if mediaItem.MimeType.Valid { mimeType = mediaItem.MimeType.String } @@ -435,7 +442,11 @@ func (h *OPDSHandler) DownloadBook(c echo.Context) error { } } else { // Default: EPUB - filePath = mediaItem.FilePath + var err error + filePath, err = h.libraryService.ResolveMediaPath(c.Request().Context(), mediaItem.LibraryID, mediaItem.FilePath) + if err != nil { + return c.JSON(http.StatusNotFound, map[string]string{"error": "file not found"}) + } if mediaItem.MimeType.Valid { mimeType = mediaItem.MimeType.String }