diff --git a/cmd/lang.go b/cmd/lang.go index 25028023..5fb8e51b 100644 --- a/cmd/lang.go +++ b/cmd/lang.go @@ -6,11 +6,12 @@ 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/internal/bootstrap/data" + log "github.com/sirupsen/logrus" + _ "github.com/alist-org/alist/v3/drivers" "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/operations" @@ -38,7 +39,7 @@ func convert(s string) string { func generateDriversJson() { drivers := make(Drivers) drivers["drivers"] = make(KV[interface{}]) - driverItemsMap := operations.GetDriverItemsMap() + driverItemsMap := operations.GetDriverInfoMap() for k, v := range driverItemsMap { drivers["drivers"][k] = k items := make(KV[interface{}]) diff --git a/drivers/virtual/meta.go b/drivers/virtual/meta.go index 13575f93..83b00eb5 100644 --- a/drivers/virtual/meta.go +++ b/drivers/virtual/meta.go @@ -17,6 +17,7 @@ var config = driver.Config{ Name: "Virtual", OnlyLocal: true, LocalSort: true, + NeedMs: true, //NoCache: true, } diff --git a/internal/driver/config.go b/internal/driver/config.go index 27334818..23fbd164 100644 --- a/internal/driver/config.go +++ b/internal/driver/config.go @@ -1,13 +1,14 @@ package driver type Config struct { - Name string - LocalSort bool - OnlyLocal bool - OnlyProxy bool - NoCache bool - NoUpload bool - DefaultRoot string + Name string `json:"name"` + LocalSort bool `json:"local_sort"` + OnlyLocal bool `json:"only_local"` + OnlyProxy bool `json:"only_proxy"` + NoCache bool `json:"no_cache"` + NoUpload bool `json:"no_upload"` + NeedMs bool `json:"need_ms"` // if need get message from user, such as validate code + DefaultRoot string `json:"default_root"` } func (c Config) MustProxy() bool { diff --git a/internal/driver/item.go b/internal/driver/item.go index b1ec55a1..150e897a 100644 --- a/internal/driver/item.go +++ b/internal/driver/item.go @@ -13,9 +13,10 @@ type Item struct { Help string `json:"help"` } -type Items struct { +type Info struct { Common []Item `json:"common"` Additional []Item `json:"additional"` + Config Config `json:"config"` } type IRootFolderPath interface { diff --git a/internal/operations/driver.go b/internal/operations/driver.go index b704dd94..b85e8861 100644 --- a/internal/operations/driver.go +++ b/internal/operations/driver.go @@ -13,7 +13,7 @@ import ( type New func() driver.Driver var driverNewMap = map[string]New{} -var driverItemsMap = map[string]driver.Items{} +var driverInfoMap = map[string]driver.Info{} func RegisterDriver(config driver.Config, driver New) { // log.Infof("register driver: [%s]", config.Name) @@ -31,14 +31,14 @@ func GetDriverNew(name string) (New, error) { func GetDriverNames() []string { var driverNames []string - for k := range driverItemsMap { + for k := range driverInfoMap { driverNames = append(driverNames, k) } return driverNames } -func GetDriverItemsMap() map[string]driver.Items { - return driverItemsMap +func GetDriverInfoMap() map[string]driver.Info { + return driverInfoMap } func registerDriverItems(config driver.Config, addition driver.Additional) { @@ -46,9 +46,10 @@ func registerDriverItems(config driver.Config, addition driver.Additional) { tAddition := reflect.TypeOf(addition) mainItems := getMainItems(config) additionalItems := getAdditionalItems(tAddition, config.DefaultRoot) - driverItemsMap[config.Name] = driver.Items{ + driverInfoMap[config.Name] = driver.Info{ Common: mainItems, Additional: additionalItems, + Config: config, } } diff --git a/internal/operations/driver_test.go b/internal/operations/driver_test.go index e9f088b5..41b86ea0 100644 --- a/internal/operations/driver_test.go +++ b/internal/operations/driver_test.go @@ -8,10 +8,10 @@ import ( ) func TestDriverItemsMap(t *testing.T) { - itemsMap := operations.GetDriverItemsMap() + itemsMap := operations.GetDriverInfoMap() if len(itemsMap) != 0 { - t.Logf("driverItemsMap: %v", itemsMap) + t.Logf("driverInfoMap: %v", itemsMap) } else { - t.Errorf("expected driverItemsMap not empty, but got empty") + t.Errorf("expected driverInfoMap not empty, but got empty") } } diff --git a/server/handles/driver.go b/server/handles/driver.go index 67343a81..8eba4139 100644 --- a/server/handles/driver.go +++ b/server/handles/driver.go @@ -8,18 +8,18 @@ import ( "github.com/gin-gonic/gin" ) -func ListDriverItems(c *gin.Context) { - common.SuccessResp(c, operations.GetDriverItemsMap()) +func ListDriverInfo(c *gin.Context) { + common.SuccessResp(c, operations.GetDriverInfoMap()) } func ListDriverNames(c *gin.Context) { common.SuccessResp(c, operations.GetDriverNames()) } -func GetDriverItems(c *gin.Context) { +func GetDriverInfo(c *gin.Context) { driverName := c.Query("driver") - itemsMap := operations.GetDriverItemsMap() - items, ok := itemsMap[driverName] + infoMap := operations.GetDriverInfoMap() + items, ok := infoMap[driverName] if !ok { common.ErrorStrResp(c, fmt.Sprintf("driver [%s] not found", driverName), 404) return diff --git a/server/router.go b/server/router.go index 10a212e4..b90cb4fc 100644 --- a/server/router.go +++ b/server/router.go @@ -70,9 +70,9 @@ func admin(g *gin.RouterGroup) { storage.POST("/disable", handles.DisableStorage) driver := g.Group("/driver") - driver.GET("/list", handles.ListDriverItems) + driver.GET("/list", handles.ListDriverInfo) driver.GET("/names", handles.ListDriverNames) - driver.GET("/items", handles.GetDriverItems) + driver.GET("/info", handles.GetDriverInfo) setting := g.Group("/setting") setting.GET("/get", handles.GetSetting)