mirror of https://github.com/Xhofe/alist
parent
3a41b929c9
commit
3af23f6792
|
@ -1,8 +1,10 @@
|
|||
package handles
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/op"
|
||||
|
@ -116,3 +118,35 @@ func GetStorage(c *gin.Context) {
|
|||
}
|
||||
common.SuccessResp(c, storage)
|
||||
}
|
||||
|
||||
func LoadAllStorages(c *gin.Context) {
|
||||
storages, err := db.GetEnabledStorages()
|
||||
if err != nil {
|
||||
log.Errorf("failed get enabled storages: %+v", err)
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
conf.StoragesLoaded = false
|
||||
go func(storages []model.Storage) {
|
||||
for _, storage := range storages {
|
||||
storageDriver, err := op.GetStorageByMountPath(storage.MountPath)
|
||||
if err != nil {
|
||||
log.Errorf("failed get storage driver: %+v", err)
|
||||
continue
|
||||
}
|
||||
// drop the storage in the driver
|
||||
if err := storageDriver.Drop(context.Background()); err != nil {
|
||||
log.Errorf("failed drop storage: %+v", err)
|
||||
continue
|
||||
}
|
||||
if err := op.LoadStorage(context.Background(), storage); err != nil {
|
||||
log.Errorf("failed get enabled storages: %+v", err)
|
||||
continue
|
||||
}
|
||||
log.Infof("success load storage: [%s], driver: [%s]",
|
||||
storage.MountPath, storage.Driver)
|
||||
}
|
||||
conf.StoragesLoaded = true
|
||||
}(storages)
|
||||
common.SuccessResp(c)
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ func admin(g *gin.RouterGroup) {
|
|||
storage.POST("/delete", handles.DeleteStorage)
|
||||
storage.POST("/enable", handles.EnableStorage)
|
||||
storage.POST("/disable", handles.DisableStorage)
|
||||
storage.POST("/load_all", handles.LoadAllStorages)
|
||||
|
||||
driver := g.Group("/driver")
|
||||
driver.GET("/list", handles.ListDriverInfo)
|
||||
|
|
Loading…
Reference in New Issue