diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-03 08:03:27 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-03 08:03:27 +0300 |
| commit | f4bc35c0a24766c8e9a155cbad5ffdaf088ec458 (patch) | |
| tree | a9f1bb488bc7473549cb6e3552c531154841f0ef /internal/image/search.go | |
| parent | 63bd86d8046949e80e5b1122a1fcf717f51915c6 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'internal/image/search.go')
| -rw-r--r-- | internal/image/search.go | 27 |
1 files changed, 20 insertions, 7 deletions
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 |
