π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[cli] Add option to exlude albums
Dirk Wildenfb0a78ee7f5a
diff --git a/cli/cmd/export.go b/cli/cmd/export.goindex 0979bbeb5e..29ae7055dc 100644--- a/cli/cmd/export.go+++ b/cli/cmd/export.go@@ -16,10 +16,12 @@ var exportCmd = &cobra.Command{hidden, _ := cmd.Flags().GetBool("hidden")albums, _ := cmd.Flags().GetStringSlice("albums")emails, _ := cmd.Flags().GetStringSlice("emails")+ excludeAlbums, _ := cmd.Flags().GetStringSlice("exclude-albums")// Create Filters struct with flag valuesfilters := model.Filter{ExcludeShared: !shared,ExcludeHidden: !hidden,+ ExcludeAlbums: excludeAlbums,Albums: albums,Emails: emails,}@@ -36,4 +38,5 @@ func init() {exportCmd.Flags().Bool("hidden", true, "to exclude hidden albums, pass --hidden=false")exportCmd.Flags().StringSlice("albums", []string{}, "Comma-separated list of album names to export")exportCmd.Flags().StringSlice("emails", []string{}, "Comma-separated list of emails to export files shared with")+ exportCmd.Flags().StringSlice("exclude-albums", []string{}, "Comma-separated list of album names to exclude")}diff --git a/cli/pkg/model/export/filter.go b/cli/pkg/model/export/filter.goindex 742d5fef38..4ccba7ca91 100644--- a/cli/pkg/model/export/filter.go+++ b/cli/pkg/model/export/filter.go@@ -11,4 +11,6 @@ type Filters struct {Albums []string// when email is provided, only files shared with that email are exportedEmails []string+ // for the listed album names, files in these albums are excluded+ ExcludeAlbums []string}diff --git a/cli/pkg/model/filter.go b/cli/pkg/model/filter.goindex 6f083c3f32..41e274d6e3 100644--- a/cli/pkg/model/filter.go+++ b/cli/pkg/model/filter.go@@ -16,6 +16,8 @@ type Filter struct {Albums []string// when email is provided, only files shared with that email are exportedEmails []string+ // for the listed album names, files in these albums are excluded+ ExcludeAlbums []string}func (f Filter) SkipAccount(email string) bool {@@ -52,8 +54,17 @@ func (f Filter) SkipAlbum(album RemoteAlbum, shouldLog bool) bool {return false}-// excludeByName returns true if albums list is not empty and album name is not in the list+// excludeByName returns true if Albums list is not empty and album name is not in the list,+// or if album name is in the ExcludeAlbums listfunc (f Filter) excludeByName(album RemoteAlbum) bool {+ // Check if album is in the ExcludeAlbums list+ for _, a := range f.ExcludeAlbums {+ if strings.ToLower(a) == strings.ToLower(strings.TrimSpace(album.AlbumName)) {+ return true+ }+ }++ // Check if Albums filter is set and album is not in the listif len(f.Albums) > 0 {for _, a := range f.Albums {if strings.ToLower(a) == strings.ToLower(strings.TrimSpace(album.AlbumName)) {diff --git a/cli/pkg/model/filter_test.go b/cli/pkg/model/filter_test.gonew file mode 100644index 0000000000..50a8d32adb--- /dev/null+++ b/cli/pkg/model/filter_test.go@@ -0,0 +1,89 @@+package model++import (+ "testing"+)++func TestFilter_excludeByName(t *testing.T) {+ tests := []struct {+ name string+ filter Filter+ album RemoteAlbum+ want bool+ }{+ {+ name: "no filters - should not exclude",+ filter: Filter{},+ album: RemoteAlbum{AlbumName: "Vacation"},+ want: false,+ },+ {+ name: "album in Albums list - should not exclude",+ filter: Filter{Albums: []string{"Vacation", "Family"}},+ album: RemoteAlbum{AlbumName: "Vacation"},+ want: false,+ },+ {+ name: "album not in Albums list - should exclude",+ filter: Filter{Albums: []string{"Vacation", "Family"}},+ album: RemoteAlbum{AlbumName: "Work"},+ want: true,+ },+ {+ name: "album in Albums list case insensitive - should not exclude",+ filter: Filter{Albums: []string{"vacation"}},+ album: RemoteAlbum{AlbumName: "Vacation"},+ want: false,+ },+ {+ name: "album with whitespace in Albums list - should not exclude",+ filter: Filter{Albums: []string{"Vacation"}},+ album: RemoteAlbum{AlbumName: " Vacation "},+ want: false,+ },+ {+ name: "album in ExcludeAlbums list - should exclude",+ filter: Filter{ExcludeAlbums: []string{"Work", "Private"}},+ album: RemoteAlbum{AlbumName: "Work"},+ want: true,+ },+ {+ name: "album not in ExcludeAlbums list - should not exclude",+ filter: Filter{ExcludeAlbums: []string{"Work", "Private"}},+ album: RemoteAlbum{AlbumName: "Vacation"},+ want: false,+ },+ {+ name: "album in ExcludeAlbums case insensitive - should exclude",+ filter: Filter{ExcludeAlbums: []string{"work"}},+ album: RemoteAlbum{AlbumName: "Work"},+ want: true,+ },+ {+ name: "album with whitespace in ExcludeAlbums - should exclude",+ filter: Filter{ExcludeAlbums: []string{"Work"}},+ album: RemoteAlbum{AlbumName: " Work "},+ want: true,+ },+ {+ name: "album in both Albums and ExcludeAlbums - ExcludeAlbums takes precedence",+ filter: Filter{Albums: []string{"Vacation"}, ExcludeAlbums: []string{"Vacation"}},+ album: RemoteAlbum{AlbumName: "Vacation"},+ want: true,+ },+ {+ name: "album in Albums but different one in ExcludeAlbums - should not exclude",+ filter: Filter{Albums: []string{"Vacation", "Family"}, ExcludeAlbums: []string{"Work"}},+ album: RemoteAlbum{AlbumName: "Vacation"},+ want: false,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ if got := tt.filter.excludeByName(tt.album); got != tt.want {+ t.Errorf("Filter.excludeByName() = %v, want %v", got, tt.want)+ }+ })+ }+}