feat: add driver config in driver info

pull/1604/head
Noah Hsu 2022-08-30 14:39:10 +08:00
parent fec98e7f69
commit 59ec17a353
8 changed files with 31 additions and 26 deletions

View File

@ -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{}])

View File

@ -17,6 +17,7 @@ var config = driver.Config{
Name: "Virtual",
OnlyLocal: true,
LocalSort: true,
NeedMs: true,
//NoCache: true,
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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,
}
}

View File

@ -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")
}
}

View File

@ -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

View File

@ -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)