Feat: GET Site/Config getting global configuration
This commit is contained in:
parent
9d8a462dc4
commit
370a1a0c9f
4 changed files with 65 additions and 2 deletions
37
pkg/serializer/setting.go
Normal file
37
pkg/serializer/setting.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package serializer
|
||||
|
||||
import model "github.com/HFO4/cloudreve/models"
|
||||
|
||||
// SiteConfig 站点全局设置序列
|
||||
type SiteConfig struct {
|
||||
SiteName string `json:"title"`
|
||||
LoginCaptcha bool `json:"loginCaptcha"`
|
||||
RegCaptcha bool `json:"regCaptcha"`
|
||||
ForgetCaptcha bool `json:"forgetCaptcha"`
|
||||
EmailActive bool `json:"emailActive"`
|
||||
QQLogin bool `json:"QQLogin"`
|
||||
Themes string `json:"themes"`
|
||||
DefaultTheme string `json:"defaultTheme"`
|
||||
}
|
||||
|
||||
func checkSettingValue(setting map[string]string, key string) string {
|
||||
if v, ok := setting[key]; ok {
|
||||
return v
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// BuildSiteConfig 站点全局设置
|
||||
func BuildSiteConfig(settings map[string]string) Response {
|
||||
return Response{
|
||||
Data: SiteConfig{
|
||||
SiteName: checkSettingValue(settings, "siteName"),
|
||||
LoginCaptcha: model.IsTrueVal(checkSettingValue(settings, "login_captcha")),
|
||||
RegCaptcha: model.IsTrueVal(checkSettingValue(settings, "reg_captcha")),
|
||||
ForgetCaptcha: model.IsTrueVal(checkSettingValue(settings, "forget_captcha")),
|
||||
EmailActive: model.IsTrueVal(checkSettingValue(settings, "email_active")),
|
||||
QQLogin: model.IsTrueVal(checkSettingValue(settings, "qq_login")),
|
||||
Themes: checkSettingValue(settings, "themes"),
|
||||
DefaultTheme: checkSettingValue(settings, "defaultTheme"),
|
||||
}}
|
||||
}
|
24
routers/controllers/site.go
Normal file
24
routers/controllers/site.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
model "github.com/HFO4/cloudreve/models"
|
||||
"github.com/HFO4/cloudreve/pkg/serializer"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// SiteConfig 获取站点全局配置
|
||||
func SiteConfig(c *gin.Context) {
|
||||
siteConfig := model.GetSettingByNames([]string{
|
||||
"siteName",
|
||||
"login_captcha",
|
||||
"qq_login",
|
||||
"reg_captcha",
|
||||
"email_active",
|
||||
"forget_captcha",
|
||||
"email_active",
|
||||
"themes",
|
||||
"defaultTheme",
|
||||
})
|
||||
|
||||
c.JSON(200, serializer.BuildSiteConfig(siteConfig))
|
||||
}
|
|
@ -29,11 +29,13 @@ func InitRouter() *gin.Engine {
|
|||
v3 := r.Group("/Api/V3")
|
||||
{
|
||||
// 测试用路由
|
||||
v3.GET("Ping", controllers.Ping)
|
||||
v3.GET("Site/Ping", controllers.Ping)
|
||||
// 用户登录
|
||||
v3.POST("User/Session", controllers.UserLogin)
|
||||
// 验证码
|
||||
v3.GET("Captcha", controllers.Captcha)
|
||||
// 站点全局配置
|
||||
v3.GET("Site/Config", controllers.SiteConfig)
|
||||
|
||||
// 需要登录保护的
|
||||
auth := v3.Group("")
|
||||
|
|
|
@ -42,7 +42,7 @@ func TestPing(t *testing.T) {
|
|||
router := InitRouter()
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/Api/V3/Ping", nil)
|
||||
req, _ := http.NewRequest("GET", "/Api/V3/Site/Ping", nil)
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(t, 200, w.Code)
|
||||
|
|
Loading…
Add table
Reference in a new issue