mirror of
https://github.com/grafana/grafana.git
synced 2025-02-04 12:41:12 -06:00
33 lines
856 B
Go
33 lines
856 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/torkelo/grafana-pro/pkg/components/renderer"
|
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
|
"github.com/torkelo/grafana-pro/pkg/utils"
|
|
)
|
|
|
|
func RenderToPng(c *middleware.Context) {
|
|
accountId := c.GetAccountId()
|
|
queryReader := utils.NewUrlQueryReader(c.Req.URL)
|
|
queryParams := "?render&accountId=" + strconv.FormatInt(accountId, 10) + "&" + c.Req.URL.RawQuery
|
|
|
|
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)
|
|
}
|