mirror of https://github.com/Xhofe/alist
feat: add driver config in driver info
parent
fec98e7f69
commit
59ec17a353
|
@ -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{}])
|
||||
|
|
|
@ -17,6 +17,7 @@ var config = driver.Config{
|
|||
Name: "Virtual",
|
||||
OnlyLocal: true,
|
||||
LocalSort: true,
|
||||
NeedMs: true,
|
||||
//NoCache: true,
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue