Improve database compatibility
- Make MediaType case insensitive when saved to database - Null check exif migrations, this might solve #300
This commit is contained in:
parent
7f546e122e
commit
f8cd804c3d
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ const PreviewMedia = ({ media, previewImage }: PreviewMediaProps) => {
|
|||
return <PreviewVideo media={media} />
|
||||
}
|
||||
|
||||
throw new Error('Unknown media type')
|
||||
return <div>ERROR: Unknown media type: {media.type}</div>
|
||||
}
|
||||
|
||||
const Name = styled.div`
|
||||
|
|
Loading…
Reference in New Issue