prime8dev

prime8dev
git clone https://git.prime8.dev/prime8dev.git
Log | Files | Refs | README | LICENSE

commit f88318e4e4bb416b372396968ed8bf94987c84d0
parent e187752c1ccafba9ae888b1c5f50c857b98a4334
Author: Damian Myrda <damian@prime8.dev>
Date:   Tue, 10 Nov 2026 01:48:45 +0000

wakatime: read hrs logged from self-hosted Wakapi (time.prime8.dev); footer links there

Diffstat:
Minternal/external/wakatime.go | 15++++++++++-----
Minternal/external/wakatime_test.go | 4++--
Minternal/web/templates/partials/footer.gohtml | 2+-
3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/internal/external/wakatime.go b/internal/external/wakatime.go @@ -19,8 +19,9 @@ const ( wakaTimeStaleKey = "wakatime:total:stale" ) -// WakaTime reads a user's all-time total from WakaTime's public, -// unauthenticated stats endpoint. The profile's stats must be public. +// WakaTime reads a user's all-time total from the self-hosted Wakapi +// (time.prime8.dev) through its WakaTime-compatible public, +// unauthenticated stats endpoint. Public sharing must be on in Wakapi. type WakaTime struct { httpClient *http.Client baseURL string @@ -30,8 +31,8 @@ type WakaTime struct { func NewWakaTime(c *cache.Cache) *WakaTime { return &WakaTime{ - httpClient: &http.Client{Timeout: 10 * time.Second}, - baseURL: "https://wakatime.com/api/v1", + httpClient: &http.Client{Timeout: 30 * time.Second}, + baseURL: "https://time.prime8.dev/api/compat/wakatime/v1", user: config.WakaTimeUser, cache: c, } @@ -49,6 +50,7 @@ type publicStatsResponse struct { Data struct { Status string `json:"status"` TotalSecondsIncludingOtherLanguage *float64 `json:"total_seconds_including_other_language"` + TotalSeconds *float64 `json:"total_seconds"` // Wakapi leaves the field above null } `json:"data"` } @@ -95,7 +97,7 @@ func (s *WakaTime) stale() *WakaTimeStats { // fetchAllTimeSeconds reports ok=false when the stats are not ready yet // (202 Accepted, a non-ok status, or a missing total). func (s *WakaTime) fetchAllTimeSeconds() (float64, bool, error) { - endpoint := fmt.Sprintf("%s/users/@%s/stats/all_time", s.baseURL, url.PathEscape(s.user)) + endpoint := fmt.Sprintf("%s/users/%s/stats/all_time", s.baseURL, url.PathEscape(s.user)) resp, err := s.httpClient.Get(endpoint) if err != nil { return 0, false, err @@ -120,6 +122,9 @@ func (s *WakaTime) fetchAllTimeSeconds() (float64, bool, error) { } total := data.Data.TotalSecondsIncludingOtherLanguage + if total == nil { + total = data.Data.TotalSeconds + } if (data.Data.Status != "" && data.Data.Status != "ok") || total == nil || *total <= 0 { return 0, false, nil } diff --git a/internal/external/wakatime_test.go b/internal/external/wakatime_test.go @@ -38,7 +38,7 @@ func TestFetchTotalParsesPublicStats(t *testing.T) { if stats == nil || stats.AllTime.TotalText != "3.4k hrs logged" { t.Fatalf("stats = %+v", stats) } - if gotPath != "/users/@moncheeta/stats/all_time" { + if gotPath != "/users/moncheeta/stats/all_time" { t.Fatalf("path = %q", gotPath) } if gotAuth != "" { @@ -64,7 +64,7 @@ func TestFetchTotalEscapesUser(t *testing.T) { if _, err := newTestWakaTime(srv, "a b/c").FetchTotal(); err != nil { t.Fatal(err) } - if gotPath != "/users/@a%20b%2Fc/stats/all_time" { + if gotPath != "/users/a%20b%2Fc/stats/all_time" { t.Fatalf("path = %q", gotPath) } } diff --git a/internal/web/templates/partials/footer.gohtml b/internal/web/templates/partials/footer.gohtml @@ -3,7 +3,7 @@ <button type="button" class="ssh" data-ssh-copy title="copy to clipboard"><span class="ssh-dollar">$</span> <span data-ssh-command>ssh prime8.dev</span><span class="ssh-hint">[copy]</span></button> <span class="spacer"></span> {{with wakaTimeUser}} - <a class="wakatime" id="wakatime-link" href="https://wakatime.com/@{{.}}" target="_blank" rel="noopener noreferrer">Loading...</a> + <a class="wakatime" id="wakatime-link" href="https://time.prime8.dev" target="_blank" rel="noopener noreferrer">Loading...</a> {{end}} </footer>