Fixed error handling for forbidden sizes
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Andreas Neue 2021-05-21 09:53:44 +02:00
parent 8d722fb45e
commit 2ac1c8ba5f
1 changed files with 4 additions and 16 deletions

20
main.go
View File

@ -60,6 +60,7 @@ func resizeHandler(w http.ResponseWriter, r *http.Request) {
}
if forbidden {
writeError(w, imgPath, method, "size is not allowed", http.StatusForbidden)
return
}
size := strings.Split(args, "x")
@ -90,6 +91,7 @@ func resizeHandler(w http.ResponseWriter, r *http.Request) {
return
}
// Read from response body, convert and write to output buffer
img, err := vips.NewImageFromReader(resp.Body)
if err != nil {
writeError(w, imgPath, method, fmt.Sprintf("%v", err), http.StatusInternalServerError)
@ -100,28 +102,14 @@ func resizeHandler(w http.ResponseWriter, r *http.Request) {
writeError(w, imgPath, method, fmt.Sprintf("%v", err), http.StatusInternalServerError)
return
}
ep := vips.NewDefaultExportParams()
ep := vips.NewDefaultExportParams() // default export params are sufficient
buf, _, _ := img.Export(ep)
_, err = w.Write(buf)
if err != nil {
writeError(w, imgPath, method, fmt.Sprintf("%v", err), http.StatusInternalServerError)
return
}
// govips returns the output of the image as a []byte object. We don't need
// it since we are directly piping it to the ResponseWriter
/*_, _, err = vips.NewTransform().
Load(resp.Body).
ResizeStrategy(vips.ResizeStrategyAuto).
Resize(iw, ih).
Output(w).
Apply()
if err != nil {
writeError(w, imgPath, method, "failed to resize", http.StatusInternalServerError)
return
}
*/
case "thumbnail":