mirror of https://github.com/Xhofe/alist
✨ grouping settings
parent
04752f7473
commit
4c00866249
|
@ -10,16 +10,8 @@ import (
|
|||
|
||||
func InitSettings() {
|
||||
log.Infof("init settings...")
|
||||
version := model.SettingItem{
|
||||
Key: "version",
|
||||
Value: conf.GitTag,
|
||||
Description: "version",
|
||||
Type: "string",
|
||||
Group: model.CONST,
|
||||
Version: conf.GitTag,
|
||||
}
|
||||
|
||||
err := model.SaveSetting(version)
|
||||
err := model.SaveSetting(model.Version)
|
||||
if err != nil {
|
||||
log.Fatalf("failed write setting: %s", err.Error())
|
||||
}
|
||||
|
@ -30,153 +22,155 @@ func InitSettings() {
|
|||
Value: "Alist",
|
||||
Description: "title",
|
||||
Type: "string",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "password",
|
||||
Value: "alist",
|
||||
Description: "password",
|
||||
Type: "string",
|
||||
Group: model.PRIVATE,
|
||||
Access: model.PRIVATE,
|
||||
Group: model.BACK,
|
||||
},
|
||||
{
|
||||
Key: "logo",
|
||||
Value: "https://store.heytapimage.com/cdo-portal/feedback/202112/05/1542f45f86b8609495b69c5380753135.png",
|
||||
Description: "logo",
|
||||
Type: "string",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "favicon",
|
||||
Value: "https://store.heytapimage.com/cdo-portal/feedback/202112/05/1542f45f86b8609495b69c5380753135.png",
|
||||
Description: "favicon",
|
||||
Type: "string",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "icon color",
|
||||
Value: "#1890ff",
|
||||
Description: "icon's color",
|
||||
Type: "string",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "text types",
|
||||
Value: strings.Join(conf.TextTypes, ","),
|
||||
Type: "string",
|
||||
Description: "text type extensions",
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "hide readme file",
|
||||
Value: "true",
|
||||
Type: "bool",
|
||||
Description: "hide readme file? ",
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "music cover",
|
||||
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
|
||||
Description: "music cover image",
|
||||
Type: "string",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "site beian",
|
||||
Description: "chinese beian info",
|
||||
Type: "string",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "home readme url",
|
||||
Description: "when have multiple, the readme file to show",
|
||||
Type: "string",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "markdown theme",
|
||||
Value: "vuepress",
|
||||
Description: "default | github | vuepress",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Type: "select",
|
||||
Values: "default,github,vuepress",
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "autoplay video",
|
||||
Value: "false",
|
||||
Type: "bool",
|
||||
Group: model.PUBLIC,
|
||||
Key: "autoplay video",
|
||||
Value: "false",
|
||||
Type: "bool",
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "autoplay audio",
|
||||
Value: "false",
|
||||
Type: "bool",
|
||||
Group: model.PUBLIC,
|
||||
Key: "autoplay audio",
|
||||
Value: "false",
|
||||
Type: "bool",
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "check parent folder",
|
||||
Value: "false",
|
||||
Type: "bool",
|
||||
Description: "check parent folder password",
|
||||
Group: model.PRIVATE,
|
||||
Access: model.PRIVATE,
|
||||
Group: model.BACK,
|
||||
},
|
||||
{
|
||||
Key: "customize head",
|
||||
Value: `<style>
|
||||
.chakra-ui-light{
|
||||
background-color: #edddfd;
|
||||
}
|
||||
.main-box {
|
||||
border-radius: 15px !important;
|
||||
box-shadow: unset !important;
|
||||
}
|
||||
.chakra-ui-light .main-box {
|
||||
background-color: rgba(255,255,255,0.9) !important;
|
||||
}
|
||||
.chakra-ui-light .readme-box {
|
||||
background-color: rgba(255,255,255,0.9) !important;
|
||||
}
|
||||
.readme-box {
|
||||
border-radius: 15px !important;
|
||||
box-shadow: unset !important;
|
||||
}
|
||||
</style>`,
|
||||
Key: "customize head",
|
||||
Value: "",
|
||||
Type: "text",
|
||||
Description: "Customize head, placed at the beginning of the head",
|
||||
Group: model.PRIVATE,
|
||||
Access: model.PRIVATE,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "customize body",
|
||||
Value: "",
|
||||
Type: "text",
|
||||
Description: "Customize script, placed at the end of the body",
|
||||
Group: model.PRIVATE,
|
||||
Access: model.PRIVATE,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "animation",
|
||||
Value: "true",
|
||||
Type: "bool",
|
||||
Description: "when there are a lot of files, the animation will freeze when opening",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Group: model.FRONT,
|
||||
},
|
||||
{
|
||||
Key: "check down link",
|
||||
Value: "false",
|
||||
Type: "bool",
|
||||
Description: "check down link password, your link will be 'https://alist.com/d/filename?pw=xxx'",
|
||||
Group: model.PUBLIC,
|
||||
Access: model.PUBLIC,
|
||||
Group: model.BACK,
|
||||
},
|
||||
{
|
||||
Key: "WebDAV username",
|
||||
Value: "alist",
|
||||
Description: "WebDAV username",
|
||||
Type: "string",
|
||||
Group: model.PRIVATE,
|
||||
Access: model.PRIVATE,
|
||||
Group: model.BACK,
|
||||
},
|
||||
{
|
||||
Key: "WebDAV password",
|
||||
Value: "alist",
|
||||
Description: "WebDAV password",
|
||||
Type: "string",
|
||||
Group: model.PRIVATE,
|
||||
Access: model.PRIVATE,
|
||||
Group: model.BACK,
|
||||
},
|
||||
}
|
||||
for i, _ := range settings {
|
||||
|
@ -193,8 +187,10 @@ func InitSettings() {
|
|||
log.Fatal("can't get setting: %s", err.Error())
|
||||
}
|
||||
} else {
|
||||
o.Version = conf.GitTag
|
||||
err = model.SaveSetting(*o)
|
||||
//o.Version = conf.GitTag
|
||||
//err = model.SaveSetting(*o)
|
||||
v.Value = o.Value
|
||||
err = model.SaveSetting(v)
|
||||
if err != nil {
|
||||
log.Fatalf("failed write setting: %s", err.Error())
|
||||
}
|
||||
|
|
|
@ -13,16 +13,33 @@ const (
|
|||
CONST
|
||||
)
|
||||
|
||||
const (
|
||||
FRONT = iota
|
||||
BACK
|
||||
OTHER
|
||||
)
|
||||
|
||||
type SettingItem struct {
|
||||
Key string `json:"key" gorm:"primaryKey" binding:"required"`
|
||||
Value string `json:"value"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
Group int `json:"group"`
|
||||
Access int `json:"access"`
|
||||
Values string `json:"values"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
var Version = SettingItem{
|
||||
Key: "version",
|
||||
Value: conf.GitTag,
|
||||
Description: "version",
|
||||
Type: "string",
|
||||
Access: CONST,
|
||||
Version: conf.GitTag,
|
||||
Group: OTHER,
|
||||
}
|
||||
|
||||
func SaveSettings(items []SettingItem) error {
|
||||
return conf.DB.Save(items).Error
|
||||
}
|
||||
|
@ -31,20 +48,29 @@ func SaveSetting(item SettingItem) error {
|
|||
return conf.DB.Save(item).Error
|
||||
}
|
||||
|
||||
func GetSettingsPublic() (*[]SettingItem, error) {
|
||||
func GetSettingsPublic() ([]SettingItem, error) {
|
||||
var items []SettingItem
|
||||
if err := conf.DB.Where("`group` <> ?", 1).Find(&items).Error; err != nil {
|
||||
if err := conf.DB.Where("`access` <> ?", 1).Find(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &items, nil
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func GetSettings() (*[]SettingItem, error) {
|
||||
func GetSettingsByGroup(group int) ([]SettingItem, error) {
|
||||
var items []SettingItem
|
||||
if err := conf.DB.Where("`group` = ?", group).Find(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append([]SettingItem{Version}, items...)
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func GetSettings() ([]SettingItem, error) {
|
||||
var items []SettingItem
|
||||
if err := conf.DB.Find(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &items, nil
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func DeleteSetting(key string) error {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func SaveSettings(c *gin.Context) {
|
||||
|
@ -22,7 +23,17 @@ func SaveSettings(c *gin.Context) {
|
|||
}
|
||||
|
||||
func GetSettings(c *gin.Context) {
|
||||
settings, err := model.GetSettings()
|
||||
groupStr := c.Query("group")
|
||||
var settings []model.SettingItem
|
||||
var err error
|
||||
if groupStr == "" {
|
||||
settings, err = model.GetSettings()
|
||||
} else {
|
||||
group, err := strconv.Atoi(groupStr)
|
||||
if err == nil {
|
||||
settings, err = model.GetSettingsByGroup(group)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
|
@ -36,7 +47,7 @@ func GetSettingsPublic(c *gin.Context) {
|
|||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
*settings = append(*settings, model.SettingItem{
|
||||
settings = append(settings, model.SettingItem{
|
||||
Key: "no cors",
|
||||
Value: base.GetNoCors(),
|
||||
Description: "",
|
||||
|
|
Loading…
Reference in New Issue