650817a9e0
Finding the right code is easier when the name matches related functionality in other packages.
69 lines
1.4 KiB
Go
69 lines
1.4 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{ID: uid, Merged: true}
|
|
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{ID: 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{ID: 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{ID: uid}
|
|
result, err := search.Subjects(f)
|
|
|
|
if err != nil {
|
|
log.Error(err)
|
|
AbortUnexpected(c)
|
|
return
|
|
}
|
|
|
|
event.PublishEntities("subjects", string(e), result)
|
|
}
|