mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 17:43:35 -06:00
removes auth hack to allow phantomjs to query pages as a user without auth. Instead we pass phantomjs the session cookie, which it then includes in the request.
35 lines
858 B
Go
35 lines
858 B
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/grafana/grafana/pkg/components/renderer"
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/grafana/grafana/pkg/util"
|
|
)
|
|
|
|
func RenderToPng(c *middleware.Context) {
|
|
queryReader := util.NewUrlQueryReader(c.Req.URL)
|
|
queryParams := fmt.Sprintf("?%s", c.Req.URL.RawQuery)
|
|
|
|
renderOpts := &renderer.RenderOpts{
|
|
Url: c.Params("*") + queryParams,
|
|
Width: queryReader.Get("width", "800"),
|
|
Height: queryReader.Get("height", "400"),
|
|
SessionId: c.Session.ID(),
|
|
}
|
|
|
|
renderOpts.Url = setting.ToAbsUrl(renderOpts.Url)
|
|
pngPath, err := renderer.RenderToPng(renderOpts)
|
|
|
|
if err != nil {
|
|
c.Handle(500, "Failed to render to png", err)
|
|
return
|
|
}
|
|
|
|
c.Resp.Header().Set("Content-Type", "image/png")
|
|
http.ServeFile(c.Resp, c.Req.Request, pngPath)
|
|
}
|