From 1aa4572f0e0997655eda283801bbb34a6de95c8b Mon Sep 17 00:00:00 2001 From: Martyn Ranyard Date: Thu, 16 Jul 2020 18:01:04 +0200 Subject: [PATCH] TSV and excel instructions Signed-off-by: Martyn Ranyard --- internal/webserver/webserver.go | 16 ++++++++++++---- web/admin.html | 17 ++++++++++++++++- web/data.csv | 2 +- web/data.tsv | 4 ++++ 4 files changed, 33 insertions(+), 6 deletions(-) create mode 100755 web/data.tsv diff --git a/internal/webserver/webserver.go b/internal/webserver/webserver.go index 45900dc..67011dc 100755 --- a/internal/webserver/webserver.go +++ b/internal/webserver/webserver.go @@ -680,10 +680,17 @@ func CSVHandler(response http.ResponseWriter, request *http.Request) { topNSongs := calculateTopNSongs(channelData.VideoCache, 10) topNSingers := calculateTopNSingers(channelData.VideoCache, 10) var td = TemplateData{channelData.Name, channelData.Command, channelData.ExtraStrings, channelData.JoinTime, channelData.JoinTime.Format(irc.UTCFormat), false, channelData.HasLeft, AugmentSingsVideoStructSliceForCSV(channelData.VideoCache), topNSongs, topNSingers} - response.Header().Add("Content-Disposition", "attachment; filename=\"duets.csv\"") - response.Header().Add("Content-type", "text/csv") - tmpl := template.Must(template.ParseFiles("web/data.csv")) - tmpl.Execute(response, td) + if request.URL.Path[0:4] == "/csv" { + response.Header().Add("Content-Disposition", "attachment; filename=\"duets.csv\"") + response.Header().Add("Content-type", "text/csv") + tmpl := template.Must(template.ParseFiles("web/data.csv")) + tmpl.Execute(response, td) + } else { + response.Header().Add("Content-Disposition", "attachment; filename=\"duets.tsv\"") + response.Header().Add("Content-type", "text/tab-separated-values") + tmpl := template.Must(template.ParseFiles("web/data.tsv")) + tmpl.Execute(response, td) + } } func HandleHTTP(passedIrcBot *irc.KardBot) { @@ -698,6 +705,7 @@ func HandleHTTP(passedIrcBot *irc.KardBot) { r.HandleFunc("/cover.css", CSSHandler) r.HandleFunc("/admin/{channel}/{key}", AdminHandler) r.HandleFunc("/csv/{channel}/{key}", CSVHandler) + r.HandleFunc("/tsv/{channel}/{key}", CSVHandler) //r.HandleFunc("/twitchadmin", TwitchAdminHandler) //r.HandleFunc("/twitchtobackend", TwitchBackendHandler) r.Path("/twitchtobackend").Queries("access_token", "{access_token}", "scope", "{scope}", "token_type", "{token_type}").HandlerFunc(TwitchBackendHandler) diff --git a/web/admin.html b/web/admin.html index 6d5a35d..898cdc8 100755 --- a/web/admin.html +++ b/web/admin.html @@ -69,6 +69,12 @@ font-weight: bold; font-style: italic; } + #csvpanel td { + padding: 5px; + } + #csvpanel th { + padding: 5px; + } @@ -148,7 +154,16 @@