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"
|
2021-09-18 15:32:39 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/search"
|
2020-01-30 18:19:26 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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}
|
2021-09-18 15:32:39 +02:00
|
|
|
result, _, err := search.Photos(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}
|
2021-09-18 15:32:39 +02:00
|
|
|
result, err := search.Albums(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}
|
2021-09-18 15:32:39 +02:00
|
|
|
result, err := search.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
|
|
|
}
|
2021-09-17 14:26:12 +02:00
|
|
|
|
|
|
|
func PublishSubjectEvent(e EntityEvent, uid string, c *gin.Context) {
|
|
|
|
f := form.SubjectSearch{ID: uid}
|
2021-09-18 15:32:39 +02:00
|
|
|
result, err := search.Subjects(f)
|
2021-09-17 14:26:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
AbortUnexpected(c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
event.PublishEntities("subjects", string(e), result)
|
|
|
|
}
|