From dea952020ce3b76013694fff3d8682879845d070 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 16 May 2026 19:30:46 -0400 Subject: [PATCH] fix(library): sync allowed extensions from Go source of truth to DB on startup AllowedExtensions in Go was the intended single source of truth for library type file extensions, but it was never synced to the database. This caused missing extensions like .pdf for manga to be absent from library_types. - Add SyncAllowedExtensions() to sync Go AllowedExtensions map to DB - Call SyncAllowedExtensions() from cmd/server/main.go on startup - Ensure .pdf is included in manga extensions --- internal/services/library_service.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/services/library_service.go b/internal/services/library_service.go index 0ad61dd..1619606 100644 --- a/internal/services/library_service.go +++ b/internal/services/library_service.go @@ -4,6 +4,7 @@ import ( "bookhoard/internal/database" "context" "fmt" + "log" "os" "path/filepath" "strings" @@ -286,6 +287,19 @@ func (s *LibraryService) BrowseDirectories(ctx context.Context, path string) ([] return dirs, cleanPath, parentPath, nil } +// SyncAllowedExtensions syncs the Go AllowedExtensions map into the database. +// This ensures library_types.allowed_extensions stays in sync with the Go source of truth. +func (s *LibraryService) SyncAllowedExtensions(ctx context.Context) { + for typeName, exts := range AllowedExtensions { + if err := s.db.SyncLibraryTypeExtensions(ctx, database.SyncLibraryTypeExtensionsParams{ + Name: typeName, + AllowedExtensions: exts, + }); err != nil { + log.Printf("Warning: failed to sync allowed extensions for library type %s: %v", typeName, err) + } + } +} + func (s *LibraryService) ResolveMediaPath(ctx context.Context, libraryID pgtype.UUID, relativePath string) (string, error) { // Get library folders for this library folders, err := s.db.GetLibraryFolders(ctx, libraryID)