feat: driver manage api

refactor/fs
Noah Hsu 2022-06-26 20:25:02 +08:00
parent 3349982312
commit b98cd915a4
5 changed files with 44 additions and 0 deletions

View File

@ -17,6 +17,7 @@ func init() {
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
})
logrus.SetLevel(logrus.DebugLevel)
}
func Log() {
@ -24,6 +25,9 @@ func Log() {
if args.Debug || args.Dev {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetReportCaller(true)
} else {
logrus.SetLevel(logrus.InfoLevel)
logrus.SetReportCaller(false)
}
logConfig := conf.Conf.Log
if logConfig.Enable {

View File

@ -51,6 +51,7 @@ func CreateAccount(ctx context.Context, account model.Account) error {
if err != nil {
return errors.WithMessage(err, "failed init account but account is already created")
}
log.Debugf("account %+v is created", accountDriver)
accountsMap.Store(account.VirtualPath, accountDriver)
return nil
}

View File

@ -28,6 +28,14 @@ func GetDriverNew(name string) (New, error) {
return n, nil
}
func GetDriverNames() []string {
var driverNames []string
for k := range driverItemsMap {
driverNames = append(driverNames, k)
}
return driverNames
}
func GetDriverItemsMap() map[string]driver.Items {
return driverItemsMap
}

View File

@ -0,0 +1,26 @@
package controllers
import (
"github.com/alist-org/alist/v3/internal/operations"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
)
func ListDriverItems(c *gin.Context) {
common.SuccessResp(c, operations.GetDriverItemsMap())
}
func ListDriverNames(c *gin.Context) {
common.SuccessResp(c, operations.GetDriverNames())
}
func GetDriverItems(c *gin.Context) {
driverName := c.Query("driver")
itemsMap := operations.GetDriverItemsMap()
items, ok := itemsMap[driverName]
if !ok {
common.ErrorStrResp(c, "driver not found", 404)
return
}
common.SuccessResp(nil, items)
}

View File

@ -36,6 +36,11 @@ func Init(r *gin.Engine) {
account.POST("/create", controllers.CreateAccount)
account.POST("/update", controllers.UpdateAccount)
account.POST("/delete", controllers.DeleteAccount)
driver := admin.Group("/driver")
driver.GET("/list", controllers.ListDriverItems)
driver.GET("/names", controllers.ListDriverNames)
driver.GET("/items", controllers.GetDriverItems)
}
func Cors(r *gin.Engine) {