package imgbundler import ( "bytes" "context" "encoding/base64" "fmt" "html" "io/ioutil" "mime" "net/http" "net/url" "os" "path" "regexp" "strings" "sync" "time" "golang.org/x/xerrors" "oss.terrastruct.com/util-go/xdefer" "oss.terrastruct.com/util-go/xmain" ) const maxImageSize int64 = 1 << 25 // 33_554_432 var imageRegex = regexp.MustCompile(` 0 { return svg, xerrors.Errorf("%v", errhrefs) } return svg, nil } svg = bytes.Replace(svg, repl.from, repl.to, 1) } } } func worker(ctx context.Context, href []byte, isRemote bool) ([]byte, error) { var buf []byte var mimeType string var err error if isRemote { buf, mimeType, err = httpGet(ctx, html.UnescapeString(string(href))) } else { buf, err = os.ReadFile(html.UnescapeString(string(href))) } if err != nil { return nil, err } if mimeType == "" { mimeType = sniffMimeType(href, buf, isRemote) } mimeType = strings.Replace(mimeType, "text/xml", "image/svg+xml", 1) b64 := base64.StdEncoding.EncodeToString(buf) return []byte(fmt.Sprintf(`