diff --git a/internal/api/album.go b/internal/api/album.go index a9c3cc385..31d6067bc 100644 --- a/internal/api/album.go +++ b/internal/api/album.go @@ -316,7 +316,7 @@ func CloneAlbums(router *gin.RouterGroup) { continue } - photos, err := search.AlbumPhotos(cloneAlbum, 10000) + photos, err := search.AlbumPhotos(cloneAlbum, 10000, false) if err != nil { log.Errorf("album: %s", err) @@ -462,7 +462,7 @@ func DownloadAlbum(router *gin.RouterGroup) { return } - files, err := search.AlbumPhotos(a, 10000) + files, err := search.AlbumPhotos(a, 10000, true) if err != nil { AbortEntityNotFound(c) diff --git a/internal/form/search_geojson.go b/internal/form/search_geojson.go index 2a28167e3..983d27741 100644 --- a/internal/form/search_geojson.go +++ b/internal/form/search_geojson.go @@ -5,6 +5,7 @@ import "time" // SearchGeo represents search form fields for "/api/v1/geo". type SearchGeo struct { Query string `form:"q"` + Filter string `form:"filter"` Near string `form:"near"` Type string `form:"type"` Path string `form:"path"` @@ -14,6 +15,7 @@ type SearchGeo struct { Before time.Time `form:"before" time_format:"2006-01-02"` After time.Time `form:"after" time_format:"2006-01-02"` Favorite bool `form:"favorite"` + Unsorted bool `form:"unsorted"` Video bool `form:"video"` Photo bool `form:"photo"` Raw bool `form:"raw"` @@ -79,6 +81,12 @@ func (f *SearchGeo) ParseQueryString() error { f.People = "" } + if f.Filter != "" { + if err := Unserialize(f, f.Filter); err != nil { + return err + } + } + return err } diff --git a/internal/search/albums_photos.go b/internal/search/albums_photos.go index a4f7262c9..6035097dc 100644 --- a/internal/search/albums_photos.go +++ b/internal/search/albums_photos.go @@ -6,13 +6,23 @@ import ( ) // AlbumPhotos returns up to count photos from an album. -func AlbumPhotos(a entity.Album, count int) (results PhotoResults, err error) { - results, _, err = Photos(form.SearchPhotos{ +func AlbumPhotos(a entity.Album, count int, shared bool) (results PhotoResults, err error) { + frm := form.SearchPhotos{ Album: a.AlbumUID, Filter: a.AlbumFilter, Count: count, Offset: 0, - }) + } + + if shared { + frm.Public = true + frm.Private = false + frm.Hidden = false + frm.Archived = false + frm.Review = false + } + + results, _, err = Photos(frm) return results, err } diff --git a/internal/search/albums_test.go b/internal/search/albums_test.go index 378ceb4ba..8d5398d29 100644 --- a/internal/search/albums_test.go +++ b/internal/search/albums_test.go @@ -11,7 +11,7 @@ import ( func TestAlbumPhotos(t *testing.T) { t.Run("search with string", func(t *testing.T) { - results, err := AlbumPhotos(entity.AlbumFixtures.Get("april-1990"), 2) + results, err := AlbumPhotos(entity.AlbumFixtures.Get("april-1990"), 2, true) if err != nil { t.Fatal(err) diff --git a/internal/search/geojson.go b/internal/search/geojson.go index 1420a46b6..f60f77d9b 100644 --- a/internal/search/geojson.go +++ b/internal/search/geojson.go @@ -186,8 +186,14 @@ func Geo(f form.SearchGeo) (results GeoResults, err error) { // Filter by album? if rnd.IsPPID(f.Album, 'a') { - s = s.Joins("JOIN photos_albums ON photos_albums.photo_uid = photos.photo_uid"). - Where("photos_albums.hidden = 0 AND photos_albums.album_uid = ?", f.Album) + if f.Filter != "" { + s = s.Where("photos.photo_uid NOT IN (SELECT photo_uid FROM photos_albums pa WHERE pa.hidden = 1 AND pa.album_uid = ?)", f.Album) + } else { + s = s.Joins("JOIN photos_albums ON photos_albums.photo_uid = photos.photo_uid"). + Where("photos_albums.hidden = 0 AND photos_albums.album_uid = ?", f.Album) + } + } else if f.Unsorted && f.Filter == "" { + s = s.Where("photos.photo_uid NOT IN (SELECT photo_uid FROM photos_albums pa WHERE pa.hidden = 0)") } else if f.Albums != "" || f.Album != "" { if f.Albums == "" { f.Albums = f.Album diff --git a/internal/search/photos.go b/internal/search/photos.go index d8a0d40c9..4de1fc525 100644 --- a/internal/search/photos.go +++ b/internal/search/photos.go @@ -504,7 +504,7 @@ func Photos(f form.SearchPhotos) (results PhotoResults, count int, err error) { } for _, where := range LikeAnyWord("a.album_title", f.Albums) { - s = s.Where("photos.photo_uid IN (SELECT pa.photo_uid FROM photos_albums pa JOIN albums a ON a.album_uid = pa.album_uid WHERE (?))", gorm.Expr(where)) + s = s.Where("photos.photo_uid IN (SELECT pa.photo_uid FROM photos_albums pa JOIN albums a ON a.album_uid = pa.album_uid AND pa.hidden = 0 WHERE (?))", gorm.Expr(where)) } }