mirror of
				https://github.com/imgproxy/imgproxy.git
				synced 2025-10-30 23:08:02 +02:00 
			
		
		
		
	Check timeout automatically
This commit is contained in:
		| @@ -12,7 +12,7 @@ func applyFilters(pctx *pipelineContext, img *vips.Image, po *options.Processing | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	if err := copyMemoryAndCheckTimeout(pctx.ctx, img); err != nil { | ||||
| 	if err := img.CopyMemory(); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| @@ -52,5 +52,5 @@ func applyFilters(pctx *pipelineContext, img *vips.Image, po *options.Processing | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return copyMemoryAndCheckTimeout(pctx.ctx, img) | ||||
| 	return img.CopyMemory() | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
| } | ||||
| @@ -106,5 +106,5 @@ func finalize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOpti | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return copyMemoryAndCheckTimeout(pctx.ctx, img) | ||||
| 	return img.CopyMemory() | ||||
| } | ||||
|   | ||||
| @@ -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()) | ||||
|  | ||||
| 	return copyMemoryAndCheckTimeout(pctx.ctx, img) | ||||
| 	return img.CopyMemory() | ||||
| } | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import ( | ||||
| 	"github.com/imgproxy/imgproxy/v3/imagedata" | ||||
| 	"github.com/imgproxy/imgproxy/v3/imagetype" | ||||
| 	"github.com/imgproxy/imgproxy/v3/options" | ||||
| 	"github.com/imgproxy/imgproxy/v3/router" | ||||
| 	"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 { | ||||
| 			return err | ||||
| 		} | ||||
| 		router.CheckTimeout(ctx) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
|   | ||||
| @@ -140,7 +140,7 @@ func transformAnimated(ctx context.Context, img *vips.Image, po *options.Process | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if err = copyMemoryAndCheckTimeout(ctx, img); err != nil { | ||||
| 	if err = img.CopyMemory(); err != nil { | ||||
| 		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 img.HasAlpha() { | ||||
| 			po.Format = imagetype.PNG | ||||
|   | ||||
| @@ -18,5 +18,5 @@ func scale(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return copyMemoryAndCheckTimeout(pctx.ctx, img) | ||||
| 	return img.CopyMemory() | ||||
| } | ||||
|   | ||||
| @@ -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 { | ||||
| 		return err | ||||
| 	} | ||||
| 	if err := copyMemoryAndCheckTimeout(pctx.ctx, img); err != nil { | ||||
| 	if err := img.CopyMemory(); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user