Fix restore photo data from YAML files
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
5b1c0f2afe
commit
5a06433a1c
3 changed files with 15 additions and 13 deletions
|
@ -52,7 +52,7 @@ type Photo struct {
|
|||
TimeZone string `gorm:"type:varbinary(64);" json:"TimeZone" yaml:"-"`
|
||||
PlaceID string `gorm:"type:varbinary(16);index;" json:"PlaceID" yaml:"-"`
|
||||
LocationID string `gorm:"type:varbinary(16);index;" json:"LocationID" yaml:"-"`
|
||||
LocSrc string `gorm:"type:varbinary(8);" json:"LocSrc" yaml:"-"`
|
||||
LocSrc string `gorm:"type:varbinary(8);" json:"LocSrc" yaml:"LocSrc,omitempty"`
|
||||
PhotoLat float32 `gorm:"type:FLOAT;index;" json:"Lat" yaml:"Lat,omitempty"`
|
||||
PhotoLng float32 `gorm:"type:FLOAT;index;" json:"Lng" yaml:"Lng,omitempty"`
|
||||
PhotoAltitude int `json:"Altitude" yaml:"Altitude,omitempty"`
|
||||
|
@ -479,7 +479,7 @@ func (m *Photo) LoadPlace() error {
|
|||
|
||||
// HasLatLng checks if the photo has a latitude and longitude.
|
||||
func (m *Photo) HasLatLng() bool {
|
||||
return m.PhotoLat != 0 && m.PhotoLng != 0
|
||||
return m.PhotoLat != 0.0 || m.PhotoLng != 0.0
|
||||
}
|
||||
|
||||
// NoLatLng checks if latitude and longitude are missing.
|
||||
|
@ -755,7 +755,7 @@ func (m *Photo) UpdateYearMonth() {
|
|||
|
||||
// SetCoordinates changes the photo lat, lng and altitude if not empty and from the same source.
|
||||
func (m *Photo) SetCoordinates(lat, lng float32, altitude int, source string) {
|
||||
if lat == 0 && lng == 0 {
|
||||
if lat == 0.0 && lng == 0.0 {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -105,6 +105,8 @@ func (m *Photo) UpdateLocation(geoApi string) (keywords []string, labels classif
|
|||
} else if err := m.LoadLocation(); err == nil {
|
||||
m.Place = m.Location.Place
|
||||
m.PlaceID = m.Location.PlaceID
|
||||
} else {
|
||||
log.Warn(err)
|
||||
}
|
||||
|
||||
if m.UnknownPlace() {
|
||||
|
@ -112,6 +114,8 @@ func (m *Photo) UpdateLocation(geoApi string) (keywords []string, labels classif
|
|||
m.PlaceID = UnknownPlace.ID
|
||||
} else if err := m.LoadPlace(); err == nil {
|
||||
m.PhotoCountry = m.Place.CountryCode()
|
||||
} else {
|
||||
log.Warn(err)
|
||||
}
|
||||
|
||||
if m.UnknownCountry() {
|
||||
|
|
|
@ -138,6 +138,14 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
|
|||
entity.UnscopedDb().Model(&photo).Related(&description)
|
||||
} else {
|
||||
photo.PhotoQuality = -1
|
||||
|
||||
if yamlName := fs.TypeYaml.FindSub(m.FileName(), fs.HiddenPath, ind.conf.Settings().Index.Group); yamlName != "" {
|
||||
if err := photo.LoadFromYaml(yamlName); err != nil {
|
||||
log.Errorf("index: %s (restore from yaml) for %s", err.Error(), quotedName)
|
||||
} else {
|
||||
log.Infof("index: restored from %s", txt.Quote(fs.RelativeName(yamlName, ind.originalsPath())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if fileHash == "" {
|
||||
|
@ -385,16 +393,6 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
|
|||
return result
|
||||
}
|
||||
} else {
|
||||
if yamlName := fs.TypeYaml.FindSub(m.FileName(), fs.HiddenPath, ind.conf.Settings().Index.Group); yamlName != "" {
|
||||
if err := photo.LoadFromYaml(yamlName); err != nil {
|
||||
log.Errorf("index: %s (restore from yaml) for %s", err.Error(), quotedName)
|
||||
} else {
|
||||
log.Infof("index: restored from %s", txt.Quote(fs.RelativeName(yamlName, ind.originalsPath())))
|
||||
}
|
||||
} else {
|
||||
photo.PhotoFavorite = false
|
||||
}
|
||||
|
||||
if err := entity.UnscopedDb().Create(&photo).Error; err != nil {
|
||||
log.Errorf("index: %s", err)
|
||||
result.Status = IndexFailed
|
||||
|
|
Loading…
Reference in a new issue