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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/alist-org/alist/v3/internal/bootstrap/data"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"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/drivers"
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/operations"
|
||||||
|
@ -38,7 +39,7 @@ func convert(s string) string {
|
||||||
func generateDriversJson() {
|
func generateDriversJson() {
|
||||||
drivers := make(Drivers)
|
drivers := make(Drivers)
|
||||||
drivers["drivers"] = make(KV[interface{}])
|
drivers["drivers"] = make(KV[interface{}])
|
||||||
driverItemsMap := operations.GetDriverItemsMap()
|
driverItemsMap := operations.GetDriverInfoMap()
|
||||||
for k, v := range driverItemsMap {
|
for k, v := range driverItemsMap {
|
||||||
drivers["drivers"][k] = k
|
drivers["drivers"][k] = k
|
||||||
items := make(KV[interface{}])
|
items := make(KV[interface{}])
|
||||||
|
|
|
@ -17,6 +17,7 @@ var config = driver.Config{
|
||||||
Name: "Virtual",
|
Name: "Virtual",
|
||||||
OnlyLocal: true,
|
OnlyLocal: true,
|
||||||
LocalSort: true,
|
LocalSort: true,
|
||||||
|
NeedMs: true,
|
||||||
//NoCache: true,
|
//NoCache: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package driver
|
package driver
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
LocalSort bool
|
LocalSort bool `json:"local_sort"`
|
||||||
OnlyLocal bool
|
OnlyLocal bool `json:"only_local"`
|
||||||
OnlyProxy bool
|
OnlyProxy bool `json:"only_proxy"`
|
||||||
NoCache bool
|
NoCache bool `json:"no_cache"`
|
||||||
NoUpload bool
|
NoUpload bool `json:"no_upload"`
|
||||||
DefaultRoot string
|
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 {
|
func (c Config) MustProxy() bool {
|
||||||
|
|
|
@ -13,9 +13,10 @@ type Item struct {
|
||||||
Help string `json:"help"`
|
Help string `json:"help"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Items struct {
|
type Info struct {
|
||||||
Common []Item `json:"common"`
|
Common []Item `json:"common"`
|
||||||
Additional []Item `json:"additional"`
|
Additional []Item `json:"additional"`
|
||||||
|
Config Config `json:"config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IRootFolderPath interface {
|
type IRootFolderPath interface {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
type New func() driver.Driver
|
type New func() driver.Driver
|
||||||
|
|
||||||
var driverNewMap = map[string]New{}
|
var driverNewMap = map[string]New{}
|
||||||
var driverItemsMap = map[string]driver.Items{}
|
var driverInfoMap = map[string]driver.Info{}
|
||||||
|
|
||||||
func RegisterDriver(config driver.Config, driver New) {
|
func RegisterDriver(config driver.Config, driver New) {
|
||||||
// log.Infof("register driver: [%s]", config.Name)
|
// log.Infof("register driver: [%s]", config.Name)
|
||||||
|
@ -31,14 +31,14 @@ func GetDriverNew(name string) (New, error) {
|
||||||
|
|
||||||
func GetDriverNames() []string {
|
func GetDriverNames() []string {
|
||||||
var driverNames []string
|
var driverNames []string
|
||||||
for k := range driverItemsMap {
|
for k := range driverInfoMap {
|
||||||
driverNames = append(driverNames, k)
|
driverNames = append(driverNames, k)
|
||||||
}
|
}
|
||||||
return driverNames
|
return driverNames
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDriverItemsMap() map[string]driver.Items {
|
func GetDriverInfoMap() map[string]driver.Info {
|
||||||
return driverItemsMap
|
return driverInfoMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerDriverItems(config driver.Config, addition driver.Additional) {
|
func registerDriverItems(config driver.Config, addition driver.Additional) {
|
||||||
|
@ -46,9 +46,10 @@ func registerDriverItems(config driver.Config, addition driver.Additional) {
|
||||||
tAddition := reflect.TypeOf(addition)
|
tAddition := reflect.TypeOf(addition)
|
||||||
mainItems := getMainItems(config)
|
mainItems := getMainItems(config)
|
||||||
additionalItems := getAdditionalItems(tAddition, config.DefaultRoot)
|
additionalItems := getAdditionalItems(tAddition, config.DefaultRoot)
|
||||||
driverItemsMap[config.Name] = driver.Items{
|
driverInfoMap[config.Name] = driver.Info{
|
||||||
Common: mainItems,
|
Common: mainItems,
|
||||||
Additional: additionalItems,
|
Additional: additionalItems,
|
||||||
|
Config: config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDriverItemsMap(t *testing.T) {
|
func TestDriverItemsMap(t *testing.T) {
|
||||||
itemsMap := operations.GetDriverItemsMap()
|
itemsMap := operations.GetDriverInfoMap()
|
||||||
if len(itemsMap) != 0 {
|
if len(itemsMap) != 0 {
|
||||||
t.Logf("driverItemsMap: %v", itemsMap)
|
t.Logf("driverInfoMap: %v", itemsMap)
|
||||||
} else {
|
} 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"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ListDriverItems(c *gin.Context) {
|
func ListDriverInfo(c *gin.Context) {
|
||||||
common.SuccessResp(c, operations.GetDriverItemsMap())
|
common.SuccessResp(c, operations.GetDriverInfoMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListDriverNames(c *gin.Context) {
|
func ListDriverNames(c *gin.Context) {
|
||||||
common.SuccessResp(c, operations.GetDriverNames())
|
common.SuccessResp(c, operations.GetDriverNames())
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDriverItems(c *gin.Context) {
|
func GetDriverInfo(c *gin.Context) {
|
||||||
driverName := c.Query("driver")
|
driverName := c.Query("driver")
|
||||||
itemsMap := operations.GetDriverItemsMap()
|
infoMap := operations.GetDriverInfoMap()
|
||||||
items, ok := itemsMap[driverName]
|
items, ok := infoMap[driverName]
|
||||||
if !ok {
|
if !ok {
|
||||||
common.ErrorStrResp(c, fmt.Sprintf("driver [%s] not found", driverName), 404)
|
common.ErrorStrResp(c, fmt.Sprintf("driver [%s] not found", driverName), 404)
|
||||||
return
|
return
|
||||||
|
|
|
@ -70,9 +70,9 @@ func admin(g *gin.RouterGroup) {
|
||||||
storage.POST("/disable", handles.DisableStorage)
|
storage.POST("/disable", handles.DisableStorage)
|
||||||
|
|
||||||
driver := g.Group("/driver")
|
driver := g.Group("/driver")
|
||||||
driver.GET("/list", handles.ListDriverItems)
|
driver.GET("/list", handles.ListDriverInfo)
|
||||||
driver.GET("/names", handles.ListDriverNames)
|
driver.GET("/names", handles.ListDriverNames)
|
||||||
driver.GET("/items", handles.GetDriverItems)
|
driver.GET("/info", handles.GetDriverInfo)
|
||||||
|
|
||||||
setting := g.Group("/setting")
|
setting := g.Group("/setting")
|
||||||
setting.GET("/get", handles.GetSetting)
|
setting.GET("/get", handles.GetSetting)
|
||||||
|
|
Loading…
Reference in New Issue