Photo: Update year and month whenever takenAt may change
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
9937304d0c
commit
7ee4d5eda5
2 changed files with 26 additions and 7 deletions
|
@ -75,6 +75,8 @@ func SavePhotoForm(model Photo, form form.Photo, geoApi string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model.UpdateYearMonth()
|
||||||
|
|
||||||
if form.Description.PhotoID == model.ID {
|
if form.Description.PhotoID == model.ID {
|
||||||
if err := deepcopier.Copy(&model.Description).From(form.Description); err != nil {
|
if err := deepcopier.Copy(&model.Description).From(form.Description); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -122,6 +124,8 @@ func (m *Photo) Save() error {
|
||||||
db := Db()
|
db := Db()
|
||||||
labels := m.ClassifyLabels()
|
labels := m.ClassifyLabels()
|
||||||
|
|
||||||
|
m.UpdateYearMonth()
|
||||||
|
|
||||||
if err := m.UpdateTitle(labels); err != nil {
|
if err := m.UpdateTitle(labels); err != nil {
|
||||||
log.Warnf("%s (%s)", err.Error(), m.PhotoUUID)
|
log.Warnf("%s (%s)", err.Error(), m.PhotoUUID)
|
||||||
}
|
}
|
||||||
|
@ -485,6 +489,27 @@ func (m *Photo) SetTakenAt(taken, local time.Time, zone, source string) {
|
||||||
if zone != "" {
|
if zone != "" {
|
||||||
m.TimeZone = zone
|
m.TimeZone = zone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.UpdateYearMonth()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateYearMonth updates internal date fields.
|
||||||
|
func (m *Photo) UpdateYearMonth() {
|
||||||
|
if m.TakenAt.IsZero() || m.TakenAt.Year() < 1000 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.TakenAtLocal.IsZero() || m.TakenAtLocal.Year() < 1000 {
|
||||||
|
m.TakenAtLocal = m.TakenAt
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.TakenSrc == SrcAuto {
|
||||||
|
m.PhotoYear = YearUnknown
|
||||||
|
m.PhotoMonth = MonthUnknown
|
||||||
|
} else {
|
||||||
|
m.PhotoYear = m.TakenAtLocal.Year()
|
||||||
|
m.PhotoMonth = int(m.TakenAtLocal.Month())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCoordinates changes the photo lat, lng and altitude if not empty and from the same source.
|
// SetCoordinates changes the photo lat, lng and altitude if not empty and from the same source.
|
||||||
|
|
|
@ -279,13 +279,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
|
||||||
photo.PhotoCountry = entity.UnknownPlace.CountryCode()
|
photo.PhotoCountry = entity.UnknownPlace.CountryCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
if photo.TakenSrc == entity.SrcAuto {
|
photo.UpdateYearMonth()
|
||||||
photo.PhotoYear = entity.YearUnknown
|
|
||||||
photo.PhotoMonth = entity.MonthUnknown
|
|
||||||
} else if !photo.TakenAtLocal.IsZero() {
|
|
||||||
photo.PhotoYear = photo.TakenAtLocal.Year()
|
|
||||||
photo.PhotoMonth = int(photo.TakenAtLocal.Month())
|
|
||||||
}
|
|
||||||
|
|
||||||
if originalName != "" {
|
if originalName != "" {
|
||||||
file.OriginalName = originalName
|
file.OriginalName = originalName
|
||||||
|
|
Loading…
Reference in a new issue