From f22232de5dd513dc847f23e661e24208e6061d79 Mon Sep 17 00:00:00 2001 From: foxxorcat Date: Thu, 15 Sep 2022 09:25:20 +0800 Subject: [PATCH] chore: baidu_photo rename only duplicate folders --- drivers/baidu_photo/driver.go | 14 ++++++++++---- drivers/baidu_photo/types.go | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/baidu_photo/driver.go b/drivers/baidu_photo/driver.go index f0f1d35d..a573e8b9 100644 --- a/drivers/baidu_photo/driver.go +++ b/drivers/baidu_photo/driver.go @@ -65,10 +65,16 @@ func (d *BaiduPhoto) List(ctx context.Context, dir model.Obj, args model.ListArg } } - objs = make([]model.Obj, 0, len(files)+len(albums)) - for i := 0; i < len(albums); i++ { - objs = append(objs, &albums[i]) - } + alubmName := make(map[string]int) + objs, _ = utils.SliceConvert(albums, func(album Album) (model.Obj, error) { + i := alubmName[album.GetName()] + if i != 0 { + alubmName[album.GetName()]++ + album.Title = fmt.Sprintf("%s(%d)", album.Title, i) + } + alubmName[album.GetName()]++ + return &album, nil + }) for i := 0; i < len(files); i++ { objs = append(objs, &files[i]) } diff --git a/drivers/baidu_photo/types.go b/drivers/baidu_photo/types.go index 81499cfd..6dd03528 100644 --- a/drivers/baidu_photo/types.go +++ b/drivers/baidu_photo/types.go @@ -100,7 +100,7 @@ type ( ) func (a *Album) GetSize() int64 { return 0 } -func (a *Album) GetName() string { return fmt.Sprint(a.Title, " -> ", a.AlbumID) } +func (a *Album) GetName() string { return fmt.Sprint(a.Title) } func (a *Album) ModTime() time.Time { if a.parseTime == nil { a.parseTime = toTime(a.Mtime)