2020-01-30 18:19:26 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"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-03-28 15:29:17 +01:00
|
|
|
func PublishPhotoEvent(e EntityEvent, uuid string, c *gin.Context, q *query.Query) {
|
2020-04-21 02:10:59 +02:00
|
|
|
f := form.PhotoSearch{ID: uuid, Merged: true}
|
2020-04-20 20:07:58 +02:00
|
|
|
result, _, err := q.Photos(f)
|
2020-01-30 18:19:26 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
c.AbortWithStatusJSON(http.StatusInternalServerError, ErrUnexpectedError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-04 11:38:43 +01:00
|
|
|
event.PublishEntities("photos", string(e), result)
|
2020-01-30 18:19:26 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
func PublishAlbumEvent(e EntityEvent, uuid string, c *gin.Context, q *query.Query) {
|
2020-01-30 18:19:26 +01:00
|
|
|
f := form.AlbumSearch{ID: uuid}
|
|
|
|
result, err := q.Albums(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
c.AbortWithStatusJSON(http.StatusInternalServerError, ErrUnexpectedError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-04 11:38:43 +01:00
|
|
|
event.PublishEntities("albums", string(e), result)
|
2020-01-30 18:19:26 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
func PublishLabelEvent(e EntityEvent, uuid string, c *gin.Context, q *query.Query) {
|
2020-01-30 18:19:26 +01:00
|
|
|
f := form.LabelSearch{ID: uuid}
|
|
|
|
result, err := q.Labels(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
c.AbortWithStatusJSON(http.StatusInternalServerError, ErrUnexpectedError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-04 11:38:43 +01:00
|
|
|
event.PublishEntities("labels", string(e), result)
|
2020-01-30 18:19:26 +01:00
|
|
|
}
|