Skip to content

Commit

Permalink
feat: driver manage api
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 26, 2022
1 parent 3349982 commit b98cd91
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bootstrap/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ func init() {
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
})
logrus.SetLevel(logrus.DebugLevel)
}

func Log() {
log.SetOutput(logrus.StandardLogger().Out)
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 {
Expand Down
1 change: 1 addition & 0 deletions internal/operations/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions internal/operations/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
26 changes: 26 additions & 0 deletions server/controllers/driver.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 5 additions & 0 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b98cd91

Please sign in to comment.