2020-05-29 18:04:30 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2020-06-25 14:54:04 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
2020-05-29 18:04:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// GET /api/v1/config
|
2020-06-25 14:54:04 +02:00
|
|
|
func GetConfig(router *gin.RouterGroup) {
|
2020-05-29 18:04:30 +02:00
|
|
|
router.GET("/config", func(c *gin.Context) {
|
2020-06-25 14:54:04 +02:00
|
|
|
s := Auth(SessionID(c), acl.ResourceConfig, acl.ActionRead)
|
|
|
|
|
|
|
|
if s.Invalid() {
|
2020-07-04 12:54:35 +02:00
|
|
|
AbortUnauthorized(c)
|
2020-05-29 18:04:30 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:54:04 +02:00
|
|
|
conf := service.Config()
|
2020-06-25 01:20:58 +02:00
|
|
|
|
2020-06-25 14:54:04 +02:00
|
|
|
if s.User.Guest() {
|
2020-06-25 01:20:58 +02:00
|
|
|
c.JSON(http.StatusOK, conf.GuestConfig())
|
2020-06-25 14:54:04 +02:00
|
|
|
} else if s.User.Registered() {
|
2020-06-25 01:20:58 +02:00
|
|
|
c.JSON(http.StatusOK, conf.UserConfig())
|
|
|
|
} else {
|
|
|
|
c.JSON(http.StatusOK, conf.PublicConfig())
|
|
|
|
}
|
2020-05-29 18:04:30 +02:00
|
|
|
})
|
|
|
|
}
|