aboutsummaryrefslogtreecommitdiff
path: root/backend/storage
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-12-22 19:17:59 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2025-12-22 19:17:59 +0100
commitc66a5cc0809875df0299ebb80be423436c195416 (patch)
tree84ce7dd31c9e4dc10dbb41c5428cc2cb66bb44d9 /backend/storage
parent9ad7b0e67c90697893f188323a32590fbecd5a65 (diff)
fix(storage): remove query from ref
Diffstat (limited to 'backend/storage')
-rw-r--r--backend/storage/stats.go12
1 files changed, 5 insertions, 7 deletions
diff --git a/backend/storage/stats.go b/backend/storage/stats.go
index d95387d..b30cb8c 100644
--- a/backend/storage/stats.go
+++ b/backend/storage/stats.go
@@ -5,7 +5,7 @@ import (
"fmt"
"log/slog"
"net/http"
- "regexp"
+ "net/url"
"slices"
"strings"
"sync"
@@ -43,8 +43,6 @@ func newLoaded() *loaded {
}
}
-var trimRefererReg = regexp.MustCompile(`https?://([a-z-0-9.]+(:\d+)?)/.*`)
-
var load = newLoaded()
func UpdateStats(ctx context.Context, r *http.Request, domain string) error {
@@ -56,13 +54,13 @@ func UpdateStats(ctx context.Context, r *http.Request, domain string) error {
if ref == "" {
return nil
}
- subs := trimRefererReg.FindStringSubmatch(ref)
- if len(subs) < 2 {
+ refUrl, err := url.Parse(ref)
+ if err != nil {
return nil
}
- ref = subs[1]
+ ref = refUrl.Host
if ref == domain || ref == fmt.Sprintf("localhost:%d", 8000) {
- ref = subs[0][strings.Index(subs[0], ref)+len(ref):]
+ ref = refUrl.Path
if ref == target || strings.HasPrefix(ref, "/admin") || ref == "/favicon.ico" {
return nil
}