2014-12-29 06:36:08 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2015-01-29 05:10:34 -06:00
|
|
|
"fmt"
|
2014-12-29 06:36:08 -06:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/torkelo/grafana-pro/pkg/components/renderer"
|
|
|
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
2015-01-08 02:00:00 -06:00
|
|
|
"github.com/torkelo/grafana-pro/pkg/util"
|
2014-12-29 06:36:08 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func RenderToPng(c *middleware.Context) {
|
2015-01-08 02:00:00 -06:00
|
|
|
queryReader := util.NewUrlQueryReader(c.Req.URL)
|
2015-01-29 05:10:34 -06:00
|
|
|
queryParams := fmt.Sprintf("?render=1&%s=%d&%s", middleware.SESS_KEY_USERID, c.UserId, c.Req.URL.RawQuery)
|
2014-12-29 06:36:08 -06:00
|
|
|
|
|
|
|
renderOpts := &renderer.RenderOpts{
|
|
|
|
Url: c.Params("*") + queryParams,
|
|
|
|
Width: queryReader.Get("width", "800"),
|
|
|
|
Height: queryReader.Get("height", "400"),
|
|
|
|
}
|
|
|
|
|
|
|
|
renderOpts.Url = "http://localhost:3000/" + renderOpts.Url
|
|
|
|
|
|
|
|
pngPath, err := renderer.RenderToPng(renderOpts)
|
|
|
|
if err != nil {
|
|
|
|
c.HTML(500, "error.html", nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Resp.Header().Set("Content-Type", "image/png")
|
|
|
|
http.ServeFile(c.Resp, c.Req.Request, pngPath)
|
|
|
|
}
|