mirror of https://github.com/Xhofe/alist
chore: set default root folder in driver config
parent
184b9d1e6c
commit
fe94016289
|
@ -10,10 +10,11 @@ type Addition struct {
|
|||
}
|
||||
|
||||
var config = driver.Config{
|
||||
Name: "Local",
|
||||
OnlyLocal: true,
|
||||
LocalSort: true,
|
||||
NoCache: true,
|
||||
Name: "Local",
|
||||
OnlyLocal: true,
|
||||
LocalSort: true,
|
||||
NoCache: true,
|
||||
DefaultRoot: "/",
|
||||
}
|
||||
|
||||
func New() driver.Driver {
|
||||
|
|
|
@ -27,11 +27,11 @@ type IRootFolderId interface {
|
|||
}
|
||||
|
||||
type RootFolderPath struct {
|
||||
RootFolder string `json:"root_folder" help:"root folder path" default:"/"`
|
||||
RootFolder string `json:"root_folder" required:"true" help:"root folder path"`
|
||||
}
|
||||
|
||||
type RootFolderId struct {
|
||||
RootFolder string `json:"root_folder" help:"root folder id"`
|
||||
RootFolder string `json:"root_folder" required:"true" help:"root folder id"`
|
||||
}
|
||||
|
||||
func (r RootFolderPath) GetRootFolderPath() string {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package driver
|
||||
|
||||
type Config struct {
|
||||
Name string
|
||||
LocalSort bool
|
||||
OnlyLocal bool
|
||||
OnlyProxy bool
|
||||
NoCache bool
|
||||
NoUpload bool
|
||||
Name string
|
||||
LocalSort bool
|
||||
OnlyLocal bool
|
||||
OnlyProxy bool
|
||||
NoCache bool
|
||||
NoUpload bool
|
||||
DefaultRoot string
|
||||
}
|
||||
|
||||
func (c Config) MustProxy() bool {
|
||||
|
|
|
@ -45,7 +45,7 @@ func registerDriverItems(config driver.Config, addition driver.Additional) {
|
|||
log.Debugf("addition of %s: %+v", config.Name, addition)
|
||||
tAddition := reflect.TypeOf(addition)
|
||||
mainItems := getMainItems(config)
|
||||
additionalItems := getAdditionalItems(tAddition)
|
||||
additionalItems := getAdditionalItems(tAddition, config.DefaultRoot)
|
||||
driverItemsMap[config.Name] = driver.Items{
|
||||
Main: mainItems,
|
||||
Additional: additionalItems,
|
||||
|
@ -109,12 +109,12 @@ func getMainItems(config driver.Config) []driver.Item {
|
|||
return items
|
||||
}
|
||||
|
||||
func getAdditionalItems(t reflect.Type) []driver.Item {
|
||||
func getAdditionalItems(t reflect.Type, defaultRoot string) []driver.Item {
|
||||
var items []driver.Item
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
if field.Type.Kind() == reflect.Struct {
|
||||
items = append(items, getAdditionalItems(field.Type)...)
|
||||
items = append(items, getAdditionalItems(field.Type, defaultRoot)...)
|
||||
continue
|
||||
}
|
||||
tag := field.Tag
|
||||
|
@ -133,6 +133,9 @@ func getAdditionalItems(t reflect.Type) []driver.Item {
|
|||
if tag.Get("type") != "" {
|
||||
item.Type = tag.Get("type")
|
||||
}
|
||||
if item.Name == "root_folder" && item.Default == "" {
|
||||
item.Default = defaultRoot
|
||||
}
|
||||
// set default type to string
|
||||
if item.Type == "" {
|
||||
item.Type = "string"
|
||||
|
|
Loading…
Reference in New Issue