alist/server/controllers/setting.go

56 lines
1.1 KiB
Go
Raw Normal View History

2021-12-07 07:56:43 +00:00
package controllers
2021-10-26 14:28:37 +00:00
import (
2021-12-25 08:44:32 +00:00
"github.com/Xhofe/alist/drivers/base"
2021-10-26 14:28:37 +00:00
"github.com/Xhofe/alist/model"
2021-12-07 07:56:43 +00:00
"github.com/Xhofe/alist/server/common"
2021-11-13 07:53:26 +00:00
"github.com/gin-gonic/gin"
2021-10-26 14:28:37 +00:00
)
2021-11-13 07:53:26 +00:00
func SaveSettings(c *gin.Context) {
2021-10-26 14:28:37 +00:00
var req []model.SettingItem
2021-11-13 07:53:26 +00:00
if err := c.ShouldBind(&req); err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 400)
2021-11-13 07:53:26 +00:00
return
2021-10-26 14:28:37 +00:00
}
if err := model.SaveSettings(req); err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 500)
2021-10-26 14:28:37 +00:00
} else {
2021-11-12 14:56:30 +00:00
model.LoadSettings()
2021-12-07 07:56:43 +00:00
common.SuccessResp(c)
2021-10-26 14:28:37 +00:00
}
}
2021-11-13 07:53:26 +00:00
func GetSettings(c *gin.Context) {
2021-10-29 16:35:29 +00:00
settings, err := model.GetSettings()
2021-10-26 14:28:37 +00:00
if err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 400)
2021-11-13 07:53:26 +00:00
return
2021-10-26 14:28:37 +00:00
}
2021-12-07 07:56:43 +00:00
common.SuccessResp(c, settings)
2021-10-26 14:28:37 +00:00
}
2021-10-27 14:45:36 +00:00
2021-11-13 07:53:26 +00:00
func GetSettingsPublic(c *gin.Context) {
2021-11-03 11:51:19 +00:00
settings, err := model.GetSettingsPublic()
2021-10-27 14:45:36 +00:00
if err != nil {
2021-12-07 07:56:43 +00:00
common.ErrorResp(c, err, 400)
2021-11-13 07:53:26 +00:00
return
2021-10-27 14:45:36 +00:00
}
2021-12-25 08:44:32 +00:00
*settings = append(*settings, model.SettingItem{
Key: "no cors",
Value: base.GetNoCors(),
Description: "",
Type: "string",
})
2021-12-07 07:56:43 +00:00
common.SuccessResp(c, settings)
2021-10-29 16:35:29 +00:00
}
func DeleteSetting(c *gin.Context) {
key := c.Query("key")
if err := model.DeleteSetting(key); err != nil {
common.ErrorResp(c, err, 500)
return
}
common.SuccessResp(c)
}