diff --git a/api/database/migration_exif.go b/api/database/migration_exif.go index 546157e6..b955ff8c 100644 --- a/api/database/migration_exif.go +++ b/api/database/migration_exif.go @@ -72,6 +72,16 @@ func migrate_exif_fields_exposure(db *gorm.DB) error { return tx.Model(&exifModel{}).Table("media_exif").Where("exposure LIKE '%/%'").FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error { for _, result := range results { + + if result.Exposure == nil { + continue + } + + if *result.Exposure == "" { + result.Exposure = nil + continue + } + frac := strings.Split(*result.Exposure, "/") if len(frac) != 2 { return errors.Errorf("failed to convert exposure value (%s) expected format x/y", frac) @@ -147,6 +157,16 @@ func migrate_exif_fields_flash(db *gorm.DB) error { return tx.Model(&exifModel{}).Table("media_exif").Where("flash IS NOT NULL").FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error { for _, result := range results { + + if result.Flash == nil { + continue + } + + if *result.Flash == "" { + result.Flash = nil + continue + } + for index, name := range flashDescriptions { if *result.Flash == name { *result.Flash = fmt.Sprintf("%d", index) diff --git a/api/graphql/models/media.go b/api/graphql/models/media.go index 8fdf6102..b6096462 100644 --- a/api/graphql/models/media.go +++ b/api/graphql/models/media.go @@ -42,6 +42,29 @@ func (m *Media) BeforeSave(tx *gorm.DB) error { // Update path hash m.PathHash = MD5Hash(m.Path) + // Save media type as lowercase for better compatibility + m.Type = MediaType(strings.ToLower(string(m.Type))) + + return nil +} + +func (m *Media) AfterFind(tx *gorm.DB) error { + + // Convert lowercased media type back + lowercasedType := strings.ToLower(string(m.Type)) + foundType := false + for _, t := range AllMediaType { + if strings.ToLower(string(m.Type)) == lowercasedType { + m.Type = t + foundType = true + break + } + } + + if foundType == false { + return errors.New(fmt.Sprintf("Failed to parse media from DB: Invalid media type: %s", m.Type)) + } + return nil } diff --git a/ui/src/components/sidebar/MediaSidebar.tsx b/ui/src/components/sidebar/MediaSidebar.tsx index f044ad27..d7c2fe8d 100644 --- a/ui/src/components/sidebar/MediaSidebar.tsx +++ b/ui/src/components/sidebar/MediaSidebar.tsx @@ -129,7 +129,7 @@ const PreviewMedia = ({ media, previewImage }: PreviewMediaProps) => { return } - throw new Error('Unknown media type') + return
ERROR: Unknown media type: {media.type}
} const Name = styled.div`