From 6b3bdef0528fc590d832a965b258066b69087b0f Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 17 Oct 2026 17:16:11 -0400 Subject: [PATCH] =?UTF-8?q?refactor(reader):=20one=20comic-likeness=20pred?= =?UTF-8?q?icate=20=E2=80=94=20panel=20detection=20was=20a=20byte-identica?= =?UTF-8?q?l=20twin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit shouldEnablePanelDetection and ShouldTreatAsComic had identical truth tables (manga/comics library x fixed_layout/comic_archive) under different names — a drift trap: adding a library type to one silently missed the other. One predicate now gates both features, with the re-split instruction in its doc comment should the features ever legitimately diverge. --- internal/handlers/reader.go | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/internal/handlers/reader.go b/internal/handlers/reader.go index df9784b9..299090ac 100644 --- a/internal/handlers/reader.go +++ b/internal/handlers/reader.go @@ -102,7 +102,9 @@ func (h *ReaderHandler) ShowReader(c *echo.Context) error { } // Determine if panel detection should be enabled - enablePanelDetection := shouldEnablePanelDetection(libraryWithType.TypeName, mediaItem.FormatGroup) + // Same comic-likeness predicate as treatAsComic below — one function + // on purpose (see ShouldTreatAsComic's doc). + enablePanelDetection := ShouldTreatAsComic(libraryWithType.TypeName, mediaItem.FormatGroup) treatAsComic := ShouldTreatAsComic(libraryWithType.TypeName, mediaItem.FormatGroup) // Get reading progress @@ -639,6 +641,12 @@ func (h *ReaderHandler) generatePDFThumbnail(fullPath string, page int, width, h // only — no text-selection highlights, no annotations, no in-book search. // Comic archives already behave this way; this flag extends it to fixed- // layout PDFs shelved in comic libraries (scanned or official manga PDFs). +// +// This is ALSO the panel-detection gate (reader.go's enablePanelDetection): +// the two checks were once separate functions with byte-identical bodies — +// a drift trap (adding a library type to one silently missed the other). +// If comic treatment and panel detection ever need to diverge, re-split +// them with a comment saying why. func ShouldTreatAsComic(libraryType string, formatGroup string) bool { comicLibraries := map[string]bool{ "manga": true, @@ -652,19 +660,3 @@ func ShouldTreatAsComic(libraryType string, formatGroup string) bool { return comicLibraries[libraryType] && fixedFormats[formatGroup] } - -// 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] -}