From f4bc35c0a24766c8e9a155cbad5ffdaf088ec458 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 3 Apr 2026 08:03:27 +0300 Subject: task 00o: split ImageSearcher into ImageSearcher + AttributionProvider (ISP) Introduce AttributionProvider interface with GetAttribution() separate from ImageSearcher so callers only needing search/download don't carry attribution. ImageClient composes both. Downloader.searcher and NewDownloader now take ImageClient since attribution is needed when saving downloaded files. Compile-time assertions updated to ImageClient. Co-Authored-By: Claude Sonnet 4.6 --- internal/image/search.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'internal/image/search.go') diff --git a/internal/image/search.go b/internal/image/search.go index 9be72ed..be20731 100644 --- a/internal/image/search.go +++ b/internal/image/search.go @@ -43,21 +43,34 @@ func DefaultSearchOptions(query string) *SearchOptions { } } -// ImageSearcher defines the interface for image search providers +// AttributionProvider returns required attribution text for a search result. +// Kept separate from ImageSearcher so callers that only need attribution +// do not depend on Search/Download/Name. +type AttributionProvider interface { + GetAttribution(result *SearchResult) string +} + +// ImageSearcher defines the interface for image search providers. +// Providers that also carry attribution text implement AttributionProvider +// in addition to this interface. type ImageSearcher interface { - // Search performs an image search with the given options + // Search performs an image search with the given options. Search(ctx context.Context, opts *SearchOptions) ([]SearchResult, error) - // Download downloads an image from the given URL + // Download downloads an image from the given URL. Download(ctx context.Context, url string) (io.ReadCloser, error) - // GetAttribution returns the required attribution text for an image - GetAttribution(result *SearchResult) string - - // Name returns the name of the search provider + // Name returns the name of the search provider. Name() string } +// ImageClient combines ImageSearcher and AttributionProvider for callers +// that need full provider capabilities (search, download, attribution). +type ImageClient interface { + ImageSearcher + AttributionProvider +} + // SearchError represents an error from an image search provider type SearchError struct { Provider string -- cgit v1.2.3