mirror of https://github.com/Xhofe/alist
🎇 allow delete deprecated setting
parent
a15dae291e
commit
09e63027d9
|
@ -15,9 +15,13 @@ func InitSettings() {
|
||||||
Description: "version",
|
Description: "version",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Group: model.CONST,
|
Group: model.CONST,
|
||||||
|
Version: conf.GitTag,
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = model.SaveSetting(version)
|
err := model.SaveSetting(version)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed write setting: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
settings := []model.SettingItem{
|
settings := []model.SettingItem{
|
||||||
{
|
{
|
||||||
|
@ -114,8 +118,8 @@ func InitSettings() {
|
||||||
Group: model.PRIVATE,
|
Group: model.PRIVATE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "customize head",
|
Key: "customize head",
|
||||||
Value: `<style>
|
Value: `<style>
|
||||||
.chakra-ui-light{
|
.chakra-ui-light{
|
||||||
background-image: linear-gradient(120deg,#e0c3fc 0%,#8ec5fc 100%) !important;
|
background-image: linear-gradient(120deg,#e0c3fc 0%,#8ec5fc 100%) !important;
|
||||||
background-attachment: fixed;
|
background-attachment: fixed;
|
||||||
|
@ -173,10 +177,22 @@ func InitSettings() {
|
||||||
Group: model.PRIVATE,
|
Group: model.PRIVATE,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, v := range settings {
|
for i, _ := range settings {
|
||||||
_, err := model.GetSettingByKey(v.Key)
|
v := settings[i]
|
||||||
if err == gorm.ErrRecordNotFound {
|
v.Version = conf.GitTag
|
||||||
err = model.SaveSetting(v)
|
o, err := model.GetSettingByKey(v.Key)
|
||||||
|
if err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
err = model.SaveSetting(v)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed write setting: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Fatal("can't get setting: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
o.Version = conf.GitTag
|
||||||
|
err = model.SaveSetting(*o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed write setting: %s", err.Error())
|
log.Fatalf("failed write setting: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ var (
|
||||||
GoVersion string
|
GoVersion string
|
||||||
GitAuthor string
|
GitAuthor string
|
||||||
GitCommit string
|
GitCommit string
|
||||||
GitTag string
|
GitTag string = "dev"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -20,6 +20,7 @@ type SettingItem struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Group int `json:"group"`
|
Group int `json:"group"`
|
||||||
Values string `json:"values"`
|
Values string `json:"values"`
|
||||||
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func SaveSettings(items []SettingItem) error {
|
func SaveSettings(items []SettingItem) error {
|
||||||
|
@ -46,6 +47,13 @@ func GetSettings() (*[]SettingItem, error) {
|
||||||
return &items, nil
|
return &items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteSetting(key string) error {
|
||||||
|
setting := SettingItem{
|
||||||
|
Key: key,
|
||||||
|
}
|
||||||
|
return conf.DB.Delete(&setting).Error
|
||||||
|
}
|
||||||
|
|
||||||
func GetSettingByKey(key string) (*SettingItem, error) {
|
func GetSettingByKey(key string) (*SettingItem, error) {
|
||||||
var items SettingItem
|
var items SettingItem
|
||||||
if err := conf.DB.Where("`key` = ?", key).First(&items).Error; err != nil {
|
if err := conf.DB.Where("`key` = ?", key).First(&items).Error; err != nil {
|
||||||
|
@ -63,7 +71,7 @@ func LoadSettings() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
conf.CheckParent = checkParent.Value == "true"
|
conf.CheckParent = checkParent.Value == "true"
|
||||||
}
|
}
|
||||||
checkDown,err := GetSettingByKey("check down link")
|
checkDown, err := GetSettingByKey("check down link")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
conf.CheckDown = checkDown.Value == "true"
|
conf.CheckDown = checkDown.Value == "true"
|
||||||
}
|
}
|
||||||
|
@ -87,7 +95,7 @@ func LoadSettings() {
|
||||||
|
|
||||||
adminPassword, err := GetSettingByKey("password")
|
adminPassword, err := GetSettingByKey("password")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
conf.Token = utils.GetMD5Encode(fmt.Sprintf("https://github.com/Xhofe/alist-%s",adminPassword.Value))
|
conf.Token = utils.GetMD5Encode(fmt.Sprintf("https://github.com/Xhofe/alist-%s", adminPassword.Value))
|
||||||
}
|
}
|
||||||
|
|
||||||
davUsername, err := GetSettingByKey("WebDAV username")
|
davUsername, err := GetSettingByKey("WebDAV username")
|
||||||
|
|
|
@ -37,3 +37,12 @@ func GetSettingsPublic(c *gin.Context) {
|
||||||
}
|
}
|
||||||
common.SuccessResp(c, settings)
|
common.SuccessResp(c, settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ func InitApiRouter(r *gin.Engine) {
|
||||||
admin.GET("/login", common.Login)
|
admin.GET("/login", common.Login)
|
||||||
admin.GET("/settings", controllers.GetSettings)
|
admin.GET("/settings", controllers.GetSettings)
|
||||||
admin.POST("/settings", controllers.SaveSettings)
|
admin.POST("/settings", controllers.SaveSettings)
|
||||||
|
admin.DELETE("/setting", controllers.DeleteSetting)
|
||||||
|
|
||||||
admin.POST("/account/create", controllers.CreateAccount)
|
admin.POST("/account/create", controllers.CreateAccount)
|
||||||
admin.POST("/account/save", controllers.SaveAccount)
|
admin.POST("/account/save", controllers.SaveAccount)
|
||||||
admin.GET("/accounts", controllers.GetAccounts)
|
admin.GET("/accounts", controllers.GetAccounts)
|
||||||
|
|
Loading…
Reference in New Issue