Skip to content

Commit

Permalink
Merge branch 'xxx'
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Dec 6, 2023
2 parents 23a43ea + 37f38c1 commit 003b664
Show file tree
Hide file tree
Showing 23 changed files with 154 additions and 89 deletions.
30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
module zgo.at/goatcounter/v2

go 1.19
go 1.21

require (
code.soquee.net/otp v0.0.4
github.com/BurntSushi/toml v1.3.2
github.com/PuerkitoBio/goquery v1.8.1
github.com/bmatcuk/doublestar/v4 v4.6.0
github.com/bmatcuk/doublestar/v4 v4.6.1
github.com/boombuler/barcode v1.0.1
github.com/go-chi/chi/v5 v5.0.10
github.com/google/uuid v1.3.0
github.com/gorilla/websocket v1.5.0
github.com/mattn/go-sqlite3 v1.14.17
github.com/google/uuid v1.4.0
github.com/gorilla/websocket v1.5.1
github.com/mattn/go-sqlite3 v1.14.18
github.com/monoculum/formam/v3 v3.6.1-0.20221019142301-7634f9dcc123
github.com/oschwald/geoip2-golang v1.4.0
github.com/russross/blackfriday/v2 v2.1.0
github.com/teamwork/reload v1.4.2
golang.org/x/crypto v0.11.0
golang.org/x/crypto v0.16.0
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
golang.org/x/image v0.9.0
golang.org/x/net v0.12.0
golang.org/x/sync v0.3.0
golang.org/x/text v0.11.0
golang.org/x/image v0.14.0
golang.org/x/net v0.19.0
golang.org/x/sync v0.5.0
golang.org/x/text v0.14.0
zgo.at/bgrun v0.0.0-00010101000000-000000000000
zgo.at/blackmail v0.0.0-20221021025740-b3fdfc32a1aa
zgo.at/errors v1.2.0
Expand All @@ -35,12 +35,12 @@ require (
zgo.at/z18n v0.0.0-20221020022658-4ea64eeb51d9
zgo.at/zcache v1.2.0
zgo.at/zcache/v2 v2.1.0
zgo.at/zdb v0.0.0-20230613205410-1358de6a191d
zgo.at/zdb v0.0.0-20230818141326-8a736d26f78a
zgo.at/zhttp v0.0.0-20230625130145-b6058b7d5c54
zgo.at/zli v0.0.0-20230524003221-1db1ccaf5481
zgo.at/zli v0.0.0-20231124215953-c6675b0b020a
zgo.at/zlog v0.0.0-20211017235224-dd4772ddf860
zgo.at/zprof v0.0.0-20211217104121-c3c12596d8f0
zgo.at/zstd v0.0.0-20230630011541-913635908466
zgo.at/zstd v0.0.0-20231206020926-f20b0b1e56be
zgo.at/ztpl v0.0.0-20230614191641-fc02754e9558
zgo.at/zvalidate v0.0.0-20221021025449-cb54fa8efade
)
Expand All @@ -62,7 +62,7 @@ require (
github.com/oschwald/maxminddb-golang v1.10.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/tools v0.6.0 // indirect
)
70 changes: 38 additions & 32 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions handlers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ func TestAPICount(t *testing.T) {
// Calculate session from IP+UserAgent
{
APICountRequest{Hits: []APICountRequestHit{
{Path: "/foo", UserAgent: "Mozilla/5.0 (Linux) Firefox/1", IP: "66.66.66.66"},
{Path: "/foo", UserAgent: "Mozilla/5.0 (Linux) Firefox/1", IP: "51.171.91.33"},
{Path: "/foo", UserAgent: "Mozilla/5.0 (Linux) Firefox/1", IP: "66.66.66.67"},
{Path: "/foo", UserAgent: "Mozilla/5.0 (Linux) Firefox/1", IP: "66.66.66.66"},
{Path: "/foo", UserAgent: "Mozilla/5.0 (Linux) Firefox/1", IP: "51.171.91.33"},
}},
202, respOK, `
hit_id site_id path title event ua browser system session bot ref ref_s size loc first created_at
1 1 /foo 0 ~Z (~L) ~f1 Firefox 1 Linux 00112233445566778899aabbccddef01 0 NULL NL 1 2020-06-18 14:42:00
1 1 /foo 0 ~Z (~L) ~f1 Firefox 1 Linux 00112233445566778899aabbccddef01 0 NULL IE 1 2020-06-18 14:42:00
2 1 /foo 0 ~Z (~L) ~f1 Firefox 1 Linux 00112233445566778899aabbccddef02 0 NULL US 1 2020-06-18 14:42:00
3 1 /foo 0 ~Z (~L) ~f1 Firefox 1 Linux 00112233445566778899aabbccddef01 0 NULL NL 0 2020-06-18 14:42:00
3 1 /foo 0 ~Z (~L) ~f1 Firefox 1 Linux 00112233445566778899aabbccddef01 0 NULL IE 0 2020-06-18 14:42:00
`,
},

Expand Down
5 changes: 5 additions & 0 deletions handlers/bosmang.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (h bosmang) mount(r chi.Router, db zdb.DB) {
}))

a.Get("/bosmang/cache", zhttp.Wrap(h.cache))
a.Get("/bosmang/error", zhttp.Wrap(h.error))
a.Get("/bosmang/bgrun", zhttp.Wrap(h.bgrun))
a.Post("/bosmang/bgrun/{task}", zhttp.Wrap(h.runTask))
a.Get("/bosmang/metrics", zhttp.Wrap(h.metrics))
Expand Down Expand Up @@ -164,3 +165,7 @@ func (h bosmang) login(w http.ResponseWriter, r *http.Request) error {

return zhttp.SeeOther(w, site.URL(r.Context()))
}

func (h bosmang) error(w http.ResponseWriter, r *http.Request) error {
return guru.New(500, "test error")
}
5 changes: 3 additions & 2 deletions handlers/mw.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"zgo.at/zlog"
"zgo.at/zstd/znet"
"zgo.at/zstd/zruntime"
"zgo.at/zstd/zslice"
"zgo.at/zstd/ztime"
"zgo.at/zvalidate"
)
Expand Down Expand Up @@ -368,9 +369,9 @@ func addcsp(domainStatic string) func(http.Handler) http.Handler {
header.CSPFrameAncestors: frame,
header.CSPFrameSrc: {header.CSPSourceSelf},
header.CSPDefaultSrc: {header.CSPSourceNone},
header.CSPImgSrc: append(ds, "data:"),
header.CSPImgSrc: zslice.AppendCopy(ds, "data:"),
header.CSPScriptSrc: ds,
header.CSPStyleSrc: append(ds, header.CSPSourceUnsafeInline),
header.CSPStyleSrc: zslice.AppendCopy(ds, header.CSPSourceUnsafeInline),
header.CSPFontSrc: ds,
header.CSPFormAction: {header.CSPSourceSelf},
header.CSPManifestSrc: ds,
Expand Down
1 change: 1 addition & 0 deletions handlers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ func (h settings) merge(w http.ResponseWriter, r *http.Request) error {
if v.HasErrors() {
return v
}
paths = slices.DeleteFunc(paths, func(p int64) bool { return p == dst })

ctx := goatcounter.CopyContextValues(r.Context())
bgrun.RunFunction(fmt.Sprintf("merge:%d", Site(ctx).ID), func() {
Expand Down
4 changes: 4 additions & 0 deletions hit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"net/url"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -384,6 +385,9 @@ func (h *Hits) Purge(ctx context.Context, pathIDs []int64) error {

// Merge the given paths.
func (h *Hits) Merge(ctx context.Context, dst int64, pathIDs []int64) error {
// Shouldn't happen, but just in case.
pathIDs = slices.DeleteFunc(pathIDs, func(p int64) bool { return p == dst })

site := MustGetSite(ctx).ID

err := (&Path{}).ByID(ctx, dst) // Ensure this site owns the path.
Expand Down
2 changes: 1 addition & 1 deletion hit_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestHitStats(t *testing.T) {
},
{
"id": "NL",
"name": "Netherlands",
"name": "The Netherlands",
"count": 1
}
]
Expand Down
Loading

0 comments on commit 003b664

Please sign in to comment.