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