Skip to content

Commit

Permalink
feat(baidu_photo): optional delete album origin file (close #4872 in #…
Browse files Browse the repository at this point in the history
  • Loading branch information
foxxorcat authored Jul 31, 2023
1 parent ce0c362 commit 9f08353
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions drivers/baidu_photo/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions drivers/baidu_photo/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
1 change: 1 addition & 0 deletions drivers/baidu_photo/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/baidu_photo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9f08353

Please sign in to comment.