fix - carto now requires api keys
All checks were successful
Release / tag (push) Successful in 2s
Release / build-and-release (push) Successful in 13s

This commit is contained in:
mr0xb 2026-08-26 22:41:52 -04:00
commit 3a3307e190
9 changed files with 100 additions and 6 deletions

View file

@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"html/template"
"net/url"
"path/filepath"
"sort"
"strings"
@ -66,6 +67,10 @@ type ReportData struct {
// Theme selects the visual theme (see themes.go). Empty or unrecognized
// falls back to DefaultTheme.
Theme string
// MapAPIKey is the basemap provider API key. When non-empty it is appended
// to the theme's tile URL as a "key" query parameter (CARTO's format).
MapAPIKey string
}
// DaySummary is one row in the index page's daily breakdown table.
@ -338,6 +343,20 @@ type reportRenderData struct {
MarkerColor string
}
// tileURLWithKey appends the basemap provider API key to tileURL as a "key"
// query parameter, e.g. ".../{z}/{x}/{y}.png?key=XYZ". The URL is returned
// unchanged when no key is set.
func tileURLWithKey(tileURL, key string) string {
if key == "" || tileURL == "" {
return tileURL
}
sep := "?"
if strings.Contains(tileURL, "?") {
sep = "&"
}
return tileURL + sep + "key=" + url.QueryEscape(key)
}
// GenerateHTML renders the full HTML report from data.
func GenerateHTML(data ReportData) (string, error) {
th := themeFor(data.Theme)
@ -354,7 +373,7 @@ func GenerateHTML(data ReportData) (string, error) {
Chart3: th.Chart3,
ChartWarn: th.ChartWarn,
ChartErr: th.ChartErr,
MapTileURL: th.MapTileURL,
MapTileURL: tileURLWithKey(th.MapTileURL, data.MapAPIKey),
MapAttribution: th.MapAttribution,
MarkerColor: th.MarkerColor,
}