2021-11-17 09:20:57 +00:00
|
|
|
package bootstrap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Xhofe/alist/conf"
|
|
|
|
"github.com/Xhofe/alist/model"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitSettings() {
|
|
|
|
log.Infof("init settings...")
|
|
|
|
version := model.SettingItem{
|
|
|
|
Key: "version",
|
|
|
|
Value: conf.GitTag,
|
|
|
|
Description: "version",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.CONST,
|
2021-12-08 11:36:07 +00:00
|
|
|
Version: conf.GitTag,
|
2021-11-17 09:20:57 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 11:36:07 +00:00
|
|
|
err := model.SaveSetting(version)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed write setting: %s", err.Error())
|
|
|
|
}
|
2021-11-17 09:20:57 +00:00
|
|
|
|
|
|
|
settings := []model.SettingItem{
|
|
|
|
{
|
|
|
|
Key: "title",
|
|
|
|
Value: "Alist",
|
|
|
|
Description: "title",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PUBLIC,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "password",
|
|
|
|
Value: "alist",
|
|
|
|
Description: "password",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PRIVATE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "logo",
|
2021-12-05 05:43:08 +00:00
|
|
|
Value: "https://store.heytapimage.com/cdo-portal/feedback/202112/05/1542f45f86b8609495b69c5380753135.png",
|
2021-11-17 09:20:57 +00:00
|
|
|
Description: "logo",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PUBLIC,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "favicon",
|
2021-12-05 05:43:08 +00:00
|
|
|
Value: "https://store.heytapimage.com/cdo-portal/feedback/202112/05/1542f45f86b8609495b69c5380753135.png",
|
2021-11-17 09:20:57 +00:00
|
|
|
Description: "favicon",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PUBLIC,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "icon color",
|
|
|
|
Value: "teal.300",
|
|
|
|
Description: "icon's color",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PUBLIC,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "text types",
|
2021-12-19 13:24:04 +00:00
|
|
|
Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp,tsx,vtt,srt,ass",
|
2021-11-17 09:20:57 +00:00
|
|
|
Type: "string",
|
|
|
|
Description: "text type extensions",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "hide readme file",
|
|
|
|
Value: "true",
|
|
|
|
Type: "bool",
|
|
|
|
Description: "hide readme file? ",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "music cover",
|
|
|
|
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
|
|
|
|
Description: "music cover image",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PUBLIC,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "site beian",
|
|
|
|
Description: "chinese beian info",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PUBLIC,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "home readme url",
|
|
|
|
Description: "when have multiple, the readme file to show",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PUBLIC,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "markdown theme",
|
|
|
|
Value: "vuepress",
|
|
|
|
Description: "default | github | vuepress",
|
|
|
|
Group: model.PUBLIC,
|
|
|
|
Type: "select",
|
|
|
|
Values: "default,github,vuepress",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "autoplay video",
|
|
|
|
Value: "false",
|
|
|
|
Type: "bool",
|
2021-11-17 14:19:11 +00:00
|
|
|
Group: model.PUBLIC,
|
2021-11-17 09:20:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "autoplay audio",
|
|
|
|
Value: "false",
|
|
|
|
Type: "bool",
|
2021-11-17 14:19:11 +00:00
|
|
|
Group: model.PUBLIC,
|
2021-11-17 09:20:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "check parent folder",
|
|
|
|
Value: "false",
|
|
|
|
Type: "bool",
|
|
|
|
Description: "check parent folder password",
|
2021-11-17 14:19:11 +00:00
|
|
|
Group: model.PRIVATE,
|
2021-11-17 09:20:57 +00:00
|
|
|
},
|
|
|
|
{
|
2021-12-08 11:36:07 +00:00
|
|
|
Key: "customize head",
|
|
|
|
Value: `<style>
|
2021-12-05 05:43:08 +00:00
|
|
|
.chakra-ui-light{
|
|
|
|
background-image: linear-gradient(120deg,#e0c3fc 0%,#8ec5fc 100%) !important;
|
|
|
|
background-attachment: fixed;
|
|
|
|
}
|
|
|
|
.main-box {
|
|
|
|
border-radius: 15px !important;
|
|
|
|
}
|
|
|
|
.chakra-ui-light .main-box {
|
|
|
|
background-color: white !important;
|
|
|
|
}
|
|
|
|
.chakra-ui-light .readme-box {
|
|
|
|
background-color: white !important;
|
|
|
|
}
|
|
|
|
.readme-box {
|
|
|
|
border-radius: 15px !important;
|
|
|
|
}
|
|
|
|
</style>`,
|
2021-11-17 09:20:57 +00:00
|
|
|
Type: "text",
|
2021-12-05 05:43:08 +00:00
|
|
|
Description: "Customize head, placed at the beginning of the head",
|
2021-11-17 14:19:11 +00:00
|
|
|
Group: model.PRIVATE,
|
2021-11-17 09:20:57 +00:00
|
|
|
},
|
|
|
|
{
|
2021-12-05 05:43:08 +00:00
|
|
|
Key: "customize body",
|
2021-11-17 09:20:57 +00:00
|
|
|
Value: "",
|
|
|
|
Type: "text",
|
2021-12-05 05:43:08 +00:00
|
|
|
Description: "Customize script, placed at the end of the body",
|
2021-11-17 14:19:11 +00:00
|
|
|
Group: model.PRIVATE,
|
2021-11-17 09:20:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "animation",
|
|
|
|
Value: "true",
|
|
|
|
Type: "bool",
|
|
|
|
Description: "when there are a lot of files, the animation will freeze when opening",
|
2021-11-17 14:19:11 +00:00
|
|
|
Group: model.PUBLIC,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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,
|
2021-11-17 09:20:57 +00:00
|
|
|
},
|
2021-11-28 08:18:09 +00:00
|
|
|
{
|
|
|
|
Key: "WebDAV username",
|
|
|
|
Value: "alist",
|
|
|
|
Description: "WebDAV username",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PRIVATE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "WebDAV password",
|
|
|
|
Value: "alist",
|
|
|
|
Description: "WebDAV password",
|
|
|
|
Type: "string",
|
|
|
|
Group: model.PRIVATE,
|
|
|
|
},
|
2021-11-17 09:20:57 +00:00
|
|
|
}
|
2021-12-08 11:36:07 +00:00
|
|
|
for i, _ := range settings {
|
|
|
|
v := settings[i]
|
|
|
|
v.Version = conf.GitTag
|
|
|
|
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)
|
2021-11-17 09:20:57 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed write setting: %s", err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
model.LoadSettings()
|
2021-11-17 14:19:11 +00:00
|
|
|
}
|