2020-01-30 18:19:26 +01:00
|
|
|
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/query"
|
|
|
|
)
|
|
|
|
|
|
|
|
type EntityEvent string
|
|
|
|
|
|
|
|
const (
|
2020-01-31 15:29:06 +01:00
|
|
|
EntityUpdated EntityEvent = "updated"
|
|
|
|
EntityCreated EntityEvent = "created"
|
|
|
|
EntityDeleted EntityEvent = "deleted"
|
2020-01-30 18:19:26 +01:00
|
|
|
)
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
func PublishPhotoEvent(e EntityEvent, uid string, c *gin.Context) {
|
|
|
|
f := form.PhotoSearch{ID: uid, Merged: true}
|
2020-05-25 19:10:44 +02:00
|
|
|
result, _, err := query.PhotoSearch(f)
|
2020-01-30 18:19:26 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
2020-07-04 12:54:35 +02:00
|
|
|
AbortUnexpected(c)
|
2020-01-30 18:19:26 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-04 11:38:43 +01:00
|
|
|
event.PublishEntities("photos", string(e), result)
|
2020-01-30 18:19:26 +01:00
|
|
|
}
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
func PublishAlbumEvent(e EntityEvent, uid string, c *gin.Context) {
|
|
|
|
f := form.AlbumSearch{ID: uid}
|
2020-05-25 19:10:44 +02:00
|
|
|
result, err := query.AlbumSearch(f)
|
2020-01-30 18:19:26 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
2020-07-04 12:54:35 +02:00
|
|
|
AbortUnexpected(c)
|
2020-01-30 18:19:26 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-04 11:38:43 +01:00
|
|
|
event.PublishEntities("albums", string(e), result)
|
2020-01-30 18:19:26 +01:00
|
|
|
}
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
func PublishLabelEvent(e EntityEvent, uid string, c *gin.Context) {
|
|
|
|
f := form.LabelSearch{ID: uid}
|
2020-05-08 15:41:01 +02:00
|
|
|
result, err := query.Labels(f)
|
2020-01-30 18:19:26 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
2020-07-04 12:54:35 +02:00
|
|
|
AbortUnexpected(c)
|
2020-01-30 18:19:26 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-04 11:38:43 +01:00
|
|
|
event.PublishEntities("labels", string(e), result)
|
2020-01-30 18:19:26 +01:00
|
|
|
}
|