From 8fb30a66a81a1f7150ebe86ed091e7c1651233a1 Mon Sep 17 00:00:00 2001 From: RanXom Date: Wed, 22 Jul 2026 18:20:15 +0530 Subject: feat(gallery): filter photos by extension --- internal/gallery/query_filter.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 internal/gallery/query_filter.go (limited to 'internal/gallery/query_filter.go') diff --git a/internal/gallery/query_filter.go b/internal/gallery/query_filter.go new file mode 100644 index 0000000..9e10758 --- /dev/null +++ b/internal/gallery/query_filter.go @@ -0,0 +1,27 @@ +package gallery + +import ( + "path/filepath" + "strings" +) + +func filterQueryPhotos( + photos []Photo, + query Query, +) []Photo { + if query.Extension == "" { + return photos + } + + filtered := make([]Photo, 0, len(photos)) + + for _, photo := range photos { + ext := strings.TrimPrefix(filepath.Ext(photo.RelativePath), ".") + + if strings.EqualFold(ext, query.Extension) { + filtered = append(filtered, photo) + } + } + + return filtered +} -- cgit v1.2.3 From 816c1506b2ccf081a5792ce676bcad7a7d6841fc Mon Sep 17 00:00:00 2001 From: RanXom Date: Wed, 22 Jul 2026 18:33:40 +0530 Subject: refactor(api): add flexible filtering options --- internal/gallery/query_filter.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'internal/gallery/query_filter.go') diff --git a/internal/gallery/query_filter.go b/internal/gallery/query_filter.go index 9e10758..dda73c4 100644 --- a/internal/gallery/query_filter.go +++ b/internal/gallery/query_filter.go @@ -18,7 +18,10 @@ func filterQueryPhotos( for _, photo := range photos { ext := strings.TrimPrefix(filepath.Ext(photo.RelativePath), ".") - if strings.EqualFold(ext, query.Extension) { + if strings.EqualFold( + strings.TrimPrefix(ext, "."), + strings.TrimPrefix(query.Extension, "."), + ) { filtered = append(filtered, photo) } } -- cgit v1.2.3 From 6792c6f697db94012adca1c56d6b032d71d00665 Mon Sep 17 00:00:00 2001 From: Saiyed Shizain Date: Wed, 26 Aug 2026 16:46:29 +0530 Subject: feat(gallery): search photos by relative path --- internal/gallery/query_filter.go | 52 ++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'internal/gallery/query_filter.go') diff --git a/internal/gallery/query_filter.go b/internal/gallery/query_filter.go index dda73c4..14d9d59 100644 --- a/internal/gallery/query_filter.go +++ b/internal/gallery/query_filter.go @@ -9,22 +9,54 @@ func filterQueryPhotos( photos []Photo, query Query, ) []Photo { - if query.Extension == "" { - return photos - } - filtered := make([]Photo, 0, len(photos)) for _, photo := range photos { - ext := strings.TrimPrefix(filepath.Ext(photo.RelativePath), ".") + if !matchesExtension(photo, query.Extension) { + continue + } - if strings.EqualFold( - strings.TrimPrefix(ext, "."), - strings.TrimPrefix(query.Extension, "."), - ) { - filtered = append(filtered, photo) + if !matchesSearch(photo, query.Search) { + continue } + + filtered = append(filtered, photo) } return filtered } + +func matchesExtension( + photo Photo, + extension string, +) bool { + if extension == "" { + return true + } + + ext := strings.TrimPrefix( + filepath.Ext(photo.RelativePath), + ".", + ) + + extension = strings.TrimPrefix( + extension, + ".", + ) + + return strings.EqualFold(ext, extension) +} + +func matchesSearch( + photo Photo, + search string, +) bool { + if search == "" { + return true + } + + return strings.Contains( + strings.ToLower(photo.RelativePath), + strings.ToLower(search), + ) +} -- cgit v1.2.3