🐛 fix #600 aliyundrive move file

pull/661/head
Xhofe 2022-02-23 14:56:17 +08:00
parent b4ad301d53
commit aa79f49e25
2 changed files with 18 additions and 6 deletions

View File

@ -8,9 +8,9 @@ import (
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils" "github.com/Xhofe/alist/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
jsoniter "github.com/json-iterator/go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"path/filepath" "path/filepath"
"strings"
"time" "time"
) )
@ -190,7 +190,7 @@ func (driver AliDrive) rename(fileId, name string, account *model.Account) error
return fmt.Errorf("%+v", resp) return fmt.Errorf("%+v", resp)
} }
func (driver AliDrive) batch(srcId, dstId string, account *model.Account) error { func (driver AliDrive) batch(srcId, dstId string, url string, account *model.Account) error {
var e AliRespError var e AliRespError
res, err := aliClient.R().SetError(&e). res, err := aliClient.R().SetError(&e).
SetHeader("authorization", "Bearer\t"+account.AccessToken). SetHeader("authorization", "Bearer\t"+account.AccessToken).
@ -208,6 +208,7 @@ func (driver AliDrive) batch(srcId, dstId string, account *model.Account) error
"to_drive_id": account.DriveId, "to_drive_id": account.DriveId,
"to_parent_file_id": dstId, "to_parent_file_id": dstId,
}, },
"url": url,
}, },
}, },
"resource": "file", "resource": "file",
@ -222,12 +223,13 @@ func (driver AliDrive) batch(srcId, dstId string, account *model.Account) error
return err return err
} else { } else {
_ = model.SaveAccount(account) _ = model.SaveAccount(account)
return driver.batch(srcId, dstId, account) return driver.batch(srcId, dstId, url, account)
} }
} }
return fmt.Errorf("%s", e.Message) return fmt.Errorf("%s", e.Message)
} }
if strings.Contains(res.String(), `"status":200`) { status := jsoniter.Get(res.Body(), "status").ToInt()
if status < 400 && status >= 100 {
return nil return nil
} }
return errors.New(res.String()) return errors.New(res.String())

View File

@ -309,7 +309,7 @@ func (driver AliDrive) Move(src string, dst string, account *model.Account) erro
if err != nil { if err != nil {
return err return err
} }
err = driver.batch(srcFile.Id, dstDirFile.Id, account) err = driver.batch(srcFile.Id, dstDirFile.Id, "/file/move", account)
return err return err
} }
@ -324,7 +324,17 @@ func (driver AliDrive) Rename(src string, dst string, account *model.Account) er
} }
func (driver AliDrive) Copy(src string, dst string, account *model.Account) error { func (driver AliDrive) Copy(src string, dst string, account *model.Account) error {
return base.ErrNotSupport dstDir, _ := filepath.Split(dst)
srcFile, err := driver.File(src, account)
if err != nil {
return err
}
dstDirFile, err := driver.File(dstDir, account)
if err != nil {
return err
}
err = driver.batch(srcFile.Id, dstDirFile.Id, "/file/copy", account)
return err
} }
func (driver AliDrive) Delete(path string, account *model.Account) error { func (driver AliDrive) Delete(path string, account *model.Account) error {