Fixed error handling for forbidden sizes
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
8d722fb45e
commit
2ac1c8ba5f
18
main.go
18
main.go
|
@ -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,7 +102,7 @@ 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 {
|
||||
|
@ -108,20 +110,6 @@ func resizeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
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":
|
||||
|
||||
|
|
Loading…
Reference in New Issue