photoprism/internal/api/event.go
Michael Mayer d8e0364dbb Search: Ignore public album filter if "Private" feat is disabled #2570
This needs to be very well tested and discussed, as these changes can
lead to private photos being accidentally published. Thank you!

Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-08-01 15:57:19 +02:00

76 lines
1.5 KiB
Go

package api
import (
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/search"
)
type EntityEvent string
const (
EntityUpdated EntityEvent = "updated"
EntityCreated EntityEvent = "created"
EntityDeleted EntityEvent = "deleted"
)
func PublishPhotoEvent(e EntityEvent, uid string, c *gin.Context) {
f := form.SearchPhotos{UID: uid, Merged: true}
if err := f.ParseQueryString(); err != nil {
log.Errorf("publish: %s", err)
AbortBadRequest(c)
return
}
result, _, err := search.Photos(f)
if err != nil {
log.Error(err)
AbortUnexpected(c)
return
}
event.PublishEntities("photos", string(e), result)
}
func PublishAlbumEvent(e EntityEvent, uid string, c *gin.Context) {
f := form.SearchAlbums{UID: uid}
result, err := search.Albums(f)
if err != nil {
log.Error(err)
AbortUnexpected(c)
return
}
event.PublishEntities("albums", string(e), result)
}
func PublishLabelEvent(e EntityEvent, uid string, c *gin.Context) {
f := form.SearchLabels{UID: uid}
result, err := search.Labels(f)
if err != nil {
log.Error(err)
AbortUnexpected(c)
return
}
event.PublishEntities("labels", string(e), result)
}
func PublishSubjectEvent(e EntityEvent, uid string, c *gin.Context) {
f := form.SearchSubjects{UID: uid}
result, err := search.Subjects(f)
if err != nil {
log.Error(err)
AbortUnexpected(c)
return
}
event.PublishEntities("subjects", string(e), result)
}