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/entity"
|
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
2022-10-15 21:54:11 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/get"
|
2021-11-26 14:28:50 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/search"
|
|
|
|
)
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
// SearchServices finds account settings and returns them as JSON.
|
2021-11-26 14:28:50 +01:00
|
|
|
//
|
2022-10-15 21:54:11 +02:00
|
|
|
// GET /api/v1/services
|
|
|
|
func SearchServices(router *gin.RouterGroup) {
|
|
|
|
router.GET("/services", func(c *gin.Context) {
|
|
|
|
s := Auth(c, acl.ResourceServices, acl.ActionSearch)
|
2021-11-26 14:28:50 +01:00
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
if s.Abort(c) {
|
2021-11-26 14:28:50 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
conf := get.Config()
|
2021-11-26 14:28:50 +01:00
|
|
|
|
|
|
|
if conf.Demo() || conf.DisableSettings() {
|
2022-10-15 21:54:11 +02:00
|
|
|
c.JSON(http.StatusOK, entity.Services{})
|
2021-11-26 14:28:50 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
var f form.SearchServices
|
2021-11-26 14:28:50 +01:00
|
|
|
|
|
|
|
err := c.MustBindWith(&f, binding.Form)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
AbortBadRequest(c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := search.Accounts(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
AbortBadRequest(c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO c.Header("X-Count", strconv.Itoa(count))
|
|
|
|
AddLimitHeader(c, f.Count)
|
|
|
|
AddOffsetHeader(c, f.Offset)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
|
|
})
|
|
|
|
}
|