mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Rendering: Adds PDF support behind feature toggle (#81811)
* start pdf refactor * Update AppChrome.tsx * Update AppChrome.tsx * add encoding param to rendering grpc service * fix plugin mode * clean up * fix backend tests * fix lint errors * Support pdf encoding in render http api --------- Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
@@ -59,7 +59,9 @@ func (hs *HTTPServer) RenderToPng(c *contextmodel.ReqContext) {
|
||||
hs.log.Error("Failed to parse user id", "err", errID)
|
||||
}
|
||||
|
||||
result, err := hs.RenderService.Render(c.Req.Context(), rendering.Opts{
|
||||
encoding := queryReader.Get("encoding", "")
|
||||
|
||||
result, err := hs.RenderService.Render(c.Req.Context(), rendering.RenderPNG, rendering.Opts{
|
||||
TimeoutOpts: rendering.TimeoutOpts{
|
||||
Timeout: time.Duration(timeout) * time.Second,
|
||||
},
|
||||
@@ -72,7 +74,7 @@ func (hs *HTTPServer) RenderToPng(c *contextmodel.ReqContext) {
|
||||
Height: height,
|
||||
Path: web.Params(c.Req)["*"] + queryParams,
|
||||
Timezone: queryReader.Get("tz", ""),
|
||||
Encoding: queryReader.Get("encoding", ""),
|
||||
Encoding: encoding,
|
||||
ConcurrentLimit: hs.Cfg.RendererConcurrentRequestLimit,
|
||||
DeviceScaleFactor: scale,
|
||||
Headers: headers,
|
||||
@@ -88,7 +90,12 @@ func (hs *HTTPServer) RenderToPng(c *contextmodel.ReqContext) {
|
||||
return
|
||||
}
|
||||
|
||||
c.Resp.Header().Set("Content-Type", "image/png")
|
||||
if encoding == "pdf" {
|
||||
c.Resp.Header().Set("Content-Type", "application/pdf")
|
||||
} else {
|
||||
c.Resp.Header().Set("Content-Type", "image/png")
|
||||
}
|
||||
|
||||
c.Resp.Header().Set("Cache-Control", "private")
|
||||
http.ServeFile(c.Resp, c.Req, result.FilePath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user