2019-07-02 22:03:23 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-01-23 10:10:32 +01:00
|
|
|
"net/http"
|
|
|
|
|
2019-07-02 22:03:23 +02:00
|
|
|
"github.com/gin-gonic/gin"
|
2020-07-01 17:16:24 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
|
|
|
"github.com/photoprism/photoprism/internal/query"
|
2020-01-12 14:00:56 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2019-07-02 22:03:23 +02:00
|
|
|
)
|
|
|
|
|
2020-07-01 17:16:24 +02:00
|
|
|
func GetErrors(router *gin.RouterGroup) {
|
2020-07-02 10:03:00 +02:00
|
|
|
router.GET("/errors", func(c *gin.Context) {
|
2020-07-01 17:16:24 +02:00
|
|
|
s := Auth(SessionID(c), acl.ResourceLogs, acl.ActionSearch)
|
|
|
|
|
|
|
|
if s.Invalid() {
|
2020-07-04 12:54:35 +02:00
|
|
|
AbortUnauthorized(c)
|
2020-07-01 17:16:24 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
limit := txt.Int(c.Query("count"))
|
|
|
|
offset := txt.Int(c.Query("offset"))
|
|
|
|
|
2020-07-07 10:51:55 +02:00
|
|
|
if resp, err := query.Errors(limit, offset, c.Query("q")); err != nil {
|
2020-07-01 17:16:24 +02:00
|
|
|
c.AbortWithStatusJSON(400, gin.H{"error": txt.UcFirst(err.Error())})
|
|
|
|
return
|
|
|
|
} else {
|
2021-01-08 09:02:30 +01:00
|
|
|
AddCountHeader(c, len(resp))
|
|
|
|
AddLimitHeader(c, limit)
|
|
|
|
AddOffsetHeader(c, offset)
|
2020-07-01 17:16:24 +02:00
|
|
|
|
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|