From 9f08353d314ccb8f095604ace567d07a550c3cc2 Mon Sep 17 00:00:00 2001 From: foxxorcat <95907542+foxxorcat@users.noreply.github.com> Date: Mon, 31 Jul 2023 18:29:45 +0800 Subject: [PATCH] feat(baidu_photo): optional delete album origin file (close #4872 in #4875) --- drivers/baidu_photo/driver.go | 4 ++-- drivers/baidu_photo/help.go | 7 +++++++ drivers/baidu_photo/meta.go | 1 + drivers/baidu_photo/utils.go | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/baidu_photo/driver.go b/drivers/baidu_photo/driver.go index 2a55939fe99..ff47d25f784 100644 --- a/drivers/baidu_photo/driver.go +++ b/drivers/baidu_photo/driver.go @@ -175,9 +175,9 @@ func (d *BaiduPhoto) Copy(ctx context.Context, srcObj, dstDir model.Obj) (model. } func (d *BaiduPhoto) Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj, error) { - // 仅支持相册之间移动 if file, ok := srcObj.(*AlbumFile); ok { - if _, ok := dstDir.(*Album); ok { + switch dstDir.(type) { + case *Album, *Root: // albumfile -> root -> album or albumfile -> root newObj, err := d.Copy(ctx, srcObj, dstDir) if err != nil { return nil, err diff --git a/drivers/baidu_photo/help.go b/drivers/baidu_photo/help.go index e9b9331b7e0..d689f81d05f 100644 --- a/drivers/baidu_photo/help.go +++ b/drivers/baidu_photo/help.go @@ -69,3 +69,10 @@ func renameAlbum(album *Album, newName string) *Album { Mtime: time.Now().Unix(), } } + +func BoolToIntStr(b bool) string { + if b { + return "1" + } + return "0" +} diff --git a/drivers/baidu_photo/meta.go b/drivers/baidu_photo/meta.go index 06ab60462fd..e562b54061d 100644 --- a/drivers/baidu_photo/meta.go +++ b/drivers/baidu_photo/meta.go @@ -10,6 +10,7 @@ type Addition struct { ShowType string `json:"show_type" type:"select" options:"root,root_only_album,root_only_file" default:"root"` AlbumID string `json:"album_id"` //AlbumPassword string `json:"album_password"` + DeleteOrigin bool `json:"delete_origin"` ClientID string `json:"client_id" required:"true" default:"iYCeC9g08h5vuP9UqvPHKKSVrKFXGa1v"` ClientSecret string `json:"client_secret" required:"true" default:"jXiFMOPVPCWlO2M5CwWQzffpNPaGTRBG"` } diff --git a/drivers/baidu_photo/utils.go b/drivers/baidu_photo/utils.go index a50022b4663..daaf0a0e5b9 100644 --- a/drivers/baidu_photo/utils.go +++ b/drivers/baidu_photo/utils.go @@ -232,7 +232,7 @@ func (d *BaiduPhoto) DeleteAlbum(ctx context.Context, album *Album) error { r.SetFormData(map[string]string{ "album_id": album.AlbumID, "tid": fmt.Sprint(album.Tid), - "delete_origin_image": "0", // 是否删除原图 0 不删除 1 删除 + "delete_origin_image": BoolToIntStr(d.DeleteOrigin), // 是否删除原图 0 不删除 1 删除 }) }, nil) return err @@ -246,7 +246,7 @@ func (d *BaiduPhoto) DeleteAlbumFile(ctx context.Context, file *AlbumFile) error "album_id": fmt.Sprint(file.AlbumID), "tid": fmt.Sprint(file.Tid), "list": fmt.Sprintf(`[{"fsid":%d,"uk":%d}]`, file.Fsid, file.Uk), - "del_origin": "0", // 是否删除原图 0 不删除 1 删除 + "del_origin": BoolToIntStr(d.DeleteOrigin), // 是否删除原图 0 不删除 1 删除 }) }, nil) return err