package media import ( "fmt" "io" "io/fs" "net/http" "os" "regexp" "strings" ) func DownloadSelfHostedIcon(url, title, filePath string) ([]byte, error) { resp, err := http.Get(url) if err != nil { return nil, fmt.Errorf("failed to get icon: %w", err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to get icon, status: %d, url: %s", resp.StatusCode, url) } data, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read icon: %w", err) } data = replaceClassNames(data, title) data = insertWidthHeight(data) err = os.WriteFile(filePath, data, fs.FileMode(0640)) if err != nil { return nil, fmt.Errorf("failed to write icon: %w", err) } return data, nil } func insertWidthHeight(svgContent []byte) []byte { classRegex := regexp.MustCompile(`(?: