summaryrefslogtreecommitdiff
path: root/internal/image
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-08 08:22:10 +0200
committerPaul Buetow <paul@buetow.org>2026-03-08 08:22:10 +0200
commit9a1a8d4f072166a91f853d9b9eabfc6ebbab3474 (patch)
tree4d7cd2efb0b78ca9250154abe293056e06bbb814 /internal/image
parentb0ae81a4abaddb02fa0ec4b9d868ac1aee662fb9 (diff)
fix: complete code-quality task queue (373-378)
Diffstat (limited to 'internal/image')
-rw-r--r--internal/image/download.go12
-rw-r--r--internal/image/openai.go6
2 files changed, 10 insertions, 8 deletions
diff --git a/internal/image/download.go b/internal/image/download.go
index d01f829..8ea897e 100644
--- a/internal/image/download.go
+++ b/internal/image/download.go
@@ -68,7 +68,9 @@ func (d *Downloader) DownloadImage(ctx context.Context, result *SearchResult, ou
if err != nil {
return fmt.Errorf("download %q: %w", result.URL, err)
}
- defer reader.Close()
+ defer func() {
+ _ = reader.Close()
+ }()
// Create output file
file, err := os.Create(outputPath)
@@ -82,7 +84,7 @@ func (d *Downloader) DownloadImage(ctx context.Context, result *SearchResult, ou
if d.options.MaxSizeBytes > 0 {
written, err = io.CopyN(file, reader, d.options.MaxSizeBytes)
if err != nil && err != io.EOF {
- os.Remove(outputPath) // Clean up on error
+ _ = os.Remove(outputPath) // Clean up on error
return fmt.Errorf("write output file %q: %w", outputPath, err)
}
@@ -90,7 +92,7 @@ func (d *Downloader) DownloadImage(ctx context.Context, result *SearchResult, ou
if written == d.options.MaxSizeBytes {
// Try to read one more byte to see if file is larger
if _, err := reader.Read(make([]byte, 1)); err != io.EOF {
- os.Remove(outputPath) // Clean up
+ _ = os.Remove(outputPath) // Clean up
return fmt.Errorf("image exceeds max size %d bytes", d.options.MaxSizeBytes)
}
}
@@ -100,9 +102,9 @@ func (d *Downloader) DownloadImage(ctx context.Context, result *SearchResult, ou
return fmt.Errorf("sync output file %q: %w", outputPath, err)
}
} else {
- written, err = io.Copy(file, reader)
+ _, err = io.Copy(file, reader)
if err != nil {
- os.Remove(outputPath) // Clean up on error
+ _ = os.Remove(outputPath) // Clean up on error
return fmt.Errorf("write output file %q: %w", outputPath, err)
}
}
diff --git a/internal/image/openai.go b/internal/image/openai.go
index d964b55..5bb7db4 100644
--- a/internal/image/openai.go
+++ b/internal/image/openai.go
@@ -110,7 +110,7 @@ func (c *OpenAIClient) Search(ctx context.Context, opts *SearchOptions) ([]Searc
}
fmt.Printf("Using custom prompt: %s\n", prompt)
} else {
- prompt = c.createEducationalPrompt(opts.Query, translatedWord)
+ prompt = c.createEducationalPrompt(ctx, opts.Query, translatedWord)
if prompt == "" {
return nil, &SearchError{
Provider: "openai",
@@ -234,9 +234,9 @@ func (c *OpenAIClient) SetPromptCallback(callback func(prompt string)) {
}
// createEducationalPrompt generates a prompt optimized for language learning
-func (c *OpenAIClient) createEducationalPrompt(bulgarianWord, englishTranslation string) string {
+func (c *OpenAIClient) createEducationalPrompt(ctx context.Context, bulgarianWord, englishTranslation string) string {
// Generate a scene description for the word
- scene, err := c.generateSceneDescription(context.Background(), bulgarianWord, englishTranslation)
+ scene, err := c.generateSceneDescription(ctx, bulgarianWord, englishTranslation)
if err != nil {
fmt.Printf(" Failed to generate scene: %v, using basic prompt\n", err)
scene = ""