Skip to content

Commit

Permalink
Albums: Reset thumbnail if cover photo has been removed from album
Browse files Browse the repository at this point in the history
  • Loading branch information
kvalev committed May 17, 2023
1 parent 0f7eb8f commit a9fa168
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/api/albums.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ func RemovePhotosFromAlbum(router *gin.RouterGroup) {
event.SuccessMsg(i18n.MsgEntriesRemovedFrom, len(removed), clean.Log(a.Title()))
}

if err := a.ResetThumbIfNeeded(removed); err != nil {
log.Errorf("album: %s (reset thumbnail)", err)
}

RemoveFromAlbumCoverCache(a.AlbumUID)

PublishAlbumEvent(EntityUpdated, a.AlbumUID, c)
Expand Down
20 changes: 20 additions & 0 deletions internal/entity/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,23 @@ func (m *Album) RemovePhotos(UIDs []string) (removed PhotoAlbums) {
func (m *Album) Links() Links {
return FindLinks("", m.AlbumUID)
}

// ResetThumbIfNeeded removes the album thumbnail if it was part of the removed album photos.
func (m *Album) ResetThumbIfNeeded(removed PhotoAlbums) error {
if !m.HasThumb() {
return nil
}

f, err := FirstFileByHash(m.Thumb)
if err != nil {
return err
}

for _, pa := range removed {
if pa.PhotoUID == f.PhotoUID {
return m.ResetThumb()
}
}

return nil
}

0 comments on commit a9fa168

Please sign in to comment.