mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
41 lines
958 B
Go
41 lines
958 B
Go
package api
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/util"
|
|
)
|
|
|
|
func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapshotCommand) {
|
|
cmd.Key = util.GetRandomString(20)
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
|
c.JsonApiErr(500, "Failed to create snaphost", err)
|
|
return
|
|
}
|
|
|
|
c.JSON(200, util.DynMap{"key": cmd.Key})
|
|
}
|
|
|
|
func GetDashboardSnapshot(c *middleware.Context) {
|
|
key := c.Params(":key")
|
|
|
|
query := &m.GetDashboardSnapshotQuery{Key: key}
|
|
|
|
err := bus.Dispatch(query)
|
|
if err != nil {
|
|
c.JsonApiErr(500, "Failed to get dashboard snapshot", err)
|
|
return
|
|
}
|
|
|
|
dto := dtos.Dashboard{
|
|
Model: query.Result.Dashboard,
|
|
Meta: dtos.DashboardMeta{IsSnapshot: true},
|
|
}
|
|
|
|
c.Resp.Header().Set("Cache-Control", "public, max-age=31536000")
|
|
c.JSON(200, dto)
|
|
}
|