2022-11-29 01:50:48PM

This commit is contained in:
Alexander Wang 2022-11-29 13:50:48 -08:00
parent fe75e7067b
commit 983b05bd9c
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
2 changed files with 10 additions and 10 deletions

View file

@ -205,24 +205,24 @@ func compile(ctx context.Context, ms *xmain.State, isWatching bool, plugin d2plu
if err != nil {
return nil, err
}
svg, err = imgbundler.InlineLocal(ms, svg)
svg, err = imgbundler.InlineLocal(ctx, ms, svg)
if err != nil {
// Missing/broken images are fine during watch mode, as the user is likely building up a diagram.
// Otherwise, the assumption is that this diagram is building for production, and broken images are not okay.
if !isWatching {
return nil, err
}
ms.Log.Debug.Printf("ignoring missing/broken local image in watch mode: %v", err)
ms.Log.Debug.Printf("ignoring missing/broken local image(s) in watch mode: %v", err)
}
out := svg
if filepath.Ext(outputPath) == ".png" {
svg, err = imgbundler.InlineRemote(ms, svg)
svg, err = imgbundler.InlineRemote(ctx, ms, svg)
if err != nil {
if !isWatching {
return nil, err
}
ms.Log.Debug.Printf("ignoring missing/broken remote image in watch mode: %v", err)
ms.Log.Debug.Printf("ignoring missing/broken remote image(s) in watch mode: %v", err)
}
out, err = png.ConvertSVG(ms, page, svg)

View file

@ -31,15 +31,15 @@ type resp struct {
err error
}
func InlineLocal(ms *xmain.State, in []byte) ([]byte, error) {
return inline(ms, in, false)
func InlineLocal(ctx context.Context, ms *xmain.State, in []byte) ([]byte, error) {
return inline(ctx, ms, in, false)
}
func InlineRemote(ms *xmain.State, in []byte) ([]byte, error) {
return inline(ms, in, true)
func InlineRemote(ctx context.Context, ms *xmain.State, in []byte) ([]byte, error) {
return inline(ctx, ms, in, true)
}
func inline(ms *xmain.State, svg []byte, isRemote bool) (_ []byte, err error) {
func inline(ctx context.Context, ms *xmain.State, svg []byte, isRemote bool) (_ []byte, err error) {
defer xdefer.Errorf(&err, "failed to bundle images")
imgs := imageRe.FindAllSubmatch(svg, -1)
@ -57,7 +57,7 @@ func inline(ms *xmain.State, svg []byte, isRemote bool) (_ []byte, err error) {
// Limits the number of workers to 16.
sema := make(chan struct{}, 16)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
ctx, cancel := context.WithTimeout(ctx, time.Minute*5)
defer cancel()
wg.Add(len(filtered))