mirror of https://github.com/Xhofe/alist
feat: auto generate settings lang
parent
cc9ccc4e9b
commit
fbcf082ca7
|
@ -39,7 +39,7 @@ jobs:
|
|||
cd ..
|
||||
- name: Copy lang file
|
||||
run: |
|
||||
cp -f ./alist/drivers.json ./alist-web/src/lang/en/
|
||||
cp -f ./alist/lang/*.json ./alist-web/src/lang/en/
|
||||
|
||||
- name: Commit git
|
||||
run: |
|
||||
|
|
|
@ -28,4 +28,5 @@ public/*.html
|
|||
public/assets/
|
||||
public/public/
|
||||
/data
|
||||
log/
|
||||
log/
|
||||
lang/
|
30
cmd/lang.go
30
cmd/lang.go
|
@ -6,6 +6,9 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/alist-org/alist/v3/internal/bootstrap/data"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
_ "github.com/alist-org/alist/v3/drivers"
|
||||
|
@ -56,7 +59,27 @@ func generateDriversJson() {
|
|||
}
|
||||
drivers[k] = items
|
||||
}
|
||||
utils.WriteJsonToFile("drivers.json", drivers)
|
||||
utils.WriteJsonToFile("lang/drivers.json", drivers)
|
||||
}
|
||||
|
||||
func generateSettingsJson() {
|
||||
settings := data.InitialSettings()
|
||||
settingsLang := make(KV[any])
|
||||
for _, setting := range settings {
|
||||
settingsLang[setting.Key] = convert(setting.Key)
|
||||
if setting.Help != "" {
|
||||
settingsLang[fmt.Sprintf("%s-tips", setting.Key)] = setting.Help
|
||||
}
|
||||
if setting.Type == conf.TypeSelect && len(setting.Options) > 0 {
|
||||
options := make(KV[string])
|
||||
_options := strings.Split(setting.Options, ",")
|
||||
for _, o := range _options {
|
||||
options[o] = convert(o)
|
||||
}
|
||||
settingsLang[fmt.Sprintf("%ss", setting.Key)] = options
|
||||
}
|
||||
}
|
||||
utils.WriteJsonToFile("lang/settings.json", settingsLang)
|
||||
}
|
||||
|
||||
// langCmd represents the lang command
|
||||
|
@ -64,7 +87,12 @@ var langCmd = &cobra.Command{
|
|||
Use: "lang",
|
||||
Short: "Generate language json file",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
err := os.MkdirAll("lang", 0777)
|
||||
if err != nil {
|
||||
log.Fatal("failed create folder: %s", err.Error())
|
||||
}
|
||||
generateDriversJson()
|
||||
generateSettingsJson()
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
var initialSettingItems []model.SettingItem
|
||||
|
||||
func initSettings() {
|
||||
initialSettings()
|
||||
InitialSettings()
|
||||
// check deprecated
|
||||
settings, err := db.GetSettingItems()
|
||||
if err != nil {
|
||||
|
@ -58,7 +58,7 @@ func isActive(key string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func initialSettings() {
|
||||
func InitialSettings() []model.SettingItem {
|
||||
var token string
|
||||
if flags.Dev {
|
||||
token = "dev_token"
|
||||
|
@ -105,6 +105,7 @@ func initialSettings() {
|
|||
{Key: conf.VideoAutoplay, Value: "true", Type: conf.TypeBool, Group: model.PREVIEW},
|
||||
// global settings
|
||||
{Key: conf.HideFiles, Value: "/\\/README.md/i", Type: conf.TypeText, Group: model.GLOBAL},
|
||||
{Key: "package_download", Value: "true", Type: conf.TypeBool, Group: model.GLOBAL},
|
||||
{Key: conf.GlobalReadme, Value: "This is global readme", Type: conf.TypeText, Group: model.GLOBAL},
|
||||
{Key: conf.CustomizeHead, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
|
||||
{Key: conf.CustomizeBody, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
|
||||
|
@ -119,6 +120,11 @@ func initialSettings() {
|
|||
{Key: conf.Token, Value: token, Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE},
|
||||
}
|
||||
if flags.Dev {
|
||||
initialSettingItems = append(initialSettingItems, model.SettingItem{Key: "test_deprecated", Value: "test_value", Type: conf.TypeString, Flag: model.DEPRECATED})
|
||||
initialSettingItems = append(initialSettingItems, []model.SettingItem{
|
||||
{Key: "test_deprecated", Value: "test_value", Type: conf.TypeString, Flag: model.DEPRECATED},
|
||||
{Key: "test_options", Value: "a", Type: conf.TypeSelect, Options: "a,b,c"},
|
||||
{Key: "test_help", Type: conf.TypeString, Help: "this is a help message"},
|
||||
}...)
|
||||
}
|
||||
return initialSettingItems
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue