fix(cache): skip SVG favicons to prevent conversion errors
- commit
- 7aeab86975a29eeabd72f4a474884279e15af6ea
- author
- bamen · · 2025-10-06 17:44 UTC
- committer
- bamen · · 2025-10-06 17:02 UTC
- parent
- 55d6e7c
- signature
- unsigned
1 file · +8 -3
M internal/cache/favicon.go +8 -3
| @@ -13,6 +13,7 @@ import ( | |||
| 13 | 13 | "net/http" | |
| 14 | 14 | "os" | |
| 15 | 15 | "path/filepath" | |
| 16 | + | "strings" | |
| 16 | 17 | "time" | |
| 17 | 18 | ||
| 18 | 19 | "github.com/bnema/dumber/internal/config" | |
| @@ -113,6 +114,12 @@ func (fc *FaviconCache) getFilename(faviconURL string) string { | |||
| 113 | 114 | ||
| 114 | 115 | // downloadFavicon downloads a favicon and saves it to cache | |
| 115 | 116 | func (fc *FaviconCache) downloadFavicon(faviconURL string) error { | |
| 117 | + | // Skip SVG files - we can't convert them to PNG without additional dependencies | |
| 118 | + | if strings.HasSuffix(strings.ToLower(faviconURL), ".svg") { | |
| 119 | + | log.Printf("[favicon] Skipping SVG favicon: %s", faviconURL) | |
| 120 | + | return nil | |
| 121 | + | } | |
| 122 | + | ||
| 116 | 123 | filename := fc.getFilename(faviconURL) | |
| 117 | 124 | cachedPath := filepath.Join(fc.cacheDir, filename) | |
| 118 | 125 | ||
| @@ -177,9 +184,7 @@ func (fc *FaviconCache) downloadFavicon(faviconURL string) error { | |||
| 177 | 184 | if _, err := io.Copy(downloadFile, limitedBody); err != nil { | |
| 178 | 185 | return fmt.Errorf("failed to save favicon data: %w", err) | |
| 179 | 186 | } | |
| 180 | - | if err := downloadFile.Close(); err != nil { | |
| 181 | - | log.Printf("[favicon] failed to close download file: %v", err) | |
| 182 | - | } | |
| 187 | + | // Note: downloadFile will be closed by the defer above, no need to close explicitly | |
| 183 | 188 | ||
| 184 | 189 | // Detect if it's an ICO file and convert with ffmpeg if needed | |
| 185 | 190 | if err := fc.convertToPNG(tempDownloadFile, cachedPath, faviconURL); err != nil { | |
| @@ -13,6 +13,7 @@ import ( | |||||
| 13 | "net/http" | 13 | "net/http" | ||
| 14 | "os" | 14 | "os" | ||
| 15 | "path/filepath" | 15 | "path/filepath" | ||
| 16 | + | "strings" | |||
| 16 | "time" | 17 | "time" | ||
| 17 | 18 | ||||
| 18 | "github.com/bnema/dumber/internal/config" | 19 | "github.com/bnema/dumber/internal/config" | ||
| @@ -113,6 +114,12 @@ func (fc *FaviconCache) getFilename(faviconURL string) string { | |||||
| 113 | 114 | ||||
| 114 | // downloadFavicon downloads a favicon and saves it to cache | 115 | // downloadFavicon downloads a favicon and saves it to cache | ||
| 115 | func (fc *FaviconCache) downloadFavicon(faviconURL string) error { | 116 | func (fc *FaviconCache) downloadFavicon(faviconURL string) error { | ||
| 117 | + | // Skip SVG files - we can't convert them to PNG without additional dependencies | |||
| 118 | + | if strings.HasSuffix(strings.ToLower(faviconURL), ".svg") { | |||
| 119 | + | log.Printf("[favicon] Skipping SVG favicon: %s", faviconURL) | |||
| 120 | + | return nil | |||
| 121 | + | } | |||
| 122 | + | ||||
| 116 | filename := fc.getFilename(faviconURL) | 123 | filename := fc.getFilename(faviconURL) | ||
| 117 | cachedPath := filepath.Join(fc.cacheDir, filename) | 124 | cachedPath := filepath.Join(fc.cacheDir, filename) | ||
| 118 | 125 | ||||
| @@ -177,9 +184,7 @@ func (fc *FaviconCache) downloadFavicon(faviconURL string) error { | |||||
| 177 | if _, err := io.Copy(downloadFile, limitedBody); err != nil { | 184 | if _, err := io.Copy(downloadFile, limitedBody); err != nil { | ||
| 178 | return fmt.Errorf("failed to save favicon data: %w", err) | 185 | return fmt.Errorf("failed to save favicon data: %w", err) | ||
| 179 | } | 186 | } | ||
| 180 | - | if err := downloadFile.Close(); err != nil { | 187 | + | // Note: downloadFile will be closed by the defer above, no need to close explicitly |
| 181 | - | log.Printf("[favicon] failed to close download file: %v", err) | |||
| 182 | - | } | |||
| 183 | 188 | ||||
| 184 | // Detect if it's an ICO file and convert with ffmpeg if needed | 189 | // Detect if it's an ICO file and convert with ffmpeg if needed | ||
| 185 | if err := fc.convertToPNG(tempDownloadFile, cachedPath, faviconURL); err != nil { | 190 | if err := fc.convertToPNG(tempDownloadFile, cachedPath, faviconURL); err != nil { | ||