fix(onedrive): either id or path in parentReference must be specified (close #3028)

pull/3556/head
Andy Hsu 2023-02-21 16:19:46 +08:00
parent 95b3b87672
commit fd36ce59f6
1 changed files with 15 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"path"
"github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/internal/driver"
@ -75,9 +76,19 @@ func (d *Onedrive) MakeDir(ctx context.Context, parentDir model.Obj, dirName str
}
func (d *Onedrive) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
parentPath := ""
if dstDir.GetID() == "" {
parentPath = dstDir.GetPath()
if utils.PathEqual(parentPath, "/") {
parentPath = path.Join("/drive/root", parentPath)
} else {
parentPath = path.Join("/drive/root:/", parentPath)
}
}
data := base.Json{
"parentReference": base.Json{
"id": dstDir.GetID(),
"path": parentPath,
},
"name": srcObj.GetName(),
}
@ -89,13 +100,15 @@ func (d *Onedrive) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
}
func (d *Onedrive) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
//dstDir, err := op.GetUnwrap(ctx, d, stdpath.Dir(srcObj.GetPath()))
var parentID string
if o, ok := srcObj.(*Object); ok {
parentID = o.ParentID
} else {
return fmt.Errorf("srcObj is not Object")
}
if parentID == "" {
parentID = "root"
}
data := base.Json{
"parentReference": base.Json{
"id": parentID,