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)