func convertByFileHandler(c *gin.Context) { s := c.MustGet("statsd").(*statsd.Client) r, ravenOk := c.Get("sentry") file, header, err := c.Request.FormFile("file") if err != nil { c.AbortWithError(http.StatusBadRequest, ErrFileInvalid).SetType(gin.ErrorTypePublic) s.Increment("invalid_file") return } ext := c.Query("ext") source, err := converter.NewConversionSource("", file, ext) if err != nil { s.Increment("conversion_error") if ravenOk { r.(*raven.Client).CaptureError(err, map[string]string{"url": header.Filename}) } c.Error(err) return } conversionHandler(c, *source) }
// convertByURLHandler is the main v1 API handler for converting a HTML to a PDF // via a GET request. It can either return a JSON string indicating that the // output of the conversion has been uploaded or it can return the output of // the conversion to the client (raw bytes). func convertByURLHandler(c *gin.Context) { s := c.MustGet("statsd").(*statsd.Client) r, ravenOk := c.Get("sentry") url := c.Query("url") if url == "" { c.AbortWithError(http.StatusBadRequest, ErrURLInvalid).SetType(gin.ErrorTypePublic) s.Increment("invalid_url") return } ext := c.Query("ext") source, err := converter.NewConversionSource(url, nil, ext) if err != nil { s.Increment("conversion_error") if ravenOk { r.(*raven.Client).CaptureError(err, map[string]string{"url": url}) } c.Error(err) return } conversionHandler(c, *source) }