fix: load balance

This commit is contained in:
Xhofe
2022-03-31 21:52:19 +08:00
parent ced61da33a
commit b52e1e8be3
4 changed files with 33 additions and 15 deletions

View File

@ -33,7 +33,12 @@ func ParsePath(rawPath string) (*model.Account, string, base.Driver, error) {
if !ok {
return nil, "", nil, fmt.Errorf("no [%s] driver", account.Type)
}
return &account, strings.TrimPrefix(rawPath, utils.ParsePath(account.Name)), driver, nil
name := utils.ParsePath(account.Name)
bIndex := strings.LastIndex(name, ".balance")
if bIndex != -1 {
name = name[:bIndex]
}
return &account, strings.TrimPrefix(rawPath, name), driver, nil
}
func ErrorResp(c *gin.Context, err error, code int) {

View File

@ -4,22 +4,21 @@ import (
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/drivers/operate"
"github.com/Xhofe/alist/model"
log "github.com/sirupsen/logrus"
)
func Path(rawPath string) (*model.File, []model.File, *model.Account, base.Driver, string, error) {
account, path, driver, err := ParsePath(rawPath)
if err != nil {
if err.Error() == "path not found" {
accountFiles, err := model.GetAccountFilesByPath(rawPath)
if err != nil {
return nil, nil, nil, nil, "", err
}
accountFiles := model.GetAccountFilesByPath(rawPath)
if len(accountFiles) != 0 {
return nil, accountFiles, nil, nil, path, nil
}
}
return nil, nil, nil, nil, "", err
}
log.Debugln("use account: ", account.Name)
file, files, err := operate.Path(driver, account, path)
if err != nil {
return nil, nil, nil, nil, "", err
@ -27,10 +26,7 @@ func Path(rawPath string) (*model.File, []model.File, *model.Account, base.Drive
if file != nil {
return file, nil, account, driver, path, nil
} else {
accountFiles, err := model.GetAccountFilesByPath(rawPath)
if err != nil {
return nil, nil, nil, nil, "", err
}
accountFiles := model.GetAccountFilesByPath(rawPath)
files = append(files, accountFiles...)
return nil, files, account, driver, path, nil
}

View File

@ -18,6 +18,10 @@ func RefreshFolder(c *gin.Context) {
}
account, path_, _, err := common.ParsePath(req.Path)
if err != nil {
if err.Error() == "path not found" && req.Path == "/" {
common.SuccessResp(c)
return
}
common.ErrorResp(c, err, 500)
return
}