1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-23 11:14:48 +02:00

Check timeout automatically

This commit is contained in:
DarthSim 2022-06-23 17:23:04 +06:00
parent d80a203390
commit a44e8dc94b
8 changed files with 9 additions and 25 deletions

View File

@ -12,7 +12,7 @@ func applyFilters(pctx *pipelineContext, img *vips.Image, po *options.Processing
return nil return nil
} }
if err := copyMemoryAndCheckTimeout(pctx.ctx, img); err != nil { if err := img.CopyMemory(); err != nil {
return err return err
} }
@ -52,5 +52,5 @@ func applyFilters(pctx *pipelineContext, img *vips.Image, po *options.Processing
return err return err
} }
return copyMemoryAndCheckTimeout(pctx.ctx, img) return img.CopyMemory()
} }

View File

@ -1,14 +0,0 @@
package processing
import (
"context"
"github.com/imgproxy/imgproxy/v3/router"
"github.com/imgproxy/imgproxy/v3/vips"
)
func copyMemoryAndCheckTimeout(ctx context.Context, img *vips.Image) error {
err := img.CopyMemory()
router.CheckTimeout(ctx)
return err
}

View File

@ -106,5 +106,5 @@ func finalize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOpti
} }
} }
return copyMemoryAndCheckTimeout(pctx.ctx, img) return img.CopyMemory()
} }

View File

@ -29,5 +29,5 @@ func fixWebpSize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingO
log.Warningf("WebP dimension size is limited to %d. The image is rescaled to %dx%d", int(webpMaxDimension), img.Width(), img.Height()) log.Warningf("WebP dimension size is limited to %d. The image is rescaled to %dx%d", int(webpMaxDimension), img.Width(), img.Height())
return copyMemoryAndCheckTimeout(pctx.ctx, img) return img.CopyMemory()
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/imgproxy/imgproxy/v3/imagedata" "github.com/imgproxy/imgproxy/v3/imagedata"
"github.com/imgproxy/imgproxy/v3/imagetype" "github.com/imgproxy/imgproxy/v3/imagetype"
"github.com/imgproxy/imgproxy/v3/options" "github.com/imgproxy/imgproxy/v3/options"
"github.com/imgproxy/imgproxy/v3/router"
"github.com/imgproxy/imgproxy/v3/vips" "github.com/imgproxy/imgproxy/v3/vips"
) )
@ -52,6 +53,7 @@ func (p pipeline) Run(ctx context.Context, img *vips.Image, po *options.Processi
if err := step(&pctx, img, po, imgdata); err != nil { if err := step(&pctx, img, po, imgdata); err != nil {
return err return err
} }
router.CheckTimeout(ctx)
} }
return nil return nil

View File

@ -140,7 +140,7 @@ func transformAnimated(ctx context.Context, img *vips.Image, po *options.Process
return err return err
} }
if err = copyMemoryAndCheckTimeout(ctx, img); err != nil { if err = img.CopyMemory(); err != nil {
return err return err
} }
@ -264,10 +264,6 @@ func ProcessImage(ctx context.Context, imgdata *imagedata.ImageData, po *options
} }
} }
if err := copyMemoryAndCheckTimeout(ctx, img); err != nil {
return nil, err
}
if po.Format == imagetype.AVIF && (img.Width() < 16 || img.Height() < 16) { if po.Format == imagetype.AVIF && (img.Width() < 16 || img.Height() < 16) {
if img.HasAlpha() { if img.HasAlpha() {
po.Format = imagetype.PNG po.Format = imagetype.PNG

View File

@ -18,5 +18,5 @@ func scale(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions
} }
} }
return copyMemoryAndCheckTimeout(pctx.ctx, img) return img.CopyMemory()
} }

View File

@ -14,7 +14,7 @@ func trim(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions,
if err := img.Trim(po.Trim.Threshold, po.Trim.Smart, po.Trim.Color, po.Trim.EqualHor, po.Trim.EqualVer); err != nil { if err := img.Trim(po.Trim.Threshold, po.Trim.Smart, po.Trim.Color, po.Trim.EqualHor, po.Trim.EqualVer); err != nil {
return err return err
} }
if err := copyMemoryAndCheckTimeout(pctx.ctx, img); err != nil { if err := img.CopyMemory(); err != nil {
return err return err
} }