Skip to content

Commit

Permalink
Shares: Show all albums on overview page photoprism#776
Browse files Browse the repository at this point in the history
  • Loading branch information
lastzero committed Dec 31, 2020
1 parent bbd0af3 commit f439a6d
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 37 deletions.
2 changes: 1 addition & 1 deletion frontend/src/share/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/api/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/photoprism/moments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/query/albums.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions internal/query/geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ 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 {
s = s.Where("photos.photo_favorite = 1")
}

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 {
Expand All @@ -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), "*", "%"))
}
Expand Down
40 changes: 20 additions & 20 deletions internal/query/photo_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var log = event.Log
const (
MySQL = "mysql"
SQLite = "sqlite3"
OrSep = "|"
Or = "|"
)

// Max result limit for queries.
Expand Down
2 changes: 1 addition & 1 deletion internal/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
6 changes: 5 additions & 1 deletion internal/session/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions internal/session/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit f439a6d

Please sign in to comment.