mirror of
https://github.com/AlistGo/alist.git
synced 2025-04-21 20:18:47 +08:00
feat: driver manage api
This commit is contained in:
parent
3349982312
commit
b98cd915a4
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
26
server/controllers/driver.go
Normal file
26
server/controllers/driver.go
Normal 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)
|
||||
}
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user