settings update - export settings JSON

pull/78/head v0.67
Hunter Long 2018-09-25 00:30:58 -07:00
parent 24ccf94e3d
commit 277594f212
4 changed files with 21 additions and 14 deletions

View File

@ -1,4 +1,4 @@
VERSION=0.66
VERSION=0.67
BINARY_NAME=statup
GOPATH:=$(GOPATH)
GOCMD=go

View File

@ -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)

View File

@ -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))
}

View File

@ -132,10 +132,14 @@
<label for="api_secret" class="col-sm-3 col-form-label">API Secret</label>
<div class="col-sm-9">
<input type="text" class="form-control select-input" value="{{ .ApiSecret }}" id="api_secret" readonly>
<small id="emailHelp" class="form-text text-muted">You can <a href="/api/renew">Regenerate API Keys</a> if you need to.</small>
<small class="form-text text-muted">You can <a href="/api/renew">Regenerate API Keys</a> if you need to.</small>
</div>
</div>
<div class="row">
<a href="/settings/export" class="btn btn-sm btn-secondary float-right">Export Settings</a>
</div>
</form>
</div>
@ -256,9 +260,7 @@
<div class="tab-pane fade" id="v-pills-backups" role="tabpanel" aria-labelledby="v-pills-backups-tab">
<a href="/backups/create" class="btn btn-primary btn-block">Backup Database</a>
</div>
{{ range .Plugins }}