2021-11-26 14:28:50 +01: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 09:01:17 +02:00
|
|
|
s := Auth(c, acl.ResourcePeople, acl.ActionSearch)
|
2021-11-26 14:28:50 +01:00
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
// Abort if permission was not granted.
|
|
|
|
if s.Abort(c) {
|
2021-11-26 14:28:50 +01: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 09:42:07 +02:00
|
|
|
c.AbortWithStatusJSON(400, gin.H{"error": txt.UpperFirst(err.Error())})
|
2021-11-26 14:28:50 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
AddCountHeader(c, len(result))
|
|
|
|
AddLimitHeader(c, f.Count)
|
|
|
|
AddOffsetHeader(c, f.Offset)
|
2022-10-13 22:11:02 +02:00
|
|
|
AddTokenHeaders(c, s)
|
2021-11-26 14:28:50 +01:00
|
|
|
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
|
|
})
|
|
|
|
}
|