cached webrequests

This commit is contained in:
Sebastian Frank
2019-03-25 15:07:02 +01:00
parent 267d1010bb
commit 234137f22f
6 changed files with 107 additions and 61 deletions

View File

@@ -8,7 +8,6 @@ import (
"image/gif"
"image/jpeg"
"image/png"
"net/http"
"net/url"
"os"
"path"
@@ -66,20 +65,6 @@ func parseImageParams(str string) (*mark2web.ImagingConfig, error) {
return &p, nil
}
func getImageFromURL(url string) (image.Image, string, error) {
resp, err := http.Get(url)
if err != nil {
return nil, "", fmt.Errorf("could not get url '%s': %s", url, err)
}
img, format, err := image.Decode(resp.Body)
if err != nil {
return nil, "", fmt.Errorf("could read body from url '%s': %s", url, err)
}
return img, format, nil
}
// ImageProcessFilter read the image url and process parameters and saves the resized/processed image
// param: w=WITDH,h=HEIGHT
func ImageProcessFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
@@ -168,7 +153,7 @@ func ImageProcessFilter(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *
logger.Log.Noticef("processing image from %s to %s", imgSource, imgTarget)
if strings.HasPrefix(imgSource, "http://") || strings.HasPrefix(imgSource, "https://") {
// remote file
img, p.Format, err = getImageFromURL(imgSource)
img, p.Format, err = helper.ImageWebRequest(imgSource)
} else {
img, err = imaging.Open(imgSource, imaging.AutoOrientation(true))
}