diff --git a/frontend/src/share/routes.js b/frontend/src/share/routes.js index 5df05eb6a..700d3a1bc 100644 --- a/frontend/src/share/routes.js +++ b/frontend/src/share/routes.js @@ -16,7 +16,7 @@ export default [ path: "/s/:token", component: Albums, meta: { title: shareTitle, auth: true }, - props: { view: "album", staticFilter: { type: "album" } }, + props: { view: "album", staticFilter: { type: "" } }, }, { name: "album", diff --git a/internal/api/album.go b/internal/api/album.go index b209169d8..041e64f8b 100644 --- a/internal/api/album.go +++ b/internal/api/album.go @@ -78,7 +78,7 @@ func GetAlbums(router *gin.RouterGroup) { // Guest permissions are limited to shared albums. if s.Guest() { - f.ID = s.Shares.String() + f.ID = s.Shares.Join(query.Or) } result, err := query.AlbumSearch(f) diff --git a/internal/photoprism/moments.go b/internal/photoprism/moments.go index 88ce2a64b..297f11026 100644 --- a/internal/photoprism/moments.go +++ b/internal/photoprism/moments.go @@ -204,7 +204,7 @@ func (m *Moments) Start() (err error) { } else { w := txt.Words(f.Label) w = append(w, mom.Label) - f.Label = strings.Join(txt.UniqueWords(w), query.OrSep) + f.Label = strings.Join(txt.UniqueWords(w), query.Or) } if err := a.Update("AlbumFilter", f.Serialize()); err != nil { diff --git a/internal/query/albums.go b/internal/query/albums.go index ce742467d..7dbfbacd7 100644 --- a/internal/query/albums.go +++ b/internal/query/albums.go @@ -117,7 +117,7 @@ func AlbumSearch(f form.AlbumSearch) (results AlbumResults, err error) { Where("albums.deleted_at IS NULL") if f.ID != "" { - s = s.Where("albums.album_uid IN (?)", strings.Split(f.ID, OrSep)) + s = s.Where("albums.album_uid IN (?)", strings.Split(f.ID, Or)) if result := s.Scan(&results); result.Error != nil { return results, result.Error @@ -132,15 +132,15 @@ func AlbumSearch(f form.AlbumSearch) (results AlbumResults, err error) { } if f.Type != "" { - s = s.Where("albums.album_type IN (?)", strings.Split(f.Type, OrSep)) + s = s.Where("albums.album_type IN (?)", strings.Split(f.Type, Or)) } if f.Category != "" { - s = s.Where("albums.album_category IN (?)", strings.Split(f.Category, OrSep)) + s = s.Where("albums.album_category IN (?)", strings.Split(f.Category, Or)) } if f.Location != "" { - s = s.Where("albums.album_location IN (?)", strings.Split(f.Location, OrSep)) + s = s.Where("albums.album_location IN (?)", strings.Split(f.Location, Or)) } if f.Favorite { diff --git a/internal/query/geo.go b/internal/query/geo.go index 1ea2485e9..238a2443a 100644 --- a/internal/query/geo.go +++ b/internal/query/geo.go @@ -100,7 +100,7 @@ func Geo(f form.GeoSearch) (results GeoResults, err error) { } if f.Color != "" { - s = s.Where("files.file_main_color IN (?)", strings.Split(strings.ToLower(f.Color), OrSep)) + s = s.Where("files.file_main_color IN (?)", strings.Split(strings.ToLower(f.Color), Or)) } if f.Favorite { @@ -108,12 +108,12 @@ func Geo(f form.GeoSearch) (results GeoResults, err error) { } if f.Country != "" { - s = s.Where("photos.photo_country IN (?)", strings.Split(strings.ToLower(f.Country), OrSep)) + s = s.Where("photos.photo_country IN (?)", strings.Split(strings.ToLower(f.Country), Or)) } // Filter by media type. if f.Type != "" { - s = s.Where("photos.photo_type IN (?)", strings.Split(strings.ToLower(f.Type), OrSep)) + s = s.Where("photos.photo_type IN (?)", strings.Split(strings.ToLower(f.Type), Or)) } if f.Video { @@ -131,15 +131,15 @@ func Geo(f form.GeoSearch) (results GeoResults, err error) { if strings.HasSuffix(p, "/") { s = s.Where("photos.photo_path = ?", p[:len(p)-1]) - } else if strings.Contains(p, OrSep) { - s = s.Where("photos.photo_path IN (?)", strings.Split(p, OrSep)) + } else if strings.Contains(p, Or) { + s = s.Where("photos.photo_path IN (?)", strings.Split(p, Or)) } else { s = s.Where("photos.photo_path LIKE ?", strings.ReplaceAll(p, "*", "%")) } } - if strings.Contains(f.Name, OrSep) { - s = s.Where("photos.photo_name IN (?)", strings.Split(f.Name, OrSep)) + if strings.Contains(f.Name, Or) { + s = s.Where("photos.photo_name IN (?)", strings.Split(f.Name, Or)) } else if f.Name != "" { s = s.Where("photos.photo_name LIKE ?", strings.ReplaceAll(fs.StripKnownExt(f.Name), "*", "%")) } diff --git a/internal/query/photo_search.go b/internal/query/photo_search.go index 9acb62611..74e3d0c4d 100644 --- a/internal/query/photo_search.go +++ b/internal/query/photo_search.go @@ -58,7 +58,7 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error // Shortcut for known photo ids. if f.ID != "" { - s = s.Where("photos.photo_uid IN (?)", strings.Split(f.ID, OrSep)) + s = s.Where("photos.photo_uid IN (?)", strings.Split(f.ID, Or)) s = s.Order("files.file_primary DESC") if result := s.Scan(&results); result.Error != nil { @@ -80,7 +80,7 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error var labelIds []uint if f.Label != "" { - if err := Db().Where(AnySlug("label_slug", f.Label, OrSep)).Or(AnySlug("custom_slug", f.Label, OrSep)).Find(&labels).Error; len(labels) == 0 || err != nil { + if err := Db().Where(AnySlug("label_slug", f.Label, Or)).Or(AnySlug("custom_slug", f.Label, Or)).Find(&labels).Error; len(labels) == 0 || err != nil { log.Errorf("search: labels %s not found", txt.Quote(f.Label)) return results, 0, fmt.Errorf("%s not found", txt.Quote(f.Label)) } else { @@ -182,7 +182,7 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error } if f.Color != "" { - s = s.Where("files.file_main_color IN (?)", strings.Split(strings.ToLower(f.Color), OrSep)) + s = s.Where("files.file_main_color IN (?)", strings.Split(strings.ToLower(f.Color), Or)) } if f.Favorite { @@ -204,21 +204,21 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error } if f.Country != "" { - s = s.Where("photos.photo_country IN (?)", strings.Split(strings.ToLower(f.Country), OrSep)) + s = s.Where("photos.photo_country IN (?)", strings.Split(strings.ToLower(f.Country), Or)) } if f.State != "" { - s = s.Where("places.place_state IN (?)", strings.Split(f.State, OrSep)) + s = s.Where("places.place_state IN (?)", strings.Split(f.State, Or)) } if f.Category != "" { s = s.Joins("JOIN cells ON photos.cell_id = cells.id"). - Where("cells.cell_category IN (?)", strings.Split(strings.ToLower(f.Category), OrSep)) + Where("cells.cell_category IN (?)", strings.Split(strings.ToLower(f.Category), Or)) } // Filter by media type. if f.Type != "" { - s = s.Where("photos.photo_type IN (?)", strings.Split(strings.ToLower(f.Type), OrSep)) + s = s.Where("photos.photo_type IN (?)", strings.Split(strings.ToLower(f.Type), Or)) } if f.Video { @@ -236,41 +236,41 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error if strings.HasSuffix(p, "/") { s = s.Where("photos.photo_path = ?", p[:len(p)-1]) - } else if strings.Contains(p, OrSep) { - s = s.Where("photos.photo_path IN (?)", strings.Split(p, OrSep)) + } else if strings.Contains(p, Or) { + s = s.Where("photos.photo_path IN (?)", strings.Split(p, Or)) } else { s = s.Where("photos.photo_path LIKE ?", strings.ReplaceAll(p, "*", "%")) } } - if strings.Contains(f.Name, OrSep) { - s = s.Where("photos.photo_name IN (?)", strings.Split(f.Name, OrSep)) + if strings.Contains(f.Name, Or) { + s = s.Where("photos.photo_name IN (?)", strings.Split(f.Name, Or)) } else if f.Name != "" { s = s.Where("photos.photo_name LIKE ?", strings.ReplaceAll(fs.StripKnownExt(f.Name), "*", "%")) } - if strings.Contains(f.Filename, OrSep) { - s = s.Where("files.file_name IN (?)", strings.Split(f.Filename, OrSep)) + if strings.Contains(f.Filename, Or) { + s = s.Where("files.file_name IN (?)", strings.Split(f.Filename, Or)) } else if f.Filename != "" { s = s.Where("files.file_name LIKE ?", strings.ReplaceAll(f.Filename, "*", "%")) } - if strings.Contains(f.Original, OrSep) { - s = s.Where("photos.original_name IN (?)", strings.Split(f.Original, OrSep)) + if strings.Contains(f.Original, Or) { + s = s.Where("photos.original_name IN (?)", strings.Split(f.Original, Or)) } else if f.Original != "" { s = s.Where("photos.original_name LIKE ?", strings.ReplaceAll(f.Original, "*", "%")) } - if strings.Contains(f.Title, OrSep) { - s = s.Where("photos.photo_title IN (?)", strings.Split(strings.ToLower(f.Title), OrSep)) + if strings.Contains(f.Title, Or) { + s = s.Where("photos.photo_title IN (?)", strings.Split(strings.ToLower(f.Title), Or)) } else if f.Title != "" { s = s.Where("photos.photo_title LIKE ?", strings.ReplaceAll(strings.ToLower(f.Title), "*", "%")) } - if strings.Contains(f.Hash, OrSep) { - s = s.Where("files.file_hash IN (?)", strings.Split(strings.ToLower(f.Hash), OrSep)) + if strings.Contains(f.Hash, Or) { + s = s.Where("files.file_hash IN (?)", strings.Split(strings.ToLower(f.Hash), Or)) } else if f.Hash != "" { - s = s.Where("files.file_hash IN (?)", strings.Split(strings.ToLower(f.Hash), OrSep)) + s = s.Where("files.file_hash IN (?)", strings.Split(strings.ToLower(f.Hash), Or)) } if f.Portrait { diff --git a/internal/query/query.go b/internal/query/query.go index 40103f3d7..cb6e7e5c5 100644 --- a/internal/query/query.go +++ b/internal/query/query.go @@ -49,7 +49,7 @@ var log = event.Log const ( MySQL = "mysql" SQLite = "sqlite3" - OrSep = "|" + Or = "|" ) // Max result limit for queries. diff --git a/internal/query/query_test.go b/internal/query/query_test.go index 0e1bb0a94..59e20f067 100644 --- a/internal/query/query_test.go +++ b/internal/query/query_test.go @@ -89,7 +89,7 @@ func TestAnySlug(t *testing.T) { }) t.Run("comma separated", func(t *testing.T) { - where := AnySlug("custom_slug", "botanical-garden|landscape|bay", OrSep) + where := AnySlug("custom_slug", "botanical-garden|landscape|bay", Or) assert.Equal(t, "custom_slug = 'botanical-garden' OR custom_slug = 'landscape' OR custom_slug = 'bay'", where) }) diff --git a/internal/session/data.go b/internal/session/data.go index 01a2896fb..17df69970 100644 --- a/internal/session/data.go +++ b/internal/session/data.go @@ -15,7 +15,11 @@ type Saved struct { type UIDs []string func (list UIDs) String() string { - return strings.Join(list, ",") + return list.Join(",") +} + +func (list UIDs) Join(s string) string { + return strings.Join(list, s) } type Data struct { diff --git a/internal/session/data_test.go b/internal/session/data_test.go index 20fd820d9..935dbdcd7 100644 --- a/internal/session/data_test.go +++ b/internal/session/data_test.go @@ -11,6 +11,11 @@ func TestUIDs_String(t *testing.T) { assert.Equal(t, "dghjkfd,dfgehrih", uid.String()) } +func TestUIDs_Join(t *testing.T) { + uid := UIDs{"dghjkfd", "dfgehrih"} + assert.Equal(t, "dghjkfd|dfgehrih", uid.Join("|")) +} + func TestData_HasShare(t *testing.T) { data := Data{Shares: []string{"abc123", "def444"}} assert.True(t, data.HasShare("def444"))