From 277594f21276c59f10e6a8c8b720ff9bb5609826 Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Tue, 25 Sep 2018 00:30:58 -0700 Subject: [PATCH] settings update - export settings JSON --- Makefile | 2 +- core/services.go | 5 ----- handlers/dashboard.go | 20 +++++++++++++++----- source/tmpl/settings.html | 8 +++++--- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 6b3fa098..ac9f31c3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=0.66 +VERSION=0.67 BINARY_NAME=statup GOPATH:=$(GOPATH) GOCMD=go diff --git a/core/services.go b/core/services.go index ed2c3a0c..25adcc00 100644 --- a/core/services.go +++ b/core/services.go @@ -222,18 +222,13 @@ func (s *Service) Downtime() time.Duration { func GraphDataRaw(service types.ServiceInterface, start, end time.Time) *DateScanObj { var d []DateScan - //s := service.Select() - model := service.(*Service).HitsBetween(start, end) rows, _ := model.Rows() - - //sql := GroupDataBy("hits", s.Id, start, end, 3600) for rows.Next() { var gd DateScan var createdAt string var value float64 rows.Scan(&createdAt, &value) - createdTime, _ := time.Parse(types.TIME, createdAt) gd.CreatedAt = utils.Timezoner(createdTime, CoreApp.Timezone).Format(types.TIME) gd.Value = int64(value * 1000) diff --git a/handlers/dashboard.go b/handlers/dashboard.go index a3395c68..efa14d82 100644 --- a/handlers/dashboard.go +++ b/handlers/dashboard.go @@ -16,6 +16,7 @@ package handlers import ( + "bytes" "encoding/json" "fmt" "github.com/hunterlong/statup/core" @@ -24,6 +25,8 @@ import ( "github.com/hunterlong/statup/types" "github.com/hunterlong/statup/utils" "net/http" + "strconv" + "time" ) func dashboardHandler(w http.ResponseWriter, r *http.Request) { @@ -117,11 +120,18 @@ func exportHandler(w http.ResponseWriter, r *http.Request) { data := exportData{core.CoreApp, notifiers} - w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(data) + export, _ := json.Marshal(data) - w.Header().Set("Content-Disposition", "attachment; filename=Wiki.png") - w.Header().Set("Content-Type", r.Header.Get("Content-Type")) - w.Header().Set("Content-Length", r.Header.Get("Content-Length")) + mime := http.DetectContentType(export) + fileSize := len(string(export)) + + w.Header().Set("Content-Type", mime) + w.Header().Set("Content-Disposition", "attachment; filename=export.json") + w.Header().Set("Expires", "0") + w.Header().Set("Content-Transfer-Encoding", "binary") + w.Header().Set("Content-Length", strconv.Itoa(fileSize)) + w.Header().Set("Content-Control", "private, no-transform, no-store, must-revalidate") + + http.ServeContent(w, r, "export.json", time.Now(), bytes.NewReader(export)) } diff --git a/source/tmpl/settings.html b/source/tmpl/settings.html index dac4f87b..a76a3c60 100644 --- a/source/tmpl/settings.html +++ b/source/tmpl/settings.html @@ -132,10 +132,14 @@
- You can Regenerate API Keys if you need to. + You can Regenerate API Keys if you need to.
+
+ Export Settings +
+ @@ -256,9 +260,7 @@
- Backup Database -
{{ range .Plugins }}