From f874e95a9df5e87a29a7ed037316a7fb7b858fbd Mon Sep 17 00:00:00 2001 From: iacore Date: Wed, 25 Sep 2024 18:44:55 +0000 Subject: [PATCH] no historical data shenanigans --- main.go | 39 ++++++++++++++++++++++++++++----------- templates/index.html | 4 ++-- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index d79cda7..e59a9be 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ var staticAssets embed.FS //go:embed all:templates var templateAssets embed.FS -func parseAndRenderTemplate(templateName, siteName, iconSrc string, data []core.Row) (string, error) { +func parseAndRenderTemplate(templateName, siteName, iconSrc string, data scanner.ServiceStatusBatch) (string, error) { rawTemplate, err := templateAssets.ReadFile(templateName) if err != nil { return "", err @@ -87,12 +87,13 @@ func index(w http.ResponseWriter, r *http.Request) { if (!accept_html || prefer_text) && accept_text { indexForVT100(w, r, data) } else if accept_html { - historical_data, err := dbm.QueryAllAfter(time.Now().Add(-7 * 24 * time.Hour)) - if err != nil { - http.Error(w, err.Error(), 500) - return - } - indexForBrowserWithHistoricalData(w, r, historical_data, config.SiteName, config.IconSrc) + // historical_data, err := dbm.QueryAllAfter(time.Now().Add(-7 * 24 * time.Hour)) + // if err != nil { + // http.Error(w, err.Error(), 500) + // return + // } + // indexForBrowserWithHistoricalData(w, r, historical_data, config.SiteName, config.IconSrc) + indexForBrowser(w, r, data, config.SiteName, config.IconSrc) } else { // when no valid content type is requested // not to-spec. still sends plain text anyway indexForVT100(w, r, data) @@ -105,13 +106,14 @@ func indexForVT100(w http.ResponseWriter, _ *http.Request, data scanner.ServiceS w.Write([]byte(parsedTemplate)) } -func indexForBrowserWithHistoricalData(w http.ResponseWriter, _ *http.Request, historical_data []core.Row, siteName string, iconSrc string) { + +func indexForBrowser(w http.ResponseWriter, _ *http.Request, data scanner.ServiceStatusBatch, siteName string, iconSrc string) { // the basic idea here: - // - create new template and render it with historical_data + // - create new template and render it with data // // reference: see `indexForBrowser` above - parsedTemplate, err := parseAndRenderTemplate("templates/index.html", siteName, iconSrc, historical_data) + parsedTemplate, err := parseAndRenderTemplate("templates/index.html", siteName, iconSrc, data) if err != nil { http.Error(w, err.Error(), 500) return @@ -120,6 +122,21 @@ func indexForBrowserWithHistoricalData(w http.ResponseWriter, _ *http.Request, h w.Write([]byte(parsedTemplate)) } +// func indexForBrowserWithHistoricalData(w http.ResponseWriter, _ *http.Request, historical_data []core.Row, siteName string, iconSrc string) { +// // the basic idea here: +// // - create new template and render it with historical_data +// // +// // reference: see `indexForBrowser` above + +// parsedTemplate, err := parseAndRenderTemplate("templates/index.html", siteName, iconSrc, historical_data) +// if err != nil { +// http.Error(w, err.Error(), 500) +// return +// } + +// w.Write([]byte(parsedTemplate)) +// } + var config *core.Config var dbm core.Database var client *core.MatrixClient @@ -221,7 +238,7 @@ func main() { if err != nil { log.Printf("Error in core.GetBootTime: %v", err) } else { - time_passed := time.Now().Sub(btime) + time_passed := time.Since(btime) time.Sleep(core.WaitDurationAfterBoot - time_passed) } diff --git a/templates/index.html b/templates/index.html index 5650d65..7b67703 100644 --- a/templates/index.html +++ b/templates/index.html @@ -15,7 +15,7 @@