photoprism/internal/api/config.go
Michael Mayer 1f1f92408a Sharing: Token authentication #18
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-06-25 01:20:58 +02:00

34 lines
699 B
Go

package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/config"
)
// GET /api/v1/config
func GetConfig(router *gin.RouterGroup, conf *config.Config) {
router.GET("/config", func(c *gin.Context) {
if Unauthorized(c, conf) {
c.AbortWithStatusJSON(http.StatusUnauthorized, ErrUnauthorized)
return
}
sess := Session(SessionToken(c), conf)
if sess == nil {
c.JSON(http.StatusNotFound, ErrSessionNotFound)
return
}
if sess.User.Guest() {
c.JSON(http.StatusOK, conf.GuestConfig())
} else if sess.User.User() {
c.JSON(http.StatusOK, conf.UserConfig())
} else {
c.JSON(http.StatusOK, conf.PublicConfig())
}
})
}