From fe940162893235a7dcb32946d4fa0db3207ea384 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Tue, 19 Jul 2022 17:07:12 +0800 Subject: [PATCH] chore: set default root folder in driver config --- drivers/local/meta.go | 9 +++++---- internal/driver/addition.go | 4 ++-- internal/driver/config.go | 13 +++++++------ internal/operations/driver.go | 9 ++++++--- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/local/meta.go b/drivers/local/meta.go index facf0f5e934..c330c5e4c40 100644 --- a/drivers/local/meta.go +++ b/drivers/local/meta.go @@ -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 { diff --git a/internal/driver/addition.go b/internal/driver/addition.go index 55dcfc400c3..0de8a23ed77 100644 --- a/internal/driver/addition.go +++ b/internal/driver/addition.go @@ -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 { diff --git a/internal/driver/config.go b/internal/driver/config.go index 87baae9bd4a..27334818672 100644 --- a/internal/driver/config.go +++ b/internal/driver/config.go @@ -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 { diff --git a/internal/operations/driver.go b/internal/operations/driver.go index 7a45e497c80..544bbd8f2bb 100644 --- a/internal/operations/driver.go +++ b/internal/operations/driver.go @@ -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"