2021-11-26 13:28:50 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gin-gonic/gin/binding"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
"github.com/photoprism/photoprism/internal/search"
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SearchFaces finds and returns faces as JSON.
|
|
|
|
//
|
|
|
|
// GET /api/v1/faces
|
|
|
|
func SearchFaces(router *gin.RouterGroup) {
|
|
|
|
router.GET("/faces", func(c *gin.Context) {
|
2022-09-28 07:01:17 +00:00
|
|
|
s := Auth(c, acl.ResourcePeople, acl.ActionSearch)
|
2021-11-26 13:28:50 +00:00
|
|
|
|
2022-09-28 07:01:17 +00:00
|
|
|
// Abort if permission was not granted.
|
|
|
|
if s.Abort(c) {
|
2021-11-26 13:28:50 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var f form.SearchFaces
|
|
|
|
|
|
|
|
err := c.MustBindWith(&f, binding.Form)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
AbortBadRequest(c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := search.Faces(f)
|
|
|
|
|
|
|
|
if err != nil {
|
2022-04-15 07:42:07 +00:00
|
|
|
c.AbortWithStatusJSON(400, gin.H{"error": txt.UpperFirst(err.Error())})
|
2021-11-26 13:28:50 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
AddCountHeader(c, len(result))
|
|
|
|
AddLimitHeader(c, f.Count)
|
|
|
|
AddOffsetHeader(c, f.Offset)
|
2022-10-13 20:11:02 +00:00
|
|
|
AddTokenHeaders(c, s)
|
2021-11-26 13:28:50 +00:00
|
|
|
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
|
|
})
|
|
|
|
}
|