diff --git a/internal/handlers/reader.go b/internal/handlers/reader.go index cc2e9b1..1948849 100644 --- a/internal/handlers/reader.go +++ b/internal/handlers/reader.go @@ -93,6 +93,15 @@ func (h *ReaderHandler) ShowReader(c *echo.Context) error { return c.JSON(http.StatusForbidden, map[string]string{"error": "Access denied to this library"}) } + // Get library with type information for panel detection decision + libraryWithType, err := h.db.GetLibraryWithType(c.Request().Context(), mediaItem.LibraryID) + if err != nil { + return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to get library info"}) + } + + // Determine if panel detection should be enabled + enablePanelDetection := shouldEnablePanelDetection(libraryWithType.TypeName, mediaItem.FormatGroup) + // Get reading progress var progress database.ReadingProgress progress, err = h.db.GetReadingProgress(c.Request().Context(), database.GetReadingProgressParams{ @@ -111,17 +120,21 @@ func (h *ReaderHandler) ShowReader(c *echo.Context) error { // Return JSON response instead of rendering template return c.JSON(http.StatusOK, map[string]interface{}{ - "media_item_id": mediaItemID, - "title": mediaItem.Title, - "author": textToString(mediaItem.Author), - "cover_image_path": textToString(mediaItem.CoverImagePath), - "library_type": mediaItem.FormatGroup, - "mime_type": textToString(mediaItem.MimeType), - "file_path": mediaItem.FilePath, - "total_pages": mediaItem.PageCount, - "chapter_count": mediaItem.ChapterCount, - "progress": progress, - "bookmarks": bookmarks, + "media_item_id": mediaItemID, + "title": mediaItem.Title, + "author": textToString(mediaItem.Author), + "cover_image_path": textToString(mediaItem.CoverImagePath), + "library_type": mediaItem.FormatGroup, + "mime_type": textToString(mediaItem.MimeType), + "file_path": mediaItem.FilePath, + "total_pages": mediaItem.PageCount, + "chapter_count": mediaItem.ChapterCount, + "progress": progress, + "bookmarks": bookmarks, + "enable_panel_detection": enablePanelDetection, + "format_group": mediaItem.FormatGroup, + "manga_type": mediaItem.MangaType, + "reading_direction": mediaItem.ReadingDirection, }) } @@ -620,3 +633,19 @@ func (h *ReaderHandler) ParseEbook(c *echo.Context) error { "error": "This format should be parsed client-side, not on the server", }) } + +// shouldEnablePanelDetection determines if panel detection should be enabled +// based on library type and format group +func shouldEnablePanelDetection(libraryType string, formatGroup string) bool { + panelLibraries := map[string]bool{ + "manga": true, + "comics": true, + } + + panelFormats := map[string]bool{ + "fixed_layout": true, + "comic_archive": true, + } + + return panelLibraries[libraryType] && panelFormats[formatGroup] +}