Commit 9c8d241
Eric Bower
·
2025-12-17 22:03:10 -0500 EST
parent d247cbd
refactor(db): use sqlx
+1,
-0
+2,
-1
| ... | ... | @@ -7,12 +7,13 @@ import ( | |
| 7 | 7 | "os" | |
| 8 | 8 | "time" | |
| 9 | 9 | ||
| 10 | + | "github.com/jmoiron/sqlx" | |
| 10 | 11 | "github.com/picosh/pico/pkg/db" | |
| 11 | 12 | "github.com/picosh/pico/pkg/db/postgres" | |
| 12 | 13 | "github.com/picosh/pico/pkg/shared" | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| 15 | - | func findPosts(dbpool *sql.DB) ([]*db.Post, error) { | |
| 16 | + | func findPosts(dbpool *sqlx.DB) ([]*db.Post, error) { | |
| 16 | 17 | var posts []*db.Post | |
| 17 | 18 | rs, err := dbpool.Query(`SELECT | |
| 18 | 19 | id, user_id, filename, title, text, description, |
+5,
-4
| ... | ... | @@ -7,12 +7,13 @@ import ( | |
| 7 | 7 | "log/slog" | |
| 8 | 8 | "os" | |
| 9 | 9 | ||
| 10 | + | "github.com/jmoiron/sqlx" | |
| 10 | 11 | "github.com/picosh/pico/pkg/db" | |
| 11 | 12 | "github.com/picosh/pico/pkg/db/postgres" | |
| 12 | 13 | "github.com/picosh/pico/pkg/shared" | |
| 13 | 14 | ) | |
| 14 | 15 | ||
| 15 | - | func findPosts(dbpool *sql.DB) ([]*db.Post, error) { | |
| 16 | + | func findPosts(dbpool *sqlx.DB) ([]*db.Post, error) { | |
| 16 | 17 | var posts []*db.Post | |
| 17 | 18 | rs, err := dbpool.Query(`SELECT | |
| 18 | 19 | posts.id, user_id, filename, title, text, description, |
| ... | ... | @@ -147,7 +148,7 @@ func main() { | |
| 147 | 148 | panic(err) | |
| 148 | 149 | } | |
| 149 | 150 | ||
| 150 | - | proseKeys, err := proseDb.FindKeysForUser(proseUser) | |
| 151 | + | proseKeys, err := proseDb.FindKeysByUser(proseUser) | |
| 151 | 152 | if err != nil { | |
| 152 | 153 | panic(err) | |
| 153 | 154 | } |
| ... | ... | @@ -165,7 +166,7 @@ func main() { | |
| 165 | 166 | updateIDs := []*ConflictData{} | |
| 166 | 167 | logger.Info("Finding conflicts") | |
| 167 | 168 | for _, listUser := range listUsers { | |
| 168 | - | listKeys, err := listsDb.FindKeysForUser(listUser) | |
| 169 | + | listKeys, err := listsDb.FindKeysByUser(listUser) | |
| 169 | 170 | if err != nil { | |
| 170 | 171 | panic(err) | |
| 171 | 172 | } |
| ... | ... | @@ -180,7 +181,7 @@ func main() { | |
| 180 | 181 | continue | |
| 181 | 182 | } else { | |
| 182 | 183 | proseUser := userMap[listUser.Name] | |
| 183 | - | proseKeys, err := proseDb.FindKeysForUser(proseUser) | |
| 184 | + | proseKeys, err := proseDb.FindKeysByUser(proseUser) | |
| 184 | 185 | if err != nil { | |
| 185 | 186 | panic(err) | |
| 186 | 187 | } |
| ... | ... | @@ -1,16 +1,16 @@ | |
| 1 | 1 | package main | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "database/sql" | |
| 5 | 4 | "log/slog" | |
| 6 | 5 | "os" | |
| 7 | 6 | ||
| 7 | + | "github.com/jmoiron/sqlx" | |
| 8 | 8 | "github.com/picosh/pico/pkg/db" | |
| 9 | 9 | "github.com/picosh/pico/pkg/db/postgres" | |
| 10 | 10 | "github.com/picosh/pico/pkg/shared" | |
| 11 | 11 | ) | |
| 12 | 12 | ||
| 13 | - | func findPosts(dbpool *sql.DB) ([]*db.Post, error) { | |
| 13 | + | func findPosts(dbpool *sqlx.DB) ([]*db.Post, error) { | |
| 14 | 14 | var posts []*db.Post | |
| 15 | 15 | rs, err := dbpool.Query(`SELECT | |
| 16 | 16 | posts.id, user_id, filename, title, text, description, |
| ... | ... | @@ -69,7 +69,7 @@ func main() { | |
| 69 | 69 | continue | |
| 70 | 70 | } | |
| 71 | 71 | if len(parsed.Tags) > 0 { | |
| 72 | - | err := picoDb.ReplaceTagsForPost(parsed.Tags, post.ID) | |
| 72 | + | err := picoDb.ReplaceTagsByPost(parsed.Tags, post.ID) | |
| 73 | 73 | panic(err) | |
| 74 | 74 | } | |
| 75 | 75 | } |
M
go.mod
+48,
-12
| ... | ... | @@ -1,8 +1,6 @@ | |
| 1 | 1 | module github.com/picosh/pico | |
| 2 | 2 | ||
| 3 | - | go 1.24 | |
| 4 | - | ||
| 5 | - | toolchain go1.24.0 | |
| 3 | + | go 1.24.0 | |
| 6 | 4 | ||
| 7 | 5 | // replace github.com/picosh/tunkit => ../tunkit | |
| 8 | 6 |
| ... | ... | @@ -55,6 +53,8 @@ require ( | |
| 55 | 53 | github.com/prometheus/client_golang v1.22.0 | |
| 56 | 54 | github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 | |
| 57 | 55 | github.com/simplesurance/go-ip-anonymizer v0.0.0-20200429124537-35a880f8e87d | |
| 56 | + | github.com/testcontainers/testcontainers-go v0.40.0 | |
| 57 | + | github.com/testcontainers/testcontainers-go/modules/postgres v0.40.0 | |
| 58 | 58 | github.com/x-way/crawlerdetect v0.2.28 | |
| 59 | 59 | github.com/yuin/goldmark v1.7.8 | |
| 60 | 60 | github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc |
| ... | ... | @@ -62,7 +62,7 @@ require ( | |
| 62 | 62 | go.abhg.dev/goldmark/anchor v0.2.0 | |
| 63 | 63 | go.abhg.dev/goldmark/hashtag v0.3.1 | |
| 64 | 64 | go.abhg.dev/goldmark/toc v0.11.0 | |
| 65 | - | golang.org/x/crypto v0.38.0 | |
| 65 | + | golang.org/x/crypto v0.43.0 | |
| 66 | 66 | google.golang.org/protobuf v1.36.6 | |
| 67 | 67 | gopkg.in/yaml.v2 v2.4.0 | |
| 68 | 68 | modernc.org/sqlite v1.36.2 |
| ... | ... | @@ -71,9 +71,10 @@ require ( | |
| 71 | 71 | require ( | |
| 72 | 72 | cel.dev/expr v0.22.1 // indirect | |
| 73 | 73 | codeberg.org/emersion/go-scfg v0.1.0 // indirect | |
| 74 | - | dario.cat/mergo v1.0.1 // indirect | |
| 74 | + | dario.cat/mergo v1.0.2 // indirect | |
| 75 | 75 | filippo.io/edwards25519 v1.1.0 // indirect | |
| 76 | 76 | github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect | |
| 77 | + | github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect | |
| 77 | 78 | github.com/KimMachineGun/automemlimit v0.7.1 // indirect | |
| 78 | 79 | github.com/Masterminds/goutils v1.1.1 // indirect | |
| 79 | 80 | github.com/Masterminds/semver/v3 v3.3.1 // indirect |
| ... | ... | @@ -98,13 +99,19 @@ require ( | |
| 98 | 99 | github.com/caddyserver/certmagic v0.23.0 // indirect | |
| 99 | 100 | github.com/caddyserver/zerossl v0.1.3 // indirect | |
| 100 | 101 | github.com/ccoveille/go-safecast v1.6.1 // indirect | |
| 102 | + | github.com/cenkalti/backoff/v4 v4.3.0 // indirect | |
| 101 | 103 | github.com/cespare/xxhash v1.1.0 // indirect | |
| 102 | 104 | github.com/cespare/xxhash/v2 v2.3.0 // indirect | |
| 103 | 105 | github.com/chzyer/readline v1.5.1 // indirect | |
| 104 | 106 | github.com/cloudflare/circl v1.6.0 // indirect | |
| 107 | + | github.com/containerd/errdefs v1.0.0 // indirect | |
| 108 | + | github.com/containerd/errdefs/pkg v0.3.0 // indirect | |
| 109 | + | github.com/containerd/log v0.1.0 // indirect | |
| 110 | + | github.com/containerd/platforms v0.2.1 // indirect | |
| 105 | 111 | github.com/coreos/go-oidc/v3 v3.13.0 // indirect | |
| 106 | 112 | github.com/coreos/go-semver v0.3.1 // indirect | |
| 107 | 113 | github.com/coreos/go-systemd/v22 v22.5.0 // indirect | |
| 114 | + | github.com/cpuguy83/dockercfg v0.3.2 // indirect | |
| 108 | 115 | github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect | |
| 109 | 116 | github.com/darkweak/go-esi v0.0.6 // indirect | |
| 110 | 117 | github.com/darkweak/storages/badger v0.0.14 // indirect |
| ... | ... | @@ -115,6 +122,7 @@ require ( | |
| 115 | 122 | github.com/darkweak/storages/otter v0.0.14 // indirect | |
| 116 | 123 | github.com/darkweak/storages/redis v0.0.14 // indirect | |
| 117 | 124 | github.com/darkweak/storages/simplefs v0.0.14 // indirect | |
| 125 | + | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | |
| 118 | 126 | github.com/delthas/go-libnp v0.1.0 // indirect | |
| 119 | 127 | github.com/delthas/go-localeinfo v0.1.0 // indirect | |
| 120 | 128 | github.com/dgraph-io/badger v1.6.2 // indirect |
| ... | ... | @@ -124,7 +132,11 @@ require ( | |
| 124 | 132 | github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da // indirect | |
| 125 | 133 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect | |
| 126 | 134 | github.com/disintegration/imaging v1.6.2 // indirect | |
| 135 | + | github.com/distribution/reference v0.6.0 // indirect | |
| 127 | 136 | github.com/dlclark/regexp2 v1.11.5 // indirect | |
| 137 | + | github.com/docker/docker v28.5.1+incompatible // indirect | |
| 138 | + | github.com/docker/go-connections v0.6.0 // indirect | |
| 139 | + | github.com/docker/go-units v0.5.0 // indirect | |
| 128 | 140 | github.com/dolthub/maphash v0.1.0 // indirect | |
| 129 | 141 | github.com/dsoprea/go-exif v0.0.0-20230826092837-6579e82b732d // indirect | |
| 130 | 142 | github.com/dsoprea/go-exif/v2 v2.0.0-20230826092837-6579e82b732d // indirect |
| ... | ... | @@ -134,6 +146,8 @@ require ( | |
| 134 | 146 | github.com/dsoprea/go-png-image-structure v0.0.0-20210512210324-29b889a6093d // indirect | |
| 135 | 147 | github.com/dsoprea/go-utility v0.0.0-20221003172846-a3e1774ef349 // indirect | |
| 136 | 148 | github.com/dustin/go-humanize v1.0.1 // indirect | |
| 149 | + | github.com/ebitengine/purego v0.8.4 // indirect | |
| 150 | + | github.com/felixge/httpsnoop v1.0.4 // indirect | |
| 137 | 151 | github.com/forPelevin/gomoji v1.3.0 // indirect | |
| 138 | 152 | github.com/francoispqt/gojay v1.2.13 // indirect | |
| 139 | 153 | github.com/gammazero/deque v1.0.0 // indirect |
| ... | ... | @@ -143,6 +157,8 @@ require ( | |
| 143 | 157 | github.com/go-ini/ini v1.67.0 // indirect | |
| 144 | 158 | github.com/go-jose/go-jose/v3 v3.0.4 // indirect | |
| 145 | 159 | github.com/go-jose/go-jose/v4 v4.0.5 // indirect | |
| 160 | + | github.com/go-logr/logr v1.4.2 // indirect | |
| 161 | + | github.com/go-logr/stdr v1.2.2 // indirect | |
| 146 | 162 | github.com/go-ole/go-ole v1.3.0 // indirect | |
| 147 | 163 | github.com/go-redis/redis/v8 v8.11.5 // indirect | |
| 148 | 164 | github.com/go-sql-driver/mysql v1.9.1 // indirect |
| ... | ... | @@ -186,6 +202,7 @@ require ( | |
| 186 | 202 | github.com/kr/text v0.2.0 // indirect | |
| 187 | 203 | github.com/libdns/libdns v1.0.0-beta.1 // indirect | |
| 188 | 204 | github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35 // indirect | |
| 205 | + | github.com/magiconair/properties v1.8.10 // indirect | |
| 189 | 206 | github.com/manifoldco/promptui v0.9.0 // indirect | |
| 190 | 207 | github.com/maruel/natural v1.1.1 // indirect | |
| 191 | 208 | github.com/mattn/go-colorable v0.1.14 // indirect |
| ... | ... | @@ -204,8 +221,16 @@ require ( | |
| 204 | 221 | github.com/mitchellh/reflectwalk v1.0.2 // indirect | |
| 205 | 222 | github.com/mmcdole/goxpp v1.1.1 // indirect | |
| 206 | 223 | github.com/mmcloughlin/md4 v0.1.2 // indirect | |
| 224 | + | github.com/moby/docker-image-spec v1.3.1 // indirect | |
| 225 | + | github.com/moby/go-archive v0.1.0 // indirect | |
| 226 | + | github.com/moby/patternmatcher v0.6.0 // indirect | |
| 227 | + | github.com/moby/sys/sequential v0.6.0 // indirect | |
| 228 | + | github.com/moby/sys/user v0.4.0 // indirect | |
| 229 | + | github.com/moby/sys/userns v0.1.0 // indirect | |
| 230 | + | github.com/moby/term v0.5.0 // indirect | |
| 207 | 231 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | |
| 208 | 232 | github.com/modern-go/reflect2 v1.0.2 // indirect | |
| 233 | + | github.com/morikuni/aec v1.0.0 // indirect | |
| 209 | 234 | github.com/mschoch/smat v0.2.0 // indirect | |
| 210 | 235 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | |
| 211 | 236 | github.com/nats-io/nats.go v1.40.1 // indirect |
| ... | ... | @@ -215,10 +240,13 @@ require ( | |
| 215 | 240 | github.com/neurosnap/go-jpeg-image-structure v0.0.0-20221010133817-70b1c1ff679e // indirect | |
| 216 | 241 | github.com/nutsdb/nutsdb v1.0.4 // indirect | |
| 217 | 242 | github.com/onsi/ginkgo/v2 v2.23.3 // indirect | |
| 243 | + | github.com/opencontainers/go-digest v1.0.0 // indirect | |
| 244 | + | github.com/opencontainers/image-spec v1.1.1 // indirect | |
| 218 | 245 | github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect | |
| 219 | 246 | github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect | |
| 220 | 247 | github.com/pierrec/lz4/v4 v4.1.22 // indirect | |
| 221 | 248 | github.com/pkg/errors v0.9.1 // indirect | |
| 249 | + | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect | |
| 222 | 250 | github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect | |
| 223 | 251 | github.com/pquerna/cachecontrol v0.2.0 // indirect | |
| 224 | 252 | github.com/prometheus/client_model v0.6.2 // indirect |
| ... | ... | @@ -238,9 +266,11 @@ require ( | |
| 238 | 266 | github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect | |
| 239 | 267 | github.com/secure-io/sio-go v0.3.1 // indirect | |
| 240 | 268 | github.com/shirou/gopsutil/v3 v3.24.5 // indirect | |
| 269 | + | github.com/shirou/gopsutil/v4 v4.25.6 // indirect | |
| 241 | 270 | github.com/shoenig/go-m1cpu v0.1.6 // indirect | |
| 242 | 271 | github.com/shopspring/decimal v1.4.0 // indirect | |
| 243 | 272 | github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect | |
| 273 | + | github.com/sirupsen/logrus v1.9.3 // indirect | |
| 244 | 274 | github.com/slackhq/nebula v1.9.5 // indirect | |
| 245 | 275 | github.com/smallstep/certificates v0.28.3 // indirect | |
| 246 | 276 | github.com/smallstep/cli-utils v0.12.1 // indirect |
| ... | ... | @@ -254,6 +284,7 @@ require ( | |
| 254 | 284 | github.com/spf13/cobra v1.9.1 // indirect | |
| 255 | 285 | github.com/spf13/pflag v1.0.6 // indirect | |
| 256 | 286 | github.com/stoewer/go-strcase v1.3.0 // indirect | |
| 287 | + | github.com/stretchr/testify v1.11.1 // indirect | |
| 257 | 288 | github.com/tailscale/tscert v0.0.0-20240608151842-d3f834017e53 // indirect | |
| 258 | 289 | github.com/tidwall/btree v1.7.0 // indirect | |
| 259 | 290 | github.com/tidwall/gjson v1.17.0 // indirect |
| ... | ... | @@ -276,6 +307,11 @@ require ( | |
| 276 | 307 | go.etcd.io/etcd/client/pkg/v3 v3.5.21 // indirect | |
| 277 | 308 | go.etcd.io/etcd/client/v3 v3.5.21 // indirect | |
| 278 | 309 | go.opencensus.io v0.24.0 // indirect | |
| 310 | + | go.opentelemetry.io/auto/sdk v1.1.0 // indirect | |
| 311 | + | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect | |
| 312 | + | go.opentelemetry.io/otel v1.35.0 // indirect | |
| 313 | + | go.opentelemetry.io/otel/metric v1.35.0 // indirect | |
| 314 | + | go.opentelemetry.io/otel/trace v1.35.0 // indirect | |
| 279 | 315 | go.step.sm/crypto v0.60.0 // indirect | |
| 280 | 316 | go.uber.org/automaxprocs v1.6.0 // indirect | |
| 281 | 317 | go.uber.org/mock v0.5.0 // indirect |
| ... | ... | @@ -285,15 +321,15 @@ require ( | |
| 285 | 321 | golang.org/x/crypto/x509roots/fallback v0.0.0-20250317152234-d0a798f77473 // indirect | |
| 286 | 322 | golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect | |
| 287 | 323 | golang.org/x/image v0.25.0 // indirect | |
| 288 | - | golang.org/x/mod v0.24.0 // indirect | |
| 289 | - | golang.org/x/net v0.38.0 // indirect | |
| 324 | + | golang.org/x/mod v0.28.0 // indirect | |
| 325 | + | golang.org/x/net v0.45.0 // indirect | |
| 290 | 326 | golang.org/x/oauth2 v0.28.0 // indirect | |
| 291 | - | golang.org/x/sync v0.14.0 // indirect | |
| 292 | - | golang.org/x/sys v0.33.0 // indirect | |
| 293 | - | golang.org/x/term v0.32.0 // indirect | |
| 294 | - | golang.org/x/text v0.25.0 // indirect | |
| 327 | + | golang.org/x/sync v0.17.0 // indirect | |
| 328 | + | golang.org/x/sys v0.37.0 // indirect | |
| 329 | + | golang.org/x/term v0.36.0 // indirect | |
| 330 | + | golang.org/x/text v0.30.0 // indirect | |
| 295 | 331 | golang.org/x/time v0.11.0 // indirect | |
| 296 | - | golang.org/x/tools v0.31.0 // indirect | |
| 332 | + | golang.org/x/tools v0.37.0 // indirect | |
| 297 | 333 | google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 // indirect | |
| 298 | 334 | google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect | |
| 299 | 335 | google.golang.org/grpc v1.71.0 // indirect |
M
go.sum
+101,
-26
| ... | ... | @@ -20,8 +20,8 @@ cloud.google.com/go/longrunning v0.6.6 h1:XJNDo5MUfMM05xK3ewpbSdmt7R2Zw+aQEMbdQR | |
| 20 | 20 | cloud.google.com/go/longrunning v0.6.6/go.mod h1:hyeGJUrPHcx0u2Uu1UFSoYZLn4lkMrccJig0t4FI7yw= | |
| 21 | 21 | codeberg.org/emersion/go-scfg v0.1.0 h1:6dnGU0ZI4gX+O5rMjwhoaySItzHG710eXL5TIQKl+uM= | |
| 22 | 22 | codeberg.org/emersion/go-scfg v0.1.0/go.mod h1:0nooW1ufBB4SlJEdTtiVN9Or+bnNM1icOkQ6Tbrq6O0= | |
| 23 | - | dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= | |
| 24 | - | dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= | |
| 23 | + | dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= | |
| 24 | + | dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= | |
| 25 | 25 | dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl+fi1br7+Rr3LqpNJf1/uxUdtRUV+Tnj0o93V2B9MU= | |
| 26 | 26 | dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU= | |
| 27 | 27 | dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4= |
| ... | ... | @@ -33,8 +33,12 @@ git.sr.ht/~delthas/senpai v0.4.0 h1:G1cycL0ARqYkqOErjEx/7Cneqykq3POfCsMYnpkWhUY= | |
| 33 | 33 | git.sr.ht/~delthas/senpai v0.4.0/go.mod h1:mzdu4o3wANA6cYzRnrz3w+uGPHA2z3j02JDrr/M3Myc= | |
| 34 | 34 | git.sr.ht/~rockorager/vaxis v0.14.1-0.20250527151737-5530f9f4bcf6 h1:lmSD6ksbKNMLdhT8R2k5FQPz8ObjslX8NkCM6z1kifI= | |
| 35 | 35 | git.sr.ht/~rockorager/vaxis v0.14.1-0.20250527151737-5530f9f4bcf6/go.mod h1:h94aKek3frIV1hJbdXjqnBqaLkbWXvV+UxAsQHg9bns= | |
| 36 | + | github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= | |
| 37 | + | github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= | |
| 36 | 38 | github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 h1:cTp8I5+VIoKjsnZuH8vjyaysT/ses3EvZeaV/1UkF2M= | |
| 37 | 39 | github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= | |
| 40 | + | github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= | |
| 41 | + | github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= | |
| 38 | 42 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | |
| 39 | 43 | github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= | |
| 40 | 44 | github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= |
| ... | ... | @@ -146,6 +150,8 @@ github.com/caddyserver/zerossl v0.1.3 h1:onS+pxp3M8HnHpN5MMbOMyNjmTheJyWRaZYwn+Y | |
| 146 | 150 | github.com/caddyserver/zerossl v0.1.3/go.mod h1:CxA0acn7oEGO6//4rtrRjYgEoa4MFw/XofZnrYwGqG4= | |
| 147 | 151 | github.com/ccoveille/go-safecast v1.6.1 h1:Nb9WMDR8PqhnKCVs2sCB+OqhohwO5qaXtCviZkIff5Q= | |
| 148 | 152 | github.com/ccoveille/go-safecast v1.6.1/go.mod h1:QqwNjxQ7DAqY0C721OIO9InMk9zCwcsO7tnRuHytad8= | |
| 153 | + | github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= | |
| 154 | + | github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= | |
| 149 | 155 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= | |
| 150 | 156 | github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= | |
| 151 | 157 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= |
| ... | ... | @@ -170,6 +176,14 @@ github.com/cloudflare/circl v1.6.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZ | |
| 170 | 176 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= | |
| 171 | 177 | github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro= | |
| 172 | 178 | github.com/containerd/console v1.0.4/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= | |
| 179 | + | github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI= | |
| 180 | + | github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M= | |
| 181 | + | github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE= | |
| 182 | + | github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk= | |
| 183 | + | github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= | |
| 184 | + | github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= | |
| 185 | + | github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= | |
| 186 | + | github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= | |
| 173 | 187 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= | |
| 174 | 188 | github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= | |
| 175 | 189 | github.com/coreos/go-oidc/v3 v3.13.0 h1:M66zd0pcc5VxvBNM4pB331Wrsanby+QomQYjN8HamW8= |
| ... | ... | @@ -180,11 +194,15 @@ github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03V | |
| 180 | 194 | github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= | |
| 181 | 195 | github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= | |
| 182 | 196 | github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= | |
| 197 | + | github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA= | |
| 198 | + | github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= | |
| 183 | 199 | github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= | |
| 184 | 200 | github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | |
| 185 | 201 | github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0= | |
| 186 | 202 | github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= | |
| 187 | 203 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= | |
| 204 | + | github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= | |
| 205 | + | github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= | |
| 188 | 206 | github.com/darkweak/go-esi v0.0.6 h1:eVHCJfqrZwOHPfRK7JTlSYG9F8lfpX/d4lz/41RQkd8= | |
| 189 | 207 | github.com/darkweak/go-esi v0.0.6/go.mod h1:IJSayeQZDUh5R5ayyDC3wUEBykti12aUa0eUxZZeodk= | |
| 190 | 208 | github.com/darkweak/souin v1.7.7 h1:pIj/cknEsV/+xgq74VOGE1+0yy0dNnt5I6HGRczJlKk= |
| ... | ... | @@ -235,10 +253,18 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r | |
| 235 | 253 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= | |
| 236 | 254 | github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= | |
| 237 | 255 | github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= | |
| 256 | + | github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= | |
| 257 | + | github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= | |
| 238 | 258 | github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= | |
| 239 | 259 | github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= | |
| 240 | 260 | github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ= | |
| 241 | 261 | github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= | |
| 262 | + | github.com/docker/docker v28.5.1+incompatible h1:Bm8DchhSD2J6PsFzxC35TZo4TLGR2PdW/E69rU45NhM= | |
| 263 | + | github.com/docker/docker v28.5.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= | |
| 264 | + | github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94= | |
| 265 | + | github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE= | |
| 266 | + | github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= | |
| 267 | + | github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= | |
| 242 | 268 | github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ= | |
| 243 | 269 | github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4= | |
| 244 | 270 | github.com/dsoprea/go-exif v0.0.0-20230826092837-6579e82b732d h1:ygcRCGNKuEiA98k7X35hknEN8RIRUF1jrz7k1rZCvsk= |
| ... | ... | @@ -268,6 +294,8 @@ github.com/dsoprea/go-utility/v2 v2.0.0-20200717064901-2fccff4aa15e/go.mod h1:uA | |
| 268 | 294 | github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= | |
| 269 | 295 | github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= | |
| 270 | 296 | github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= | |
| 297 | + | github.com/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw= | |
| 298 | + | github.com/ebitengine/purego v0.8.4/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= | |
| 271 | 299 | github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 h1:oP4q0fw+fOSWn3DfFi4EXdT+B+gTtzx8GC9xsc26Znk= | |
| 272 | 300 | github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= | |
| 273 | 301 | github.com/emersion/go-smtp v0.23.0 h1:ZiriTOTK7sKep7jbWqgB5kPsiBp5wnE5auEMnwRMnGc= |
| ... | ... | @@ -317,6 +345,7 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb | |
| 317 | 345 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= | |
| 318 | 346 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= | |
| 319 | 347 | github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= | |
| 348 | + | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= | |
| 320 | 349 | github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= | |
| 321 | 350 | github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= | |
| 322 | 351 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= |
| ... | ... | @@ -437,6 +466,9 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN | |
| 437 | 466 | github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | |
| 438 | 467 | github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= | |
| 439 | 468 | github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= | |
| 469 | + | github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= | |
| 470 | + | github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 h1:VNqngBF40hVlDloBruUehVYC3ArSgIyScOAyMRqBxRg= | |
| 471 | + | github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1/go.mod h1:RBRO7fro65R6tjKzYgLAFo0t1QEXY1Dp+i/bvpRiqiQ= | |
| 440 | 472 | github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= | |
| 441 | 473 | github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= | |
| 442 | 474 | github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= |
| ... | ... | @@ -536,6 +568,8 @@ github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35 h1:PpXWgLPs+Fqr32 | |
| 536 | 568 | github.com/lufia/plan9stats v0.0.0-20250317134145-8bc96cf8fc35/go.mod h1:autxFIvghDt3jPTLoqZ9OZ7s9qTGNAWmYCjVFWPX/zg= | |
| 537 | 569 | github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= | |
| 538 | 570 | github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= | |
| 571 | + | github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE= | |
| 572 | + | github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= | |
| 539 | 573 | github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= | |
| 540 | 574 | github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= | |
| 541 | 575 | github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= |
| ... | ... | @@ -561,6 +595,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zk | |
| 561 | 595 | github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= | |
| 562 | 596 | github.com/maypok86/otter v1.2.4 h1:HhW1Pq6VdJkmWwcZZq19BlEQkHtI8xgsQzBVXJU0nfc= | |
| 563 | 597 | github.com/maypok86/otter v1.2.4/go.mod h1:mKLfoI7v1HOmQMwFgX4QkRk23mX6ge3RDvjdHOWG4R4= | |
| 598 | + | github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI= | |
| 599 | + | github.com/mdelapenya/tlscert v0.2.0/go.mod h1:O4njj3ELLnJjGdkN7M/vIVCpZ+Cf0L6muqOG4tLSl8o= | |
| 564 | 600 | github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= | |
| 565 | 601 | github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= | |
| 566 | 602 | github.com/mholt/acmez/v3 v3.1.2 h1:auob8J/0FhmdClQicvJvuDavgd5ezwLBfKuYmynhYzc= |
| ... | ... | @@ -596,6 +632,22 @@ github.com/mmcdole/goxpp v1.1.1 h1:RGIX+D6iQRIunGHrKqnA2+700XMCnNv0bAOOv5MUhx8= | |
| 596 | 632 | github.com/mmcdole/goxpp v1.1.1/go.mod h1:v+25+lT2ViuQ7mVxcncQ8ch1URund48oH+jhjiwEgS8= | |
| 597 | 633 | github.com/mmcloughlin/md4 v0.1.2 h1:kGYl+iNbxhyz4u76ka9a+0TXP9KWt/LmnM0QhZwhcBo= | |
| 598 | 634 | github.com/mmcloughlin/md4 v0.1.2/go.mod h1:AAxFX59fddW0IguqNzWlf1lazh1+rXeIt/Bj49cqDTQ= | |
| 635 | + | github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= | |
| 636 | + | github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= | |
| 637 | + | github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ= | |
| 638 | + | github.com/moby/go-archive v0.1.0/go.mod h1:G9B+YoujNohJmrIYFBpSd54GTUB4lt9S+xVQvsJyFuo= | |
| 639 | + | github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= | |
| 640 | + | github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= | |
| 641 | + | github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw= | |
| 642 | + | github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs= | |
| 643 | + | github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU= | |
| 644 | + | github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko= | |
| 645 | + | github.com/moby/sys/user v0.4.0 h1:jhcMKit7SA80hivmFJcbB1vqmw//wU61Zdui2eQXuMs= | |
| 646 | + | github.com/moby/sys/user v0.4.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs= | |
| 647 | + | github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g= | |
| 648 | + | github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= | |
| 649 | + | github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= | |
| 650 | + | github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= | |
| 599 | 651 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | |
| 600 | 652 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= | |
| 601 | 653 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= |
| ... | ... | @@ -603,6 +655,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN | |
| 603 | 655 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= | |
| 604 | 656 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= | |
| 605 | 657 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= | |
| 658 | + | github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= | |
| 659 | + | github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= | |
| 606 | 660 | github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= | |
| 607 | 661 | github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= | |
| 608 | 662 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= |
| ... | ... | @@ -642,6 +696,10 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl | |
| 642 | 696 | github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= | |
| 643 | 697 | github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8= | |
| 644 | 698 | github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY= | |
| 699 | + | github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= | |
| 700 | + | github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= | |
| 701 | + | github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= | |
| 702 | + | github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= | |
| 645 | 703 | github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= | |
| 646 | 704 | github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= | |
| 647 | 705 | github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= |
| ... | ... | @@ -746,6 +804,8 @@ github.com/secure-io/sio-go v0.3.1/go.mod h1:+xbkjDzPjwh4Axd07pRKSNriS9SCiYksWnZ | |
| 746 | 804 | github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= | |
| 747 | 805 | github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI= | |
| 748 | 806 | github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk= | |
| 807 | + | github.com/shirou/gopsutil/v4 v4.25.6 h1:kLysI2JsKorfaFPcYmcJqbzROzsBWEOAtw6A7dIfqXs= | |
| 808 | + | github.com/shirou/gopsutil/v4 v4.25.6/go.mod h1:PfybzyydfZcN+JMMjkF6Zb8Mq1A/VcogFFg7hj50W9c= | |
| 749 | 809 | github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= | |
| 750 | 810 | github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= | |
| 751 | 811 | github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= |
| ... | ... | @@ -829,6 +889,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ | |
| 829 | 889 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | |
| 830 | 890 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | |
| 831 | 891 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= | |
| 892 | + | github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= | |
| 832 | 893 | github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= | |
| 833 | 894 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | |
| 834 | 895 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= |
| ... | ... | @@ -841,11 +902,15 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO | |
| 841 | 902 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | |
| 842 | 903 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | |
| 843 | 904 | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | |
| 844 | - | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | |
| 845 | - | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | |
| 905 | + | github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= | |
| 906 | + | github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= | |
| 846 | 907 | github.com/tailscale/tscert v0.0.0-20240608151842-d3f834017e53 h1:uxMgm0C+EjytfAqyfBG55ZONKQ7mvd7x4YYCWsf8QHQ= | |
| 847 | 908 | github.com/tailscale/tscert v0.0.0-20240608151842-d3f834017e53/go.mod h1:kNGUQ3VESx3VZwRwA9MSCUegIl6+saPL8Noq82ozCaU= | |
| 848 | 909 | github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= | |
| 910 | + | github.com/testcontainers/testcontainers-go v0.40.0 h1:pSdJYLOVgLE8YdUY2FHQ1Fxu+aMnb6JfVz1mxk7OeMU= | |
| 911 | + | github.com/testcontainers/testcontainers-go v0.40.0/go.mod h1:FSXV5KQtX2HAMlm7U3APNyLkkap35zNLxukw9oBi/MY= | |
| 912 | + | github.com/testcontainers/testcontainers-go/modules/postgres v0.40.0 h1:s2bIayFXlbDFexo96y+htn7FzuhpXLYJNnIuglNKqOk= | |
| 913 | + | github.com/testcontainers/testcontainers-go/modules/postgres v0.40.0/go.mod h1:h+u/2KoREGTnTl9UwrQ/g+XhasAT8E6dClclAADeXoQ= | |
| 849 | 914 | github.com/tidwall/btree v1.1.0/go.mod h1:TzIRzen6yHbibdSfK6t8QimqbUnoxUSrZfeW7Uob0q4= | |
| 850 | 915 | github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= | |
| 851 | 916 | github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= |
| ... | ... | @@ -928,16 +993,22 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.5 | |
| 928 | 993 | go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0/go.mod h1:ijPqXp5P6IRRByFVVg9DY8P5HkxkHE5ARIa+86aXPf4= | |
| 929 | 994 | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s= | |
| 930 | 995 | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0/go.mod h1:FRmFuRJfag1IZ2dPkHnEoSFVgTVPUd2qf5Vi69hLb8I= | |
| 931 | - | go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= | |
| 932 | - | go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= | |
| 933 | - | go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= | |
| 934 | - | go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= | |
| 996 | + | go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ= | |
| 997 | + | go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y= | |
| 998 | + | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0 h1:OeNbIYk/2C15ckl7glBlOBp5+WlYsOElzTNmiPW/x60= | |
| 999 | + | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0/go.mod h1:7Bept48yIeqxP2OZ9/AqIpYS94h2or0aB4FypJTc8ZM= | |
| 1000 | + | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.34.0 h1:BEj3SPM81McUZHYjRS5pEgNgnmzGJ5tRpU5krWnV8Bs= | |
| 1001 | + | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.34.0/go.mod h1:9cKLGBDzI/F3NoHLQGm4ZrYdIHsvGt6ej6hUowxY0J4= | |
| 1002 | + | go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M= | |
| 1003 | + | go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE= | |
| 935 | 1004 | go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= | |
| 936 | 1005 | go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= | |
| 937 | 1006 | go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk= | |
| 938 | 1007 | go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= | |
| 939 | - | go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= | |
| 940 | - | go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= | |
| 1008 | + | go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs= | |
| 1009 | + | go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc= | |
| 1010 | + | go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4= | |
| 1011 | + | go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4= | |
| 941 | 1012 | go.step.sm/crypto v0.60.0 h1:UgSw8DFG5xUOGB3GUID17UA32G4j1iNQ4qoMhBmsVFw= | |
| 942 | 1013 | go.step.sm/crypto v0.60.0/go.mod h1:Ep83Lv818L4gV0vhFTdPWRKnL6/5fRMpi8SaoP5ArSw= | |
| 943 | 1014 | go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= |
| ... | ... | @@ -970,8 +1041,8 @@ golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v | |
| 970 | 1041 | golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= | |
| 971 | 1042 | golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= | |
| 972 | 1043 | golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= | |
| 973 | - | golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8= | |
| 974 | - | golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw= | |
| 1044 | + | golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= | |
| 1045 | + | golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= | |
| 975 | 1046 | golang.org/x/crypto/x509roots/fallback v0.0.0-20250317152234-d0a798f77473 h1:XxwA7BHJuoBTkv1tIM7d/8rDnl9i9M0M5anwcJWZtbA= | |
| 976 | 1047 | golang.org/x/crypto/x509roots/fallback v0.0.0-20250317152234-d0a798f77473/go.mod h1:lxN5T34bK4Z/i6cMaU7frUU57VkDXFD4Kamfl/cp9oU= | |
| 977 | 1048 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= |
| ... | ... | @@ -992,8 +1063,8 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= | |
| 992 | 1063 | golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= | |
| 993 | 1064 | golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= | |
| 994 | 1065 | golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= | |
| 995 | - | golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= | |
| 996 | - | golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= | |
| 1066 | + | golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U= | |
| 1067 | + | golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI= | |
| 997 | 1068 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | |
| 998 | 1069 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | |
| 999 | 1070 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= |
| ... | ... | @@ -1030,8 +1101,8 @@ golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= | |
| 1030 | 1101 | golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= | |
| 1031 | 1102 | golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= | |
| 1032 | 1103 | golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= | |
| 1033 | - | golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= | |
| 1034 | - | golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= | |
| 1104 | + | golang.org/x/net v0.45.0 h1:RLBg5JKixCy82FtLJpeNlVM0nrSqpCRYzVU1n8kj0tM= | |
| 1105 | + | golang.org/x/net v0.45.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY= | |
| 1035 | 1106 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= | |
| 1036 | 1107 | golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= | |
| 1037 | 1108 | golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= |
| ... | ... | @@ -1056,8 +1127,8 @@ golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | |
| 1056 | 1127 | golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | |
| 1057 | 1128 | golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | |
| 1058 | 1129 | golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | |
| 1059 | - | golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= | |
| 1060 | - | golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= | |
| 1130 | + | golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= | |
| 1131 | + | golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= | |
| 1061 | 1132 | golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | |
| 1062 | 1133 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | |
| 1063 | 1134 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= |
| ... | ... | @@ -1097,10 +1168,12 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w | |
| 1097 | 1168 | golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1098 | 1169 | golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1099 | 1170 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1171 | + | golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1100 | 1172 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1101 | 1173 | golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1102 | 1174 | golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1103 | 1175 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1176 | + | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1104 | 1177 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1105 | 1178 | golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |
| 1106 | 1179 | golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
| ... | ... | @@ -1115,8 +1188,8 @@ golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | |
| 1115 | 1188 | golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | |
| 1116 | 1189 | golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | |
| 1117 | 1190 | golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | |
| 1118 | - | golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= | |
| 1119 | - | golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= | |
| 1191 | + | golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= | |
| 1192 | + | golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= | |
| 1120 | 1193 | golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= | |
| 1121 | 1194 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | |
| 1122 | 1195 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= |
| ... | ... | @@ -1128,8 +1201,8 @@ golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= | |
| 1128 | 1201 | golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= | |
| 1129 | 1202 | golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= | |
| 1130 | 1203 | golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= | |
| 1131 | - | golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= | |
| 1132 | - | golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= | |
| 1204 | + | golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= | |
| 1205 | + | golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= | |
| 1133 | 1206 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | |
| 1134 | 1207 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | |
| 1135 | 1208 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= |
| ... | ... | @@ -1144,8 +1217,8 @@ golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= | |
| 1144 | 1217 | golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= | |
| 1145 | 1218 | golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= | |
| 1146 | 1219 | golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= | |
| 1147 | - | golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= | |
| 1148 | - | golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= | |
| 1220 | + | golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= | |
| 1221 | + | golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= | |
| 1149 | 1222 | golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | |
| 1150 | 1223 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | |
| 1151 | 1224 | golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= |
| ... | ... | @@ -1167,8 +1240,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc | |
| 1167 | 1240 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= | |
| 1168 | 1241 | golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= | |
| 1169 | 1242 | golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= | |
| 1170 | - | golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU= | |
| 1171 | - | golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ= | |
| 1243 | + | golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE= | |
| 1244 | + | golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w= | |
| 1172 | 1245 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | |
| 1173 | 1246 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | |
| 1174 | 1247 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
| ... | ... | @@ -1243,6 +1316,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= | |
| 1243 | 1316 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | |
| 1244 | 1317 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | |
| 1245 | 1318 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | |
| 1319 | + | gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= | |
| 1320 | + | gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= | |
| 1246 | 1321 | grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= | |
| 1247 | 1322 | honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= | |
| 1248 | 1323 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= |
+6,
-6
| ... | ... | @@ -85,7 +85,7 @@ func introspectHandler(apiConfig *shared.ApiConfig) http.HandlerFunc { | |
| 85 | 85 | token := r.FormValue("token") | |
| 86 | 86 | apiConfig.Cfg.Logger.Info("introspect token", "token", token) | |
| 87 | 87 | ||
| 88 | - | user, err := apiConfig.Dbpool.FindUserForToken(token) | |
| 88 | + | user, err := apiConfig.Dbpool.FindUserByToken(token) | |
| 89 | 89 | if err != nil { | |
| 90 | 90 | apiConfig.Cfg.Logger.Error(err.Error()) | |
| 91 | 91 | http.Error(w, err.Error(), http.StatusUnauthorized) |
| ... | ... | @@ -207,7 +207,7 @@ func tokenHandler(apiConfig *shared.ApiConfig) http.HandlerFunc { | |
| 207 | 207 | "grantType", grantType, | |
| 208 | 208 | ) | |
| 209 | 209 | ||
| 210 | - | _, err := apiConfig.Dbpool.FindUserForToken(token) | |
| 210 | + | _, err := apiConfig.Dbpool.FindUserByToken(token) | |
| 211 | 211 | if err != nil { | |
| 212 | 212 | apiConfig.Cfg.Logger.Error(err.Error()) | |
| 213 | 213 | http.Error(w, err.Error(), http.StatusUnauthorized) |
| ... | ... | @@ -269,7 +269,7 @@ func keyHandler(apiConfig *shared.ApiConfig) http.HandlerFunc { | |
| 269 | 269 | return | |
| 270 | 270 | } | |
| 271 | 271 | ||
| 272 | - | user, err := apiConfig.Dbpool.FindUserForKey(data.Username, authed.Pubkey) | |
| 272 | + | user, err := apiConfig.Dbpool.FindUserByKey(data.Username, authed.Pubkey) | |
| 273 | 273 | if err != nil { | |
| 274 | 274 | log.Error("find user for key", "err", err) | |
| 275 | 275 | w.WriteHeader(http.StatusUnauthorized) |
| ... | ... | @@ -337,7 +337,7 @@ func userHandler(apiConfig *shared.ApiConfig) http.HandlerFunc { | |
| 337 | 337 | return | |
| 338 | 338 | } | |
| 339 | 339 | ||
| 340 | - | keys, err := apiConfig.Dbpool.FindKeysForUser(user) | |
| 340 | + | keys, err := apiConfig.Dbpool.FindKeysByUser(user) | |
| 341 | 341 | if err != nil { | |
| 342 | 342 | apiConfig.Cfg.Logger.Error(err.Error()) | |
| 343 | 343 | http.Error(w, err.Error(), http.StatusNotFound) |
| ... | ... | @@ -357,7 +357,7 @@ func userHandler(apiConfig *shared.ApiConfig) http.HandlerFunc { | |
| 357 | 357 | func rssHandler(apiConfig *shared.ApiConfig) http.HandlerFunc { | |
| 358 | 358 | return func(w http.ResponseWriter, r *http.Request) { | |
| 359 | 359 | apiToken := r.PathValue("token") | |
| 360 | - | user, err := apiConfig.Dbpool.FindUserForToken(apiToken) | |
| 360 | + | user, err := apiConfig.Dbpool.FindUserByToken(apiToken) | |
| 361 | 361 | if err != nil { | |
| 362 | 362 | apiConfig.Cfg.Logger.Error( | |
| 363 | 363 | "could not find user for token", |
| ... | ... | @@ -545,7 +545,7 @@ func paymentWebhookHandler(apiConfig *shared.ApiConfig) http.HandlerFunc { | |
| 545 | 545 | ||
| 546 | 546 | func AddPlusFeedForUser(dbpool db.DB, userID, email string) error { | |
| 547 | 547 | // check if they already have a post grepping for the auth rss url | |
| 548 | - | posts, err := dbpool.FindPostsForUser(&db.Pager{Num: 1000, Page: 0}, userID, "feeds") | |
| 548 | + | posts, err := dbpool.FindPostsByUser(&db.Pager{Num: 1000, Page: 0}, userID, "feeds") | |
| 549 | 549 | if err != nil { | |
| 550 | 550 | return err | |
| 551 | 551 | } |
+6,
-6
| ... | ... | @@ -53,7 +53,7 @@ func TestPaymentWebhook(t *testing.T) { | |
| 53 | 53 | ||
| 54 | 54 | testResponse(t, responseRecorder, 200, "text/plain") | |
| 55 | 55 | ||
| 56 | - | posts, err := apiConfig.Dbpool.FindPostsForUser(&db.Pager{Num: 1000, Page: 0}, testUserID, "feeds") | |
| 56 | + | posts, err := apiConfig.Dbpool.FindPostsByUser(&db.Pager{Num: 1000, Page: 0}, testUserID, "feeds") | |
| 57 | 57 | if err != nil { | |
| 58 | 58 | t.Error("could not find posts for user") | |
| 59 | 59 | } |
| ... | ... | @@ -224,22 +224,22 @@ func (a *AuthDb) FindUserByName(username string) (*db.User, error) { | |
| 224 | 224 | return &db.User{ID: testUserID, Name: username}, nil | |
| 225 | 225 | } | |
| 226 | 226 | ||
| 227 | - | func (a *AuthDb) FindUserForKey(username string, pubkey string) (*db.User, error) { | |
| 227 | + | func (a *AuthDb) FindUserByKey(username string, pubkey string) (*db.User, error) { | |
| 228 | 228 | return &db.User{ID: testUserID, Name: username}, nil | |
| 229 | 229 | } | |
| 230 | 230 | ||
| 231 | - | func (a *AuthDb) FindUserForToken(token string) (*db.User, error) { | |
| 231 | + | func (a *AuthDb) FindUserByToken(token string) (*db.User, error) { | |
| 232 | 232 | if token != "123" { | |
| 233 | 233 | return nil, fmt.Errorf("invalid token") | |
| 234 | 234 | } | |
| 235 | 235 | return &db.User{ID: testUserID, Name: testUsername}, nil | |
| 236 | 236 | } | |
| 237 | 237 | ||
| 238 | - | func (a *AuthDb) HasFeatureForUser(userID string, feature string) bool { | |
| 238 | + | func (a *AuthDb) HasFeatureByUser(userID string, feature string) bool { | |
| 239 | 239 | return true | |
| 240 | 240 | } | |
| 241 | 241 | ||
| 242 | - | func (a *AuthDb) FindKeysForUser(user *db.User) ([]*db.PublicKey, error) { | |
| 242 | + | func (a *AuthDb) FindKeysByUser(user *db.User) ([]*db.PublicKey, error) { | |
| 243 | 243 | return []*db.PublicKey{{ID: "1", UserID: user.ID, Name: "my-key", Key: "nice-pubkey", CreatedAt: &time.Time{}}}, nil | |
| 244 | 244 | } | |
| 245 | 245 |
| ... | ... | @@ -254,7 +254,7 @@ func (a *AuthDb) InsertPost(post *db.Post) (*db.Post, error) { | |
| 254 | 254 | return post, nil | |
| 255 | 255 | } | |
| 256 | 256 | ||
| 257 | - | func (a *AuthDb) FindPostsForUser(pager *db.Pager, userID, space string) (*db.Paginate[*db.Post], error) { | |
| 257 | + | func (a *AuthDb) FindPostsByUser(pager *db.Pager, userID, space string) (*db.Paginate[*db.Post], error) { | |
| 258 | 258 | return &db.Paginate[*db.Post]{ | |
| 259 | 259 | Data: a.Posts, | |
| 260 | 260 | }, nil |
+1,
-1
| ... | ... | @@ -64,7 +64,7 @@ func Middleware(dbpool db.DB, cfg *shared.ConfigSite) pssh.SSHServerMiddleware { | |
| 64 | 64 | ) | |
| 65 | 65 | return writer.Flush() | |
| 66 | 66 | case "ls": | |
| 67 | - | posts, err := dbpool.FindPostsForUser(&db.Pager{Page: 0, Num: 1000}, user.ID, "feeds") | |
| 67 | + | posts, err := dbpool.FindPostsByUser(&db.Pager{Page: 0, Num: 1000}, user.ID, "feeds") | |
| 68 | 68 | if err != nil { | |
| 69 | 69 | _, _ = fmt.Fprintln(sesh.Stderr(), err) | |
| 70 | 70 | return err |
+1,
-1
| ... | ... | @@ -332,7 +332,7 @@ Also, we have centralized logs in our pico.sh TUI that will display realtime fee | |
| 332 | 332 | func (f *Fetcher) RunUser(user *db.User, now time.Time) error { | |
| 333 | 333 | logger := shared.LoggerWithUser(f.cfg.Logger, user) | |
| 334 | 334 | logger.Info("run user") | |
| 335 | - | posts, err := f.db.FindPostsForUser(&db.Pager{Num: 100}, user.ID, "feeds") | |
| 335 | + | posts, err := f.db.FindPostsByUser(&db.Pager{Num: 100}, user.ID, "feeds") | |
| 336 | 336 | if err != nil { | |
| 337 | 337 | return err | |
| 338 | 338 | } |
+1,
-1
| ... | ... | @@ -87,7 +87,7 @@ func blogHandler(w http.ResponseWriter, r *http.Request) { | |
| 87 | 87 | } | |
| 88 | 88 | logger = shared.LoggerWithUser(blogger, user) | |
| 89 | 89 | ||
| 90 | - | pager, err := dbpool.FindPostsForUser(&db.Pager{Num: 1000, Page: 0}, user.ID, cfg.Space) | |
| 90 | + | pager, err := dbpool.FindPostsByUser(&db.Pager{Num: 1000, Page: 0}, user.ID, cfg.Space) | |
| 91 | 91 | if err != nil { | |
| 92 | 92 | logger.Error("could not find posts for user", "err", err.Error()) | |
| 93 | 93 | http.Error(w, "could not fetch posts for blog", http.StatusInternalServerError) |
+1,
-1
| ... | ... | @@ -53,7 +53,7 @@ func (me *PgsPsqlDB) FindUserByPubkey(key string) (*db.User, error) { | |
| 53 | 53 | if len(pk) == 0 { | |
| 54 | 54 | return nil, fmt.Errorf("pubkey not found in our database: [%s]", key) | |
| 55 | 55 | } | |
| 56 | - | // When we run PublicKeyForKey and there are multiple public keys returned from the database | |
| 56 | + | // When we run PublicKeyByKey and there are multiple public keys returned from the database | |
| 57 | 57 | // that should mean that we don't have the correct username for this public key. | |
| 58 | 58 | // When that happens we need to reject the authentication and ask the user to provide the correct | |
| 59 | 59 | // username when using ssh. So instead of `ssh <domain>` it should be `ssh user@<domain>` |
+1,
-1
| ... | ... | @@ -24,7 +24,7 @@ func getUser(s *pssh.SSHServerConnSession, dbpool db.DB) (*db.User, error) { | |
| 24 | 24 | ||
| 25 | 25 | key := utils.KeyForKeyText(s.PublicKey()) | |
| 26 | 26 | ||
| 27 | - | user, err := dbpool.FindUserForKey(s.User(), key) | |
| 27 | + | user, err := dbpool.FindUserByKey(s.User(), key) | |
| 28 | 28 | if err != nil { | |
| 29 | 29 | return nil, err | |
| 30 | 30 | } |
+4,
-4
| ... | ... | @@ -32,7 +32,7 @@ func NewUploadHandler(dbpool db.DB, cfg *shared.ConfigSite) *UploadHandler { | |
| 32 | 32 | } | |
| 33 | 33 | ||
| 34 | 34 | func (h *UploadHandler) getAuthorizedKeyFile(user *db.User) (*sendutils.VirtualFile, string, error) { | |
| 35 | - | keys, err := h.DBPool.FindKeysForUser(user) | |
| 35 | + | keys, err := h.DBPool.FindKeysByUser(user) | |
| 36 | 36 | text := "" | |
| 37 | 37 | var modTime time.Time | |
| 38 | 38 | for _, pk := range keys { |
| ... | ... | @@ -137,7 +137,7 @@ func (h *UploadHandler) Validate(s *pssh.SSHServerConnSession) error { | |
| 137 | 137 | return fmt.Errorf("key not found") | |
| 138 | 138 | } | |
| 139 | 139 | ||
| 140 | - | user, err := h.DBPool.FindUserForKey(s.User(), key) | |
| 140 | + | user, err := h.DBPool.FindUserByKey(s.User(), key) | |
| 141 | 141 | if err != nil { | |
| 142 | 142 | return err | |
| 143 | 143 | } |
| ... | ... | @@ -215,7 +215,7 @@ func (h *UploadHandler) ProcessAuthorizedKeys(text []byte, logger *slog.Logger, | |
| 215 | 215 | logger.Info("processing new authorized_keys") | |
| 216 | 216 | dbpool := h.DBPool | |
| 217 | 217 | ||
| 218 | - | curKeysStr, err := dbpool.FindKeysForUser(user) | |
| 218 | + | curKeysStr, err := dbpool.FindKeysByUser(user) | |
| 219 | 219 | if err != nil { | |
| 220 | 220 | return err | |
| 221 | 221 | } |
| ... | ... | @@ -247,7 +247,7 @@ func (h *UploadHandler) ProcessAuthorizedKeys(text []byte, logger *slog.Logger, | |
| 247 | 247 | _, _ = fmt.Fprintf(s.Stderr(), "adding pubkey (%s)\n", key) | |
| 248 | 248 | logger.Info("adding pubkey", "pubkey", key) | |
| 249 | 249 | ||
| 250 | - | err = dbpool.InsertPublicKey(user.ID, key, pk.Comment, nil) | |
| 250 | + | err = dbpool.InsertPublicKey(user.ID, key, pk.Comment) | |
| 251 | 251 | if err != nil { | |
| 252 | 252 | _, _ = fmt.Fprintf(s.Stderr(), "error: could not insert pubkey: %s (%s)\n", err.Error(), key) | |
| 253 | 253 | logger.Error("could not insert pubkey", "err", err.Error()) |
+1,
-1
| ... | ... | @@ -173,7 +173,7 @@ func Middleware(handler *CliHandler) pssh.SSHServerMiddleware { | |
| 173 | 173 | isAdmin := false | |
| 174 | 174 | impersonate := false | |
| 175 | 175 | if user != nil { | |
| 176 | - | isAdmin = handler.DBPool.HasFeatureForUser(user.ID, "admin") | |
| 176 | + | isAdmin = handler.DBPool.HasFeatureByUser(user.ID, "admin") | |
| 177 | 177 | if isAdmin && strings.HasPrefix(sesh.User(), "admin__") { | |
| 178 | 178 | impersonate = true | |
| 179 | 179 | } |
+4,
-4
| ... | ... | @@ -171,7 +171,7 @@ func blogHandler(w http.ResponseWriter, r *http.Request) { | |
| 171 | 171 | var posts []*db.Post | |
| 172 | 172 | var p *db.Paginate[*db.Post] | |
| 173 | 173 | if tag == "" { | |
| 174 | - | p, err = dbpool.FindPostsForUser(pager, user.ID, cfg.Space) | |
| 174 | + | p, err = dbpool.FindPostsByUser(pager, user.ID, cfg.Space) | |
| 175 | 175 | } else { | |
| 176 | 176 | p, err = dbpool.FindUserPostsByTag(pager, tag, user.ID, cfg.Space) | |
| 177 | 177 | } |
| ... | ... | @@ -548,7 +548,7 @@ func readHandler(w http.ResponseWriter, r *http.Request) { | |
| 548 | 548 | var pager *db.Paginate[*db.Post] | |
| 549 | 549 | var err error | |
| 550 | 550 | if tag == "" { | |
| 551 | - | pager, err = dbpool.FindPostsForFeed(&db.Pager{Num: 30, Page: page}, cfg.Space) | |
| 551 | + | pager, err = dbpool.FindPostsByFeed(&db.Pager{Num: 30, Page: page}, cfg.Space) | |
| 552 | 552 | } else { | |
| 553 | 553 | pager, err = dbpool.FindPostsByTag(&db.Pager{Num: 30, Page: page}, tag, cfg.Space) | |
| 554 | 554 | } |
| ... | ... | @@ -639,7 +639,7 @@ func rssBlogHandler(w http.ResponseWriter, r *http.Request) { | |
| 639 | 639 | var posts []*db.Post | |
| 640 | 640 | var p *db.Paginate[*db.Post] | |
| 641 | 641 | if tag == "" { | |
| 642 | - | p, err = dbpool.FindPostsForUser(pager, user.ID, cfg.Space) | |
| 642 | + | p, err = dbpool.FindPostsByUser(pager, user.ID, cfg.Space) | |
| 643 | 643 | } else { | |
| 644 | 644 | p, err = dbpool.FindUserPostsByTag(pager, tag, user.ID, cfg.Space) | |
| 645 | 645 | } |
| ... | ... | @@ -762,7 +762,7 @@ func rssHandler(w http.ResponseWriter, r *http.Request) { | |
| 762 | 762 | logger := shared.GetLogger(r) | |
| 763 | 763 | cfg := shared.GetCfg(r) | |
| 764 | 764 | ||
| 765 | - | pager, err := dbpool.FindPostsForFeed(&db.Pager{Num: 25, Page: 0}, cfg.Space) | |
| 765 | + | pager, err := dbpool.FindPostsByFeed(&db.Pager{Num: 25, Page: 0}, cfg.Space) | |
| 766 | 766 | if err != nil { | |
| 767 | 767 | logger.Error("find all posts", "err", err.Error()) | |
| 768 | 768 | http.Error(w, err.Error(), http.StatusInternalServerError) |
+94,
-94
| ... | ... | @@ -127,29 +127,29 @@ func (p *FeedItemData) Scan(value any) error { | |
| 127 | 127 | } | |
| 128 | 128 | ||
| 129 | 129 | type Post struct { | |
| 130 | - | ID string `json:"id"` | |
| 131 | - | UserID string `json:"user_id"` | |
| 132 | - | Filename string `json:"filename"` | |
| 133 | - | Slug string `json:"slug"` | |
| 134 | - | Title string `json:"title"` | |
| 135 | - | Text string `json:"text"` | |
| 136 | - | Description string `json:"description"` | |
| 137 | - | CreatedAt *time.Time `json:"created_at"` | |
| 138 | - | PublishAt *time.Time `json:"publish_at"` | |
| 139 | - | Username string `json:"username"` | |
| 140 | - | UpdatedAt *time.Time `json:"updated_at"` | |
| 141 | - | ExpiresAt *time.Time `json:"expires_at"` | |
| 142 | - | Hidden bool `json:"hidden"` | |
| 143 | - | Views int `json:"views"` | |
| 144 | - | Space string `json:"space"` | |
| 145 | - | Shasum string `json:"shasum"` | |
| 146 | - | FileSize int `json:"file_size"` | |
| 147 | - | MimeType string `json:"mime_type"` | |
| 148 | - | Data PostData `json:"data"` | |
| 149 | - | Tags []string `json:"tags"` | |
| 130 | + | ID string `json:"id" db:"id"` | |
| 131 | + | UserID string `json:"user_id" db:"user_id"` | |
| 132 | + | Filename string `json:"filename" db:"filename"` | |
| 133 | + | Slug string `json:"slug" db:"slug"` | |
| 134 | + | Title string `json:"title" db:"title"` | |
| 135 | + | Text string `json:"text" db:"text"` | |
| 136 | + | Description string `json:"description" db:"description"` | |
| 137 | + | CreatedAt *time.Time `json:"created_at" db:"created_at"` | |
| 138 | + | PublishAt *time.Time `json:"publish_at" db:"publish_at"` | |
| 139 | + | Username string `json:"username" db:"name"` | |
| 140 | + | UpdatedAt *time.Time `json:"updated_at" db:"updated_at"` | |
| 141 | + | ExpiresAt *time.Time `json:"expires_at" db:"expires_at"` | |
| 142 | + | Hidden bool `json:"hidden" db:"hidden"` | |
| 143 | + | Views int `json:"views" db:"views"` | |
| 144 | + | Space string `json:"space" db:"cur_space"` | |
| 145 | + | Shasum string `json:"shasum" db:"shasum"` | |
| 146 | + | FileSize int `json:"file_size" db:"file_size"` | |
| 147 | + | MimeType string `json:"mime_type" db:"mime_type"` | |
| 148 | + | Data PostData `json:"data" db:"data"` | |
| 149 | + | Tags []string `json:"tags" db:"-"` | |
| 150 | 150 | ||
| 151 | 151 | // computed | |
| 152 | - | IsVirtual bool | |
| 152 | + | IsVirtual bool `db:"-"` | |
| 153 | 153 | } | |
| 154 | 154 | ||
| 155 | 155 | type Paginate[T any] struct { |
| ... | ... | @@ -158,13 +158,13 @@ type Paginate[T any] struct { | |
| 158 | 158 | } | |
| 159 | 159 | ||
| 160 | 160 | type VisitInterval struct { | |
| 161 | - | Interval *time.Time `json:"interval"` | |
| 162 | - | Visitors int `json:"visitors"` | |
| 161 | + | Interval *time.Time `json:"interval" db:"interval"` | |
| 162 | + | Visitors int `json:"visitors" db:"visitors"` | |
| 163 | 163 | } | |
| 164 | 164 | ||
| 165 | 165 | type VisitUrl struct { | |
| 166 | - | Url string `json:"url"` | |
| 167 | - | Count int `json:"count"` | |
| 166 | + | Url string `json:"url" db:"url"` | |
| 167 | + | Count int `json:"count" db:"count"` | |
| 168 | 168 | } | |
| 169 | 169 | ||
| 170 | 170 | type SummaryOpts struct { |
| ... | ... | @@ -184,34 +184,46 @@ type SummaryVisits struct { | |
| 184 | 184 | } | |
| 185 | 185 | ||
| 186 | 186 | type PostAnalytics struct { | |
| 187 | - | ID string | |
| 188 | - | PostID string | |
| 189 | - | Views int | |
| 190 | - | UpdateAt *time.Time | |
| 187 | + | ID string `json:"id" db:"id"` | |
| 188 | + | PostID string `json:"post_id" db:"post_id"` | |
| 189 | + | Views int `json:"views" db:"views"` | |
| 190 | + | UpdateAt *time.Time `json:"updated_at" db:"updated_at"` | |
| 191 | 191 | } | |
| 192 | 192 | ||
| 193 | 193 | type AnalyticsVisits struct { | |
| 194 | - | ID string `json:"id"` | |
| 195 | - | UserID string `json:"user_id"` | |
| 196 | - | ProjectID string `json:"project_id"` | |
| 197 | - | PostID string `json:"post_id"` | |
| 198 | - | Namespace string `json:"namespace"` | |
| 199 | - | Host string `json:"host"` | |
| 200 | - | Path string `json:"path"` | |
| 201 | - | IpAddress string `json:"ip_address"` | |
| 202 | - | UserAgent string `json:"user_agent"` | |
| 203 | - | Referer string `json:"referer"` | |
| 204 | - | Status int `json:"status"` | |
| 205 | - | ContentType string `json:"content_type"` | |
| 194 | + | ID string `json:"id" db:"id"` | |
| 195 | + | UserID string `json:"user_id" db:"user_id"` | |
| 196 | + | ProjectID string `json:"project_id" db:"project_id"` | |
| 197 | + | PostID string `json:"post_id" db:"post_id"` | |
| 198 | + | Namespace string `json:"namespace" db:"namespace"` | |
| 199 | + | Host string `json:"host" db:"host"` | |
| 200 | + | Path string `json:"path" db:"path"` | |
| 201 | + | IpAddress string `json:"ip_address" db:"ip_address"` | |
| 202 | + | UserAgent string `json:"user_agent" db:"user_agent"` | |
| 203 | + | Referer string `json:"referer" db:"referer"` | |
| 204 | + | Status int `json:"status" db:"status"` | |
| 205 | + | ContentType string `json:"content_type" db:"content_type"` | |
| 206 | + | } | |
| 207 | + | ||
| 208 | + | type AccessLogData struct{} | |
| 209 | + | ||
| 210 | + | func (p *AccessLogData) Scan(value any) error { | |
| 211 | + | b, err := tcast(value) | |
| 212 | + | if err != nil { | |
| 213 | + | return err | |
| 214 | + | } | |
| 215 | + | ||
| 216 | + | return json.Unmarshal(b, &p) | |
| 206 | 217 | } | |
| 207 | 218 | ||
| 208 | 219 | type AccessLog struct { | |
| 209 | - | ID string `json:"id"` | |
| 210 | - | UserID string `json:"user_id"` | |
| 211 | - | Service string `json:"service"` | |
| 212 | - | Pubkey string `json:"pubkey"` | |
| 213 | - | Identity string `json:"identity"` | |
| 214 | - | CreatedAt *time.Time `json:"created_at"` | |
| 220 | + | ID string `json:"id" db:"id"` | |
| 221 | + | UserID string `json:"user_id" db:"user_id"` | |
| 222 | + | Service string `json:"service" db:"service"` | |
| 223 | + | Pubkey string `json:"pubkey" db:"pubkey"` | |
| 224 | + | Identity string `json:"identity" db:"identity"` | |
| 225 | + | Data AccessLogData `json:"data" db:"data"` | |
| 226 | + | CreatedAt *time.Time `json:"created_at" db:"created_at"` | |
| 215 | 227 | } | |
| 216 | 228 | ||
| 217 | 229 | type Pager struct { |
| ... | ... | @@ -220,19 +232,20 @@ type Pager struct { | |
| 220 | 232 | } | |
| 221 | 233 | ||
| 222 | 234 | type FeedItem struct { | |
| 223 | - | ID string | |
| 224 | - | PostID string | |
| 225 | - | GUID string | |
| 226 | - | Data FeedItemData | |
| 227 | - | CreatedAt *time.Time | |
| 235 | + | ID string `json:"id" db:"id"` | |
| 236 | + | PostID string `json:"post_id" db:"post_id"` | |
| 237 | + | GUID string `json:"guid" db:"guid"` | |
| 238 | + | Data FeedItemData `json:"data" db:"data"` | |
| 239 | + | CreatedAt *time.Time `json:"created_at" db:"created_at"` | |
| 228 | 240 | } | |
| 229 | 241 | ||
| 230 | 242 | type Token struct { | |
| 231 | - | ID string `json:"id"` | |
| 232 | - | UserID string `json:"user_id"` | |
| 233 | - | Name string `json:"name"` | |
| 234 | - | CreatedAt *time.Time `json:"created_at"` | |
| 235 | - | ExpiresAt *time.Time `json:"expires_at"` | |
| 243 | + | ID string `json:"id" db:"id"` | |
| 244 | + | UserID string `json:"user_id" db:"user_id"` | |
| 245 | + | Name string `json:"name" db:"name"` | |
| 246 | + | Token string `json:"token" db:"token"` | |
| 247 | + | CreatedAt *time.Time `json:"created_at" db:"created_at"` | |
| 248 | + | ExpiresAt *time.Time `json:"expires_at" db:"expires_at"` | |
| 236 | 249 | } | |
| 237 | 250 | ||
| 238 | 251 | type FeatureFlag struct { |
| ... | ... | @@ -352,17 +365,17 @@ type UserServiceStats struct { | |
| 352 | 365 | } | |
| 353 | 366 | ||
| 354 | 367 | type TunsEventLog struct { | |
| 355 | - | ID string `json:"id"` | |
| 356 | - | ServerID string `json:"server_id"` | |
| 357 | - | Time *time.Time `json:"time"` | |
| 358 | - | User string `json:"user"` | |
| 359 | - | UserId string `json:"user_id"` | |
| 360 | - | RemoteAddr string `json:"remote_addr"` | |
| 361 | - | EventType string `json:"event_type"` | |
| 362 | - | TunnelID string `json:"tunnel_id"` | |
| 363 | - | TunnelType string `json:"tunnel_type"` | |
| 364 | - | ConnectionType string `json:"connection_type"` | |
| 365 | - | CreatedAt *time.Time `json:"created_at"` | |
| 368 | + | ID string `json:"id" db:"id"` | |
| 369 | + | ServerID string `json:"server_id" db:"server_id"` | |
| 370 | + | Time *time.Time `json:"time" db:"time"` | |
| 371 | + | User string `json:"user" db:"user"` | |
| 372 | + | UserId string `json:"user_id" db:"user_id"` | |
| 373 | + | RemoteAddr string `json:"remote_addr" db:"remote_addr"` | |
| 374 | + | EventType string `json:"event_type" db:"event_type"` | |
| 375 | + | TunnelID string `json:"tunnel_id" db:"tunnel_id"` | |
| 376 | + | TunnelType string `json:"tunnel_type" db:"tunnel_type"` | |
| 377 | + | ConnectionType string `json:"connection_type" db:"connection_type"` | |
| 378 | + | CreatedAt *time.Time `json:"created_at" db:"created_at"` | |
| 366 | 379 | } | |
| 367 | 380 | ||
| 368 | 381 | var NameValidator = regexp.MustCompile("^[a-zA-Z0-9]{1,50}$") |
| ... | ... | @@ -389,54 +402,41 @@ var DenyList = []string{ | |
| 389 | 402 | ||
| 390 | 403 | type DB interface { | |
| 391 | 404 | RegisterUser(name, pubkey, comment string) (*User, error) | |
| 392 | - | RemoveUsers(userIDs []string) error | |
| 393 | 405 | UpdatePublicKey(pubkeyID, name string) (*PublicKey, error) | |
| 394 | - | InsertPublicKey(userID, pubkey, name string, tx *sql.Tx) error | |
| 395 | - | FindPublicKeyForKey(pubkey string) (*PublicKey, error) | |
| 396 | - | FindPublicKey(pubkeyID string) (*PublicKey, error) | |
| 397 | - | FindKeysForUser(user *User) ([]*PublicKey, error) | |
| 406 | + | InsertPublicKey(userID, pubkey, name string) error | |
| 407 | + | FindKeysByUser(user *User) ([]*PublicKey, error) | |
| 398 | 408 | RemoveKeys(pubkeyIDs []string) error | |
| 399 | 409 | ||
| 400 | 410 | FindUsers() ([]*User, error) | |
| 401 | 411 | FindUserByName(name string) (*User, error) | |
| 402 | - | FindUserForNameAndKey(name string, pubkey string) (*User, error) | |
| 403 | - | FindUserForKey(name string, pubkey string) (*User, error) | |
| 412 | + | FindUserByKey(name string, pubkey string) (*User, error) | |
| 404 | 413 | FindUserByPubkey(pubkey string) (*User, error) | |
| 405 | 414 | FindUser(userID string) (*User, error) | |
| 406 | - | ValidateName(name string) (bool, error) | |
| 407 | - | SetUserName(userID string, name string) error | |
| 408 | 415 | ||
| 409 | - | FindUserForToken(token string) (*User, error) | |
| 410 | - | FindTokensForUser(userID string) ([]*Token, error) | |
| 416 | + | FindUserByToken(token string) (*User, error) | |
| 417 | + | FindTokensByUser(userID string) ([]*Token, error) | |
| 411 | 418 | InsertToken(userID, name string) (string, error) | |
| 412 | 419 | UpsertToken(userID, name string) (string, error) | |
| 413 | - | FindTokenByName(userID, name string) (string, error) | |
| 414 | 420 | RemoveToken(tokenID string) error | |
| 415 | 421 | ||
| 416 | 422 | FindPosts() ([]*Post, error) | |
| 417 | 423 | FindPost(postID string) (*Post, error) | |
| 418 | - | FindPostsForUser(pager *Pager, userID string, space string) (*Paginate[*Post], error) | |
| 419 | - | FindAllPostsForUser(userID string, space string) ([]*Post, error) | |
| 424 | + | FindPostsByUser(pager *Pager, userID string, space string) (*Paginate[*Post], error) | |
| 425 | + | FindAllPostsByUser(userID string, space string) ([]*Post, error) | |
| 420 | 426 | FindUsersWithPost(space string) ([]*User, error) | |
| 421 | - | FindPostsBeforeDate(date *time.Time, space string) ([]*Post, error) | |
| 422 | 427 | FindExpiredPosts(space string) ([]*Post, error) | |
| 423 | - | FindUpdatedPostsForUser(userID string, space string) ([]*Post, error) | |
| 424 | 428 | FindPostWithFilename(filename string, userID string, space string) (*Post, error) | |
| 425 | 429 | FindPostWithSlug(slug string, userID string, space string) (*Post, error) | |
| 426 | - | FindPostsForFeed(pager *Pager, space string) (*Paginate[*Post], error) | |
| 427 | - | FindAllUpdatedPosts(pager *Pager, space string) (*Paginate[*Post], error) | |
| 430 | + | FindPostsByFeed(pager *Pager, space string) (*Paginate[*Post], error) | |
| 428 | 431 | InsertPost(post *Post) (*Post, error) | |
| 429 | 432 | UpdatePost(post *Post) (*Post, error) | |
| 430 | 433 | RemovePosts(postIDs []string) error | |
| 431 | 434 | ||
| 432 | - | ReplaceTagsForPost(tags []string, postID string) error | |
| 435 | + | ReplaceTagsByPost(tags []string, postID string) error | |
| 433 | 436 | FindUserPostsByTag(pager *Pager, tag, userID, space string) (*Paginate[*Post], error) | |
| 434 | 437 | FindPostsByTag(pager *Pager, tag, space string) (*Paginate[*Post], error) | |
| 435 | 438 | FindPopularTags(space string) ([]string, error) | |
| 436 | - | FindTagsForPost(postID string) ([]string, error) | |
| 437 | - | FindTagsForUser(userID string, space string) ([]string, error) | |
| 438 | - | ||
| 439 | - | ReplaceAliasesForPost(aliases []string, postID string) error | |
| 439 | + | ReplaceAliasesByPost(aliases []string, postID string) error | |
| 440 | 440 | ||
| 441 | 441 | InsertVisit(view *AnalyticsVisits) error | |
| 442 | 442 | VisitSummary(opts *SummaryOpts) (*SummaryVisits, error) |
| ... | ... | @@ -445,9 +445,9 @@ type DB interface { | |
| 445 | 445 | ||
| 446 | 446 | AddPicoPlusUser(username, email, paymentType, txId string) error | |
| 447 | 447 | FindFeature(userID string, feature string) (*FeatureFlag, error) | |
| 448 | - | FindFeaturesForUser(userID string) ([]*FeatureFlag, error) | |
| 449 | - | HasFeatureForUser(userID string, feature string) bool | |
| 450 | - | FindTotalSizeForUser(userID string) (int, error) | |
| 448 | + | FindFeaturesByUser(userID string) ([]*FeatureFlag, error) | |
| 449 | + | HasFeatureByUser(userID string, feature string) bool | |
| 450 | + | ||
| 451 | 451 | InsertFeature(userID, name string, expiresAt time.Time) (*FeatureFlag, error) | |
| 452 | 452 | RemoveFeature(userID, names string) error | |
| 453 | 453 |
+299,
-813
| ... | ... | @@ -1,7 +1,6 @@ | |
| 1 | 1 | package postgres | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "context" | |
| 5 | 4 | "database/sql" | |
| 6 | 5 | "errors" | |
| 7 | 6 | "fmt" |
| ... | ... | @@ -12,6 +11,7 @@ import ( | |
| 12 | 11 | ||
| 13 | 12 | "slices" | |
| 14 | 13 | ||
| 14 | + | "github.com/jmoiron/sqlx" | |
| 15 | 15 | _ "github.com/lib/pq" | |
| 16 | 16 | "github.com/picosh/pico/pkg/db" | |
| 17 | 17 | "github.com/picosh/utils" |
| ... | ... | @@ -23,275 +23,16 @@ var SelectPost = ` | |
| 23 | 23 | posts.id, user_id, app_users.name, filename, slug, title, text, description, | |
| 24 | 24 | posts.created_at, publish_at, posts.updated_at, hidden, file_size, mime_type, shasum, data, expires_at, views` | |
| 25 | 25 | ||
| 26 | - | var ( | |
| 27 | - | sqlSelectPosts = fmt.Sprintf(` | |
| 28 | - | SELECT %s | |
| 29 | - | FROM posts | |
| 30 | - | LEFT JOIN app_users ON app_users.id = posts.user_id`, SelectPost) | |
| 31 | - | ||
| 32 | - | sqlSelectPostsBeforeDate = fmt.Sprintf(` | |
| 33 | - | SELECT %s | |
| 34 | - | FROM posts | |
| 35 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 36 | - | WHERE publish_at::date <= $1 AND cur_space = $2`, SelectPost) | |
| 37 | - | ||
| 38 | - | sqlSelectPostWithFilename = fmt.Sprintf(` | |
| 39 | - | SELECT %s, STRING_AGG(coalesce(post_tags.name, ''), ',') tags | |
| 40 | - | FROM posts | |
| 41 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 42 | - | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 43 | - | WHERE filename = $1 AND user_id = $2 AND cur_space = $3 | |
| 44 | - | GROUP BY %s`, SelectPost, SelectPost) | |
| 45 | - | ||
| 46 | - | sqlSelectPostWithSlug = fmt.Sprintf(` | |
| 47 | - | SELECT %s, STRING_AGG(coalesce(post_tags.name, ''), ',') tags | |
| 48 | - | FROM posts | |
| 49 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 50 | - | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 51 | - | WHERE slug = $1 AND user_id = $2 AND cur_space = $3 | |
| 52 | - | GROUP BY %s`, SelectPost, SelectPost) | |
| 53 | - | ||
| 54 | - | sqlSelectPost = fmt.Sprintf(` | |
| 55 | - | SELECT %s | |
| 56 | - | FROM posts | |
| 57 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 58 | - | WHERE posts.id = $1`, SelectPost) | |
| 59 | - | ||
| 60 | - | sqlSelectUpdatedPostsForUser = fmt.Sprintf(` | |
| 61 | - | SELECT %s | |
| 62 | - | FROM posts | |
| 63 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 64 | - | WHERE user_id = $1 AND publish_at::date <= CURRENT_DATE AND cur_space = $2 | |
| 65 | - | ORDER BY posts.updated_at DESC`, SelectPost) | |
| 66 | - | ||
| 67 | - | sqlSelectExpiredPosts = fmt.Sprintf(` | |
| 68 | - | SELECT %s | |
| 69 | - | FROM posts | |
| 70 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 71 | - | WHERE | |
| 72 | - | cur_space = $1 AND | |
| 73 | - | expires_at <= now(); | |
| 74 | - | `, SelectPost) | |
| 75 | - | ||
| 76 | - | sqlSelectPostsForUser = fmt.Sprintf(` | |
| 77 | - | SELECT %s, STRING_AGG(coalesce(post_tags.name, ''), ',') tags | |
| 78 | - | FROM posts | |
| 79 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 80 | - | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 81 | - | WHERE | |
| 82 | - | hidden = FALSE AND | |
| 83 | - | user_id = $1 AND | |
| 84 | - | publish_at::date <= CURRENT_DATE AND | |
| 85 | - | cur_space = $2 | |
| 86 | - | GROUP BY %s | |
| 87 | - | ORDER BY publish_at DESC, slug DESC | |
| 88 | - | LIMIT $3 OFFSET $4`, SelectPost, SelectPost) | |
| 89 | - | ||
| 90 | - | sqlSelectAllPostsForUser = fmt.Sprintf(` | |
| 91 | - | SELECT %s | |
| 92 | - | FROM posts | |
| 93 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 94 | - | WHERE | |
| 95 | - | user_id = $1 AND | |
| 96 | - | cur_space = $2 | |
| 97 | - | ORDER BY publish_at DESC`, SelectPost) | |
| 98 | - | ||
| 99 | - | sqlSelectPostsByTag = ` | |
| 100 | - | SELECT | |
| 101 | - | posts.id, | |
| 102 | - | user_id, | |
| 103 | - | filename, | |
| 104 | - | slug, | |
| 105 | - | title, | |
| 106 | - | text, | |
| 107 | - | description, | |
| 108 | - | publish_at, | |
| 109 | - | app_users.name as username, | |
| 110 | - | posts.updated_at, | |
| 111 | - | posts.mime_type | |
| 112 | - | FROM posts | |
| 113 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 114 | - | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 115 | - | WHERE | |
| 116 | - | post_tags.name = $3 AND | |
| 117 | - | publish_at::date <= CURRENT_DATE AND | |
| 118 | - | cur_space = $4 | |
| 119 | - | ORDER BY publish_at DESC | |
| 120 | - | LIMIT $1 OFFSET $2` | |
| 121 | - | ||
| 122 | - | sqlSelectUserPostsByTag = fmt.Sprintf(` | |
| 123 | - | SELECT %s | |
| 124 | - | FROM posts | |
| 125 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 126 | - | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 127 | - | WHERE | |
| 128 | - | hidden = FALSE AND | |
| 129 | - | user_id = $1 AND | |
| 130 | - | (post_tags.name = $2 OR hidden = true) AND | |
| 131 | - | publish_at::date <= CURRENT_DATE AND | |
| 132 | - | cur_space = $3 | |
| 133 | - | ORDER BY publish_at DESC | |
| 134 | - | LIMIT $4 OFFSET $5`, SelectPost) | |
| 135 | - | ) | |
| 136 | - | ||
| 137 | - | const ( | |
| 138 | - | sqlSelectPublicKey = `SELECT id, user_id, name, public_key, created_at FROM public_keys WHERE public_key = $1` | |
| 139 | - | sqlSelectPublicKeys = `SELECT id, user_id, name, public_key, created_at FROM public_keys WHERE user_id = $1 ORDER BY created_at ASC` | |
| 140 | - | sqlSelectUser = `SELECT id, name, created_at FROM app_users WHERE id = $1` | |
| 141 | - | sqlSelectUserForName = `SELECT id, name, created_at FROM app_users WHERE name = $1` | |
| 142 | - | sqlSelectUserForNameAndKey = `SELECT app_users.id, app_users.name, app_users.created_at, public_keys.id as pk_id, public_keys.public_key, public_keys.created_at as pk_created_at FROM app_users LEFT JOIN public_keys ON public_keys.user_id = app_users.id WHERE app_users.name = $1 AND public_keys.public_key = $2` | |
| 143 | - | sqlSelectUsers = `SELECT id, name, created_at FROM app_users ORDER BY name ASC` | |
| 144 | - | ||
| 145 | - | sqlSelectUserForToken = ` | |
| 146 | - | SELECT app_users.id, app_users.name, app_users.created_at | |
| 147 | - | FROM app_users | |
| 148 | - | LEFT JOIN tokens ON tokens.user_id = app_users.id | |
| 149 | - | WHERE tokens.token = $1 AND tokens.expires_at > NOW()` | |
| 150 | - | sqlInsertToken = `INSERT INTO tokens (user_id, name) VALUES($1, $2) RETURNING token;` | |
| 151 | - | sqlRemoveToken = `DELETE FROM tokens WHERE id = $1` | |
| 152 | - | sqlSelectTokensForUser = `SELECT id, user_id, name, created_at, expires_at FROM tokens WHERE user_id = $1` | |
| 153 | - | sqlSelectTokenByNameForUser = `SELECT token FROM tokens WHERE user_id = $1 AND name = $2` | |
| 154 | - | ||
| 155 | - | sqlSelectFeatureForUser = `SELECT id, user_id, payment_history_id, name, data, created_at, expires_at FROM feature_flags WHERE user_id = $1 AND name = $2 ORDER BY expires_at DESC LIMIT 1` | |
| 156 | - | sqlSelectSizeForUser = `SELECT COALESCE(sum(file_size), 0) FROM posts WHERE user_id = $1` | |
| 157 | - | ||
| 158 | - | sqlSelectPostIdByAliasSlug = `SELECT post_id FROM post_aliases WHERE slug = $1` | |
| 159 | - | sqlSelectTagPostCount = ` | |
| 160 | - | SELECT count(posts.id) | |
| 161 | - | FROM posts | |
| 162 | - | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 163 | - | WHERE hidden = FALSE AND cur_space=$1 and post_tags.name = $2` | |
| 164 | - | sqlSelectPostCount = `SELECT count(id) FROM posts WHERE hidden = FALSE AND cur_space=$1` | |
| 165 | - | sqlSelectAllUpdatedPosts = ` | |
| 166 | - | SELECT | |
| 167 | - | posts.id, | |
| 168 | - | user_id, | |
| 169 | - | filename, | |
| 170 | - | slug, | |
| 171 | - | title, | |
| 172 | - | text, | |
| 173 | - | description, | |
| 174 | - | publish_at, | |
| 175 | - | app_users.name as username, | |
| 176 | - | posts.updated_at, | |
| 177 | - | posts.mime_type | |
| 178 | - | FROM posts | |
| 179 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 180 | - | WHERE hidden = FALSE AND publish_at::date <= CURRENT_DATE AND cur_space = $3 | |
| 181 | - | ORDER BY updated_at DESC | |
| 182 | - | LIMIT $1 OFFSET $2` | |
| 183 | - | // add some users to deny list since they are robogenerating a bunch of posts | |
| 184 | - | // per day and are creating a lot of noise. | |
| 185 | - | sqlSelectPostsByRank = ` | |
| 186 | - | SELECT * | |
| 187 | - | FROM ( | |
| 188 | - | SELECT DISTINCT ON (posts.user_id) | |
| 189 | - | posts.id, | |
| 190 | - | posts.user_id, | |
| 191 | - | posts.filename, | |
| 192 | - | posts.slug, | |
| 193 | - | posts.title, | |
| 194 | - | posts.text, | |
| 195 | - | posts.description, | |
| 196 | - | posts.publish_at, | |
| 197 | - | app_users.name AS username, | |
| 198 | - | posts.updated_at, | |
| 199 | - | posts.mime_type | |
| 200 | - | FROM posts | |
| 201 | - | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 202 | - | WHERE | |
| 203 | - | hidden = FALSE | |
| 204 | - | AND publish_at::date <= CURRENT_DATE | |
| 205 | - | AND cur_space = $3 | |
| 206 | - | ORDER BY posts.user_id, publish_at DESC | |
| 207 | - | ) AS latest_posts | |
| 208 | - | ORDER BY publish_at DESC | |
| 209 | - | LIMIT $1 OFFSET $2` | |
| 210 | - | ||
| 211 | - | sqlSelectPopularTags = ` | |
| 212 | - | SELECT name, count(post_id) as "tally" | |
| 213 | - | FROM post_tags | |
| 214 | - | LEFT JOIN posts ON posts.id = post_id | |
| 215 | - | WHERE posts.cur_space = $1 | |
| 216 | - | GROUP BY name | |
| 217 | - | ORDER BY tally DESC | |
| 218 | - | LIMIT 5` | |
| 219 | - | sqlSelectTagsForUser = ` | |
| 220 | - | SELECT name | |
| 221 | - | FROM post_tags | |
| 222 | - | LEFT JOIN posts ON posts.id = post_id | |
| 223 | - | WHERE posts.user_id = $1 AND posts.cur_space = $2 | |
| 224 | - | GROUP BY name` | |
| 225 | - | sqlSelectTagsForPost = `SELECT name FROM post_tags WHERE post_id=$1` | |
| 226 | - | sqlSelectFeedItemsByPost = `SELECT id, post_id, guid, data, created_at FROM feed_items WHERE post_id=$1` | |
| 227 | - | ||
| 228 | - | sqlInsertPost = ` | |
| 229 | - | INSERT INTO posts | |
| 230 | - | (user_id, filename, slug, title, text, description, publish_at, hidden, cur_space, | |
| 231 | - | file_size, mime_type, shasum, data, expires_at, updated_at) | |
| 232 | - | VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) | |
| 233 | - | RETURNING id` | |
| 234 | - | sqlInsertUser = `INSERT INTO app_users (name) VALUES($1) returning id` | |
| 235 | - | sqlInsertTag = `INSERT INTO post_tags (post_id, name) VALUES($1, $2) RETURNING id;` | |
| 236 | - | sqlInsertAliases = `INSERT INTO post_aliases (post_id, slug) VALUES($1, $2) RETURNING id;` | |
| 237 | - | sqlInsertFeedItems = `INSERT INTO feed_items (post_id, guid, data) VALUES ($1, $2, $3) RETURNING id;` | |
| 238 | - | ||
| 239 | - | sqlUpdatePost = ` | |
| 240 | - | UPDATE posts | |
| 241 | - | SET slug = $1, title = $2, text = $3, description = $4, updated_at = $5, publish_at = $6, | |
| 242 | - | file_size = $7, shasum = $8, data = $9, hidden = $11, expires_at = $12 | |
| 243 | - | WHERE id = $10` | |
| 244 | - | sqlUpdateUserName = `UPDATE app_users SET name = $1 WHERE id = $2` | |
| 245 | - | ||
| 246 | - | sqlRemoveAliasesByPost = `DELETE FROM post_aliases WHERE post_id = $1` | |
| 247 | - | sqlRemoveTagsByPost = `DELETE FROM post_tags WHERE post_id = $1` | |
| 248 | - | sqlRemovePosts = `DELETE FROM posts WHERE id = ANY($1::uuid[])` | |
| 249 | - | sqlRemoveKeys = `DELETE FROM public_keys WHERE id = ANY($1::uuid[])` | |
| 250 | - | sqlRemoveUsers = `DELETE FROM app_users WHERE id = ANY($1::uuid[])` | |
| 251 | - | ||
| 252 | - | sqlInsertProject = `INSERT INTO projects (user_id, name, project_dir) VALUES ($1, $2, $3) RETURNING id;` | |
| 253 | - | sqlUpdateProject = `UPDATE projects SET updated_at = $3 WHERE user_id = $1 AND name = $2;` | |
| 254 | - | sqlFindProjectByName = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name = $2;` | |
| 255 | - | ) | |
| 256 | - | ||
| 257 | 26 | type PsqlDB struct { | |
| 258 | 27 | Logger *slog.Logger | |
| 259 | - | Db *sql.DB | |
| 28 | + | Db *sqlx.DB | |
| 260 | 29 | } | |
| 261 | 30 | ||
| 262 | 31 | type RowScanner interface { | |
| 263 | 32 | Scan(dest ...any) error | |
| 264 | 33 | } | |
| 265 | 34 | ||
| 266 | - | func CreatePostFromRow(r RowScanner) (*db.Post, error) { | |
| 267 | - | post := &db.Post{} | |
| 268 | - | err := r.Scan( | |
| 269 | - | &post.ID, | |
| 270 | - | &post.UserID, | |
| 271 | - | &post.Username, | |
| 272 | - | &post.Filename, | |
| 273 | - | &post.Slug, | |
| 274 | - | &post.Title, | |
| 275 | - | &post.Text, | |
| 276 | - | &post.Description, | |
| 277 | - | &post.CreatedAt, | |
| 278 | - | &post.PublishAt, | |
| 279 | - | &post.UpdatedAt, | |
| 280 | - | &post.Hidden, | |
| 281 | - | &post.FileSize, | |
| 282 | - | &post.MimeType, | |
| 283 | - | &post.Shasum, | |
| 284 | - | &post.Data, | |
| 285 | - | &post.ExpiresAt, | |
| 286 | - | &post.Views, | |
| 287 | - | ) | |
| 288 | - | if err != nil { | |
| 289 | - | return nil, err | |
| 290 | - | } | |
| 291 | - | return post, nil | |
| 292 | - | } | |
| 293 | - | ||
| 294 | - | func CreatePostWithTagsFromRow(r RowScanner) (*db.Post, error) { | |
| 35 | + | func CreatePostWithTagsByRow(r RowScanner) (*db.Post, error) { | |
| 295 | 36 | post := &db.Post{} | |
| 296 | 37 | tagStr := "" | |
| 297 | 38 | err := r.Scan( |
| ... | ... | @@ -338,7 +79,7 @@ func NewDB(databaseUrl string, logger *slog.Logger) *PsqlDB { | |
| 338 | 79 | } | |
| 339 | 80 | d.Logger.Info("Connecting to postgres", "databaseUrl", databaseUrl) | |
| 340 | 81 | ||
| 341 | - | db, err := sql.Open("postgres", databaseUrl) | |
| 82 | + | db, err := sqlx.Connect("postgres", databaseUrl) | |
| 342 | 83 | if err != nil { | |
| 343 | 84 | d.Logger.Error(err.Error()) | |
| 344 | 85 | } |
| ... | ... | @@ -348,35 +89,26 @@ func NewDB(databaseUrl string, logger *slog.Logger) *PsqlDB { | |
| 348 | 89 | ||
| 349 | 90 | func (me *PsqlDB) RegisterUser(username, pubkey, comment string) (*db.User, error) { | |
| 350 | 91 | lowerName := strings.ToLower(username) | |
| 351 | - | valid, err := me.ValidateName(lowerName) | |
| 92 | + | valid, err := me.validateName(lowerName) | |
| 352 | 93 | if !valid { | |
| 353 | 94 | return nil, err | |
| 354 | 95 | } | |
| 355 | 96 | ||
| 356 | - | ctx := context.Background() | |
| 357 | - | tx, err := me.Db.BeginTx(ctx, nil) | |
| 358 | - | if err != nil { | |
| 359 | - | return nil, err | |
| 360 | - | } | |
| 361 | - | defer func() { | |
| 362 | - | err = tx.Rollback() | |
| 363 | - | }() | |
| 364 | - | ||
| 365 | - | stmt, err := tx.Prepare(sqlInsertUser) | |
| 97 | + | tx, err := me.Db.Beginx() | |
| 366 | 98 | if err != nil { | |
| 367 | 99 | return nil, err | |
| 368 | 100 | } | |
| 369 | 101 | defer func() { | |
| 370 | - | _ = stmt.Close() | |
| 102 | + | _ = tx.Rollback() | |
| 371 | 103 | }() | |
| 372 | 104 | ||
| 373 | 105 | var id string | |
| 374 | - | err = stmt.QueryRow(lowerName).Scan(&id) | |
| 106 | + | err = tx.QueryRow(`INSERT INTO app_users (name) VALUES($1) returning id`, lowerName).Scan(&id) | |
| 375 | 107 | if err != nil { | |
| 376 | 108 | return nil, err | |
| 377 | 109 | } | |
| 378 | 110 | ||
| 379 | - | err = me.InsertPublicKey(id, pubkey, comment, tx) | |
| 111 | + | err = me.insertPublicKeyWithTx(id, pubkey, comment, tx) | |
| 380 | 112 | if err != nil { | |
| 381 | 113 | return nil, err | |
| 382 | 114 | } |
| ... | ... | @@ -386,36 +118,31 @@ func (me *PsqlDB) RegisterUser(username, pubkey, comment string) (*db.User, erro | |
| 386 | 118 | return nil, err | |
| 387 | 119 | } | |
| 388 | 120 | ||
| 389 | - | return me.FindUserForKey(username, pubkey) | |
| 121 | + | return me.FindUserByKey(username, pubkey) | |
| 390 | 122 | } | |
| 391 | 123 | ||
| 392 | - | func (me *PsqlDB) RemoveUsers(userIDs []string) error { | |
| 393 | - | param := "{" + strings.Join(userIDs, ",") + "}" | |
| 394 | - | _, err := me.Db.Exec(sqlRemoveUsers, param) | |
| 124 | + | func (me *PsqlDB) insertPublicKeyWithTx(userID, key, name string, tx *sqlx.Tx) error { | |
| 125 | + | pk, _ := me.findPublicKeyByKey(key) | |
| 126 | + | if pk != nil { | |
| 127 | + | return db.ErrPublicKeyTaken | |
| 128 | + | } | |
| 129 | + | query := `INSERT INTO public_keys (user_id, public_key, name) VALUES ($1, $2, $3)` | |
| 130 | + | _, err := tx.Exec(query, userID, key, name) | |
| 395 | 131 | return err | |
| 396 | 132 | } | |
| 397 | 133 | ||
| 398 | - | func (me *PsqlDB) InsertPublicKey(userID, key, name string, tx *sql.Tx) error { | |
| 399 | - | pk, _ := me.FindPublicKeyForKey(key) | |
| 134 | + | func (me *PsqlDB) InsertPublicKey(userID, key, name string) error { | |
| 135 | + | pk, _ := me.findPublicKeyByKey(key) | |
| 400 | 136 | if pk != nil { | |
| 401 | 137 | return db.ErrPublicKeyTaken | |
| 402 | 138 | } | |
| 403 | 139 | query := `INSERT INTO public_keys (user_id, public_key, name) VALUES ($1, $2, $3)` | |
| 404 | - | var err error | |
| 405 | - | if tx != nil { | |
| 406 | - | _, err = tx.Exec(query, userID, key, name) | |
| 407 | - | } else { | |
| 408 | - | _, err = me.Db.Exec(query, userID, key, name) | |
| 409 | - | } | |
| 410 | - | if err != nil { | |
| 411 | - | return err | |
| 412 | - | } | |
| 413 | - | ||
| 414 | - | return nil | |
| 140 | + | _, err := me.Db.Exec(query, userID, key, name) | |
| 141 | + | return err | |
| 415 | 142 | } | |
| 416 | 143 | ||
| 417 | 144 | func (me *PsqlDB) UpdatePublicKey(pubkeyID, name string) (*db.PublicKey, error) { | |
| 418 | - | pk, err := me.FindPublicKey(pubkeyID) | |
| 145 | + | pk, err := me.findPublicKey(pubkeyID) | |
| 419 | 146 | if err != nil { | |
| 420 | 147 | return nil, err | |
| 421 | 148 | } |
| ... | ... | @@ -426,19 +153,20 @@ func (me *PsqlDB) UpdatePublicKey(pubkeyID, name string) (*db.PublicKey, error) | |
| 426 | 153 | return nil, err | |
| 427 | 154 | } | |
| 428 | 155 | ||
| 429 | - | pk, err = me.FindPublicKey(pubkeyID) | |
| 156 | + | pk, err = me.findPublicKey(pubkeyID) | |
| 430 | 157 | if err != nil { | |
| 431 | 158 | return nil, err | |
| 432 | 159 | } | |
| 433 | 160 | return pk, nil | |
| 434 | 161 | } | |
| 435 | 162 | ||
| 436 | - | func (me *PsqlDB) FindPublicKeyForKey(key string) (*db.PublicKey, error) { | |
| 163 | + | func (me *PsqlDB) findPublicKeyByKey(key string) (*db.PublicKey, error) { | |
| 437 | 164 | var keys []*db.PublicKey | |
| 438 | - | rs, err := me.Db.Query(sqlSelectPublicKey, key) | |
| 165 | + | rs, err := me.Db.Queryx(`SELECT id, user_id, name, public_key, created_at FROM public_keys WHERE public_key = $1`, key) | |
| 439 | 166 | if err != nil { | |
| 440 | 167 | return nil, err | |
| 441 | 168 | } | |
| 169 | + | defer func() { _ = rs.Close() }() | |
| 442 | 170 | ||
| 443 | 171 | for rs.Next() { | |
| 444 | 172 | pk := &db.PublicKey{} |
| ... | ... | @@ -458,7 +186,7 @@ func (me *PsqlDB) FindPublicKeyForKey(key string) (*db.PublicKey, error) { | |
| 458 | 186 | return nil, fmt.Errorf("pubkey not found in our database: [%s]", key) | |
| 459 | 187 | } | |
| 460 | 188 | ||
| 461 | - | // When we run PublicKeyForKey and there are multiple public keys returned from the database | |
| 189 | + | // When we run PublicKeyByKey and there are multiple public keys returned from the database | |
| 462 | 190 | // that should mean that we don't have the correct username for this public key. | |
| 463 | 191 | // When that happens we need to reject the authentication and ask the user to provide the correct | |
| 464 | 192 | // username when using ssh. So instead of `ssh <domain>` it should be `ssh user@<domain>` |
| ... | ... | @@ -469,86 +197,33 @@ func (me *PsqlDB) FindPublicKeyForKey(key string) (*db.PublicKey, error) { | |
| 469 | 197 | return keys[0], nil | |
| 470 | 198 | } | |
| 471 | 199 | ||
| 472 | - | func (me *PsqlDB) FindPublicKey(pubkeyID string) (*db.PublicKey, error) { | |
| 473 | - | var keys []*db.PublicKey | |
| 474 | - | rs, err := me.Db.Query(`SELECT id, user_id, name, public_key, created_at FROM public_keys WHERE id = $1`, pubkeyID) | |
| 200 | + | func (me *PsqlDB) findPublicKey(pubkeyID string) (*db.PublicKey, error) { | |
| 201 | + | pk := &db.PublicKey{} | |
| 202 | + | err := me.Db.Get(pk, `SELECT * FROM public_keys WHERE id = $1`, pubkeyID) | |
| 475 | 203 | if err != nil { | |
| 476 | 204 | return nil, err | |
| 477 | 205 | } | |
| 478 | - | ||
| 479 | - | for rs.Next() { | |
| 480 | - | pk := &db.PublicKey{} | |
| 481 | - | err := rs.Scan(&pk.ID, &pk.UserID, &pk.Name, &pk.Key, &pk.CreatedAt) | |
| 482 | - | if err != nil { | |
| 483 | - | return nil, err | |
| 484 | - | } | |
| 485 | - | ||
| 486 | - | keys = append(keys, pk) | |
| 487 | - | } | |
| 488 | - | ||
| 489 | - | if rs.Err() != nil { | |
| 490 | - | return nil, rs.Err() | |
| 491 | - | } | |
| 492 | - | ||
| 493 | - | if len(keys) == 0 { | |
| 494 | - | return nil, errors.New("no public keys found for key provided") | |
| 495 | - | } | |
| 496 | - | ||
| 497 | - | return keys[0], nil | |
| 206 | + | return pk, nil | |
| 498 | 207 | } | |
| 499 | 208 | ||
| 500 | - | func (me *PsqlDB) FindKeysForUser(user *db.User) ([]*db.PublicKey, error) { | |
| 209 | + | func (me *PsqlDB) FindKeysByUser(user *db.User) ([]*db.PublicKey, error) { | |
| 501 | 210 | var keys []*db.PublicKey | |
| 502 | - | rs, err := me.Db.Query(sqlSelectPublicKeys, user.ID) | |
| 211 | + | err := me.Db.Select(&keys, `SELECT * FROM public_keys WHERE user_id = $1 ORDER BY created_at ASC`, user.ID) | |
| 503 | 212 | if err != nil { | |
| 504 | - | return keys, err | |
| 505 | - | } | |
| 506 | - | for rs.Next() { | |
| 507 | - | pk := &db.PublicKey{} | |
| 508 | - | err := rs.Scan(&pk.ID, &pk.UserID, &pk.Name, &pk.Key, &pk.CreatedAt) | |
| 509 | - | if err != nil { | |
| 510 | - | return keys, err | |
| 511 | - | } | |
| 512 | - | ||
| 513 | - | keys = append(keys, pk) | |
| 514 | - | } | |
| 515 | - | if rs.Err() != nil { | |
| 516 | - | return keys, rs.Err() | |
| 213 | + | return nil, err | |
| 517 | 214 | } | |
| 518 | 215 | return keys, nil | |
| 519 | 216 | } | |
| 520 | 217 | ||
| 521 | 218 | func (me *PsqlDB) RemoveKeys(keyIDs []string) error { | |
| 522 | 219 | param := "{" + strings.Join(keyIDs, ",") + "}" | |
| 523 | - | _, err := me.Db.Exec(sqlRemoveKeys, param) | |
| 220 | + | _, err := me.Db.Exec(`DELETE FROM public_keys WHERE id = ANY($1::uuid[])`, param) | |
| 524 | 221 | return err | |
| 525 | 222 | } | |
| 526 | 223 | ||
| 527 | - | func (me *PsqlDB) FindPostsBeforeDate(date *time.Time, space string) ([]*db.Post, error) { | |
| 528 | - | // now := time.Now() | |
| 529 | - | // expired := now.AddDate(0, 0, -3) | |
| 530 | - | var posts []*db.Post | |
| 531 | - | rs, err := me.Db.Query(sqlSelectPostsBeforeDate, date, space) | |
| 532 | - | if err != nil { | |
| 533 | - | return posts, err | |
| 534 | - | } | |
| 535 | - | for rs.Next() { | |
| 536 | - | post, err := CreatePostFromRow(rs) | |
| 537 | - | if err != nil { | |
| 538 | - | return nil, err | |
| 539 | - | } | |
| 540 | - | ||
| 541 | - | posts = append(posts, post) | |
| 542 | - | } | |
| 543 | - | if rs.Err() != nil { | |
| 544 | - | return posts, rs.Err() | |
| 545 | - | } | |
| 546 | - | return posts, nil | |
| 547 | - | } | |
| 548 | - | ||
| 549 | 224 | func (me *PsqlDB) FindUsersWithPost(space string) ([]*db.User, error) { | |
| 550 | 225 | var users []*db.User | |
| 551 | - | rs, err := me.Db.Query( | |
| 226 | + | rs, err := me.Db.Queryx( | |
| 552 | 227 | `SELECT u.id, u.name, u.created_at | |
| 553 | 228 | FROM app_users u | |
| 554 | 229 | INNER JOIN posts ON u.id=posts.user_id |
| ... | ... | @@ -559,6 +234,7 @@ func (me *PsqlDB) FindUsersWithPost(space string) ([]*db.User, error) { | |
| 559 | 234 | if err != nil { | |
| 560 | 235 | return users, err | |
| 561 | 236 | } | |
| 237 | + | defer func() { _ = rs.Close() }() | |
| 562 | 238 | for rs.Next() { | |
| 563 | 239 | var name sql.NullString | |
| 564 | 240 | user := &db.User{} |
| ... | ... | @@ -580,9 +256,9 @@ func (me *PsqlDB) FindUsersWithPost(space string) ([]*db.User, error) { | |
| 580 | 256 | return users, nil | |
| 581 | 257 | } | |
| 582 | 258 | ||
| 583 | - | func (me *PsqlDB) FindUserForKey(username string, key string) (*db.User, error) { | |
| 259 | + | func (me *PsqlDB) FindUserByKey(username string, key string) (*db.User, error) { | |
| 584 | 260 | me.Logger.Info("attempting to find user with only public key", "key", key) | |
| 585 | - | pk, err := me.FindPublicKeyForKey(key) | |
| 261 | + | pk, err := me.findPublicKeyByKey(key) | |
| 586 | 262 | if err == nil { | |
| 587 | 263 | me.Logger.Info("found pubkey, looking for user", "key", key, "userId", pk.UserID) | |
| 588 | 264 | user, err := me.FindUser(pk.UserID) |
| ... | ... | @@ -595,7 +271,7 @@ func (me *PsqlDB) FindUserForKey(username string, key string) (*db.User, error) | |
| 595 | 271 | ||
| 596 | 272 | if errors.Is(err, &db.ErrMultiplePublicKeys{}) { | |
| 597 | 273 | me.Logger.Info("detected multiple users with same public key", "user", username) | |
| 598 | - | user, err := me.FindUserForNameAndKey(username, key) | |
| 274 | + | user, err := me.findUserForNameAndKey(username, key) | |
| 599 | 275 | if err != nil { | |
| 600 | 276 | me.Logger.Info("could not find user by username and public key", "user", username, "key", key) | |
| 601 | 277 | // this is a little hacky but if we cannot find a user by name and public key |
| ... | ... | @@ -611,7 +287,7 @@ func (me *PsqlDB) FindUserForKey(username string, key string) (*db.User, error) | |
| 611 | 287 | ||
| 612 | 288 | func (me *PsqlDB) FindUserByPubkey(key string) (*db.User, error) { | |
| 613 | 289 | me.Logger.Info("attempting to find user with only public key", "key", key) | |
| 614 | - | pk, err := me.FindPublicKeyForKey(key) | |
| 290 | + | pk, err := me.findPublicKeyByKey(key) | |
| 615 | 291 | if err != nil { | |
| 616 | 292 | return nil, err | |
| 617 | 293 | } |
| ... | ... | @@ -627,19 +303,14 @@ func (me *PsqlDB) FindUserByPubkey(key string) (*db.User, error) { | |
| 627 | 303 | ||
| 628 | 304 | func (me *PsqlDB) FindUser(userID string) (*db.User, error) { | |
| 629 | 305 | user := &db.User{} | |
| 630 | - | var un sql.NullString | |
| 631 | - | r := me.Db.QueryRow(sqlSelectUser, userID) | |
| 632 | - | err := r.Scan(&user.ID, &un, &user.CreatedAt) | |
| 306 | + | err := me.Db.Get(user, `SELECT id, COALESCE(name, '') as name, created_at FROM app_users WHERE id = $1`, userID) | |
| 633 | 307 | if err != nil { | |
| 634 | 308 | return nil, err | |
| 635 | 309 | } | |
| 636 | - | if un.Valid { | |
| 637 | - | user.Name = un.String | |
| 638 | - | } | |
| 639 | 310 | return user, nil | |
| 640 | 311 | } | |
| 641 | 312 | ||
| 642 | - | func (me *PsqlDB) ValidateName(name string) (bool, error) { | |
| 313 | + | func (me *PsqlDB) validateName(name string) (bool, error) { | |
| 643 | 314 | lower := strings.ToLower(name) | |
| 644 | 315 | if slices.Contains(db.DenyList, lower) { | |
| 645 | 316 | return false, fmt.Errorf("%s is on deny list: %w", lower, db.ErrNameDenied) |
| ... | ... | @@ -657,19 +328,18 @@ func (me *PsqlDB) ValidateName(name string) (bool, error) { | |
| 657 | 328 | ||
| 658 | 329 | func (me *PsqlDB) FindUserByName(name string) (*db.User, error) { | |
| 659 | 330 | user := &db.User{} | |
| 660 | - | r := me.Db.QueryRow(sqlSelectUserForName, strings.ToLower(name)) | |
| 661 | - | err := r.Scan(&user.ID, &user.Name, &user.CreatedAt) | |
| 331 | + | err := me.Db.Get(user, `SELECT * FROM app_users WHERE name = $1`, strings.ToLower(name)) | |
| 662 | 332 | if err != nil { | |
| 663 | 333 | return nil, err | |
| 664 | 334 | } | |
| 665 | 335 | return user, nil | |
| 666 | 336 | } | |
| 667 | 337 | ||
| 668 | - | func (me *PsqlDB) FindUserForNameAndKey(name string, key string) (*db.User, error) { | |
| 338 | + | func (me *PsqlDB) findUserForNameAndKey(name string, key string) (*db.User, error) { | |
| 669 | 339 | user := &db.User{} | |
| 670 | 340 | pk := &db.PublicKey{} | |
| 671 | 341 | ||
| 672 | - | r := me.Db.QueryRow(sqlSelectUserForNameAndKey, strings.ToLower(name), key) | |
| 342 | + | r := me.Db.QueryRow(`SELECT app_users.id, app_users.name, app_users.created_at, public_keys.id as pk_id, public_keys.public_key, public_keys.created_at as pk_created_at FROM app_users LEFT JOIN public_keys ON public_keys.user_id = app_users.id WHERE app_users.name = $1 AND public_keys.public_key = $2`, strings.ToLower(name), key) | |
| 673 | 343 | err := r.Scan(&user.ID, &user.Name, &user.CreatedAt, &pk.ID, &pk.Key, &pk.CreatedAt) | |
| 674 | 344 | if err != nil { | |
| 675 | 345 | return nil, err |
| ... | ... | @@ -679,32 +349,29 @@ func (me *PsqlDB) FindUserForNameAndKey(name string, key string) (*db.User, erro | |
| 679 | 349 | return user, nil | |
| 680 | 350 | } | |
| 681 | 351 | ||
| 682 | - | func (me *PsqlDB) FindUserForToken(token string) (*db.User, error) { | |
| 352 | + | func (me *PsqlDB) FindUserByToken(token string) (*db.User, error) { | |
| 683 | 353 | user := &db.User{} | |
| 684 | - | ||
| 685 | - | r := me.Db.QueryRow(sqlSelectUserForToken, token) | |
| 686 | - | err := r.Scan(&user.ID, &user.Name, &user.CreatedAt) | |
| 354 | + | err := me.Db.Get(user, ` | |
| 355 | + | SELECT app_users.id, app_users.name, app_users.created_at | |
| 356 | + | FROM app_users | |
| 357 | + | LEFT JOIN tokens ON tokens.user_id = app_users.id | |
| 358 | + | WHERE tokens.token = $1 AND tokens.expires_at > NOW()`, token) | |
| 687 | 359 | if err != nil { | |
| 688 | 360 | return nil, err | |
| 689 | 361 | } | |
| 690 | - | ||
| 691 | 362 | return user, nil | |
| 692 | 363 | } | |
| 693 | 364 | ||
| 694 | - | func (me *PsqlDB) SetUserName(userID string, name string) error { | |
| 695 | - | lowerName := strings.ToLower(name) | |
| 696 | - | valid, err := me.ValidateName(lowerName) | |
| 697 | - | if !valid { | |
| 698 | - | return err | |
| 699 | - | } | |
| 700 | - | ||
| 701 | - | _, err = me.Db.Exec(sqlUpdateUserName, lowerName, userID) | |
| 702 | - | return err | |
| 703 | - | } | |
| 704 | - | ||
| 705 | 365 | func (me *PsqlDB) FindPostWithFilename(filename string, persona_id string, space string) (*db.Post, error) { | |
| 706 | - | r := me.Db.QueryRow(sqlSelectPostWithFilename, filename, persona_id, space) | |
| 707 | - | post, err := CreatePostWithTagsFromRow(r) | |
| 366 | + | query := fmt.Sprintf(` | |
| 367 | + | SELECT %s, STRING_AGG(coalesce(post_tags.name, ''), ',') tags | |
| 368 | + | FROM posts | |
| 369 | + | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 370 | + | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 371 | + | WHERE filename = $1 AND user_id = $2 AND cur_space = $3 | |
| 372 | + | GROUP BY %s`, SelectPost, SelectPost) | |
| 373 | + | r := me.Db.QueryRow(query, filename, persona_id, space) | |
| 374 | + | post, err := CreatePostWithTagsByRow(r) | |
| 708 | 375 | if err != nil { | |
| 709 | 376 | return nil, err | |
| 710 | 377 | } |
| ... | ... | @@ -713,11 +380,18 @@ func (me *PsqlDB) FindPostWithFilename(filename string, persona_id string, space | |
| 713 | 380 | } | |
| 714 | 381 | ||
| 715 | 382 | func (me *PsqlDB) FindPostWithSlug(slug string, user_id string, space string) (*db.Post, error) { | |
| 716 | - | r := me.Db.QueryRow(sqlSelectPostWithSlug, slug, user_id, space) | |
| 717 | - | post, err := CreatePostWithTagsFromRow(r) | |
| 383 | + | query := fmt.Sprintf(` | |
| 384 | + | SELECT %s, STRING_AGG(coalesce(post_tags.name, ''), ',') tags | |
| 385 | + | FROM posts | |
| 386 | + | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 387 | + | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 388 | + | WHERE slug = $1 AND user_id = $2 AND cur_space = $3 | |
| 389 | + | GROUP BY %s`, SelectPost, SelectPost) | |
| 390 | + | r := me.Db.QueryRow(query, slug, user_id, space) | |
| 391 | + | post, err := CreatePostWithTagsByRow(r) | |
| 718 | 392 | if err != nil { | |
| 719 | 393 | // attempt to find post inside post_aliases | |
| 720 | - | alias := me.Db.QueryRow(sqlSelectPostIdByAliasSlug, slug) | |
| 394 | + | alias := me.Db.QueryRow(`SELECT post_id FROM post_aliases WHERE slug = $1`, slug) | |
| 721 | 395 | postID := "" | |
| 722 | 396 | err := alias.Scan(&postID) | |
| 723 | 397 | if err != nil { |
| ... | ... | @@ -731,16 +405,20 @@ func (me *PsqlDB) FindPostWithSlug(slug string, user_id string, space string) (* | |
| 731 | 405 | } | |
| 732 | 406 | ||
| 733 | 407 | func (me *PsqlDB) FindPost(postID string) (*db.Post, error) { | |
| 734 | - | r := me.Db.QueryRow(sqlSelectPost, postID) | |
| 735 | - | post, err := CreatePostFromRow(r) | |
| 408 | + | post := &db.Post{} | |
| 409 | + | query := fmt.Sprintf(` | |
| 410 | + | SELECT %s | |
| 411 | + | FROM posts | |
| 412 | + | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 413 | + | WHERE posts.id = $1`, SelectPost) | |
| 414 | + | err := me.Db.Get(post, query, postID) | |
| 736 | 415 | if err != nil { | |
| 737 | 416 | return nil, err | |
| 738 | 417 | } | |
| 739 | - | ||
| 740 | 418 | return post, nil | |
| 741 | 419 | } | |
| 742 | 420 | ||
| 743 | - | func (me *PsqlDB) postPager(rs *sql.Rows, pageNum int, space string, tag string) (*db.Paginate[*db.Post], error) { | |
| 421 | + | func (me *PsqlDB) postPager(rs *sqlx.Rows, pageNum int, space string, tag string) (*db.Paginate[*db.Post], error) { | |
| 744 | 422 | var posts []*db.Post | |
| 745 | 423 | for rs.Next() { | |
| 746 | 424 | post := &db.Post{} |
| ... | ... | @@ -770,9 +448,13 @@ func (me *PsqlDB) postPager(rs *sql.Rows, pageNum int, space string, tag string) | |
| 770 | 448 | var count int | |
| 771 | 449 | var err error | |
| 772 | 450 | if tag == "" { | |
| 773 | - | err = me.Db.QueryRow(sqlSelectPostCount, space).Scan(&count) | |
| 451 | + | err = me.Db.QueryRow(`SELECT count(id) FROM posts WHERE hidden = FALSE AND cur_space=$1`, space).Scan(&count) | |
| 774 | 452 | } else { | |
| 775 | - | err = me.Db.QueryRow(sqlSelectTagPostCount, space, tag).Scan(&count) | |
| 453 | + | err = me.Db.QueryRow(` | |
| 454 | + | SELECT count(posts.id) | |
| 455 | + | FROM posts | |
| 456 | + | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 457 | + | WHERE hidden = FALSE AND cur_space=$1 and post_tags.name = $2`, space, tag).Scan(&count) | |
| 776 | 458 | } | |
| 777 | 459 | if err != nil { | |
| 778 | 460 | return nil, err |
| ... | ... | @@ -786,26 +468,50 @@ func (me *PsqlDB) postPager(rs *sql.Rows, pageNum int, space string, tag string) | |
| 786 | 468 | return pager, nil | |
| 787 | 469 | } | |
| 788 | 470 | ||
| 789 | - | func (me *PsqlDB) FindPostsForFeed(page *db.Pager, space string) (*db.Paginate[*db.Post], error) { | |
| 790 | - | rs, err := me.Db.Query(sqlSelectPostsByRank, page.Num, page.Num*page.Page, space) | |
| 791 | - | if err != nil { | |
| 792 | - | return nil, err | |
| 793 | - | } | |
| 794 | - | return me.postPager(rs, page.Num, space, "") | |
| 795 | - | } | |
| 796 | - | ||
| 797 | - | func (me *PsqlDB) FindAllUpdatedPosts(page *db.Pager, space string) (*db.Paginate[*db.Post], error) { | |
| 798 | - | rs, err := me.Db.Query(sqlSelectAllUpdatedPosts, page.Num, page.Num*page.Page, space) | |
| 471 | + | func (me *PsqlDB) FindPostsByFeed(page *db.Pager, space string) (*db.Paginate[*db.Post], error) { | |
| 472 | + | query := ` | |
| 473 | + | SELECT * | |
| 474 | + | FROM ( | |
| 475 | + | SELECT DISTINCT ON (posts.user_id) | |
| 476 | + | posts.id, | |
| 477 | + | posts.user_id, | |
| 478 | + | posts.filename, | |
| 479 | + | posts.slug, | |
| 480 | + | posts.title, | |
| 481 | + | posts.text, | |
| 482 | + | posts.description, | |
| 483 | + | posts.publish_at, | |
| 484 | + | app_users.name AS username, | |
| 485 | + | posts.updated_at, | |
| 486 | + | posts.mime_type | |
| 487 | + | FROM posts | |
| 488 | + | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 489 | + | WHERE | |
| 490 | + | hidden = FALSE | |
| 491 | + | AND publish_at::date <= CURRENT_DATE | |
| 492 | + | AND cur_space = $3 | |
| 493 | + | ORDER BY posts.user_id, publish_at DESC | |
| 494 | + | ) AS latest_posts | |
| 495 | + | ORDER BY publish_at DESC | |
| 496 | + | LIMIT $1 OFFSET $2` | |
| 497 | + | rs, err := me.Db.Queryx(query, page.Num, page.Num*page.Page, space) | |
| 799 | 498 | if err != nil { | |
| 800 | 499 | return nil, err | |
| 801 | 500 | } | |
| 501 | + | defer func() { _ = rs.Close() }() | |
| 802 | 502 | return me.postPager(rs, page.Num, space, "") | |
| 803 | 503 | } | |
| 804 | 504 | ||
| 805 | 505 | func (me *PsqlDB) InsertPost(post *db.Post) (*db.Post, error) { | |
| 806 | 506 | var id string | |
| 507 | + | query := ` | |
| 508 | + | INSERT INTO posts | |
| 509 | + | (user_id, filename, slug, title, text, description, publish_at, hidden, cur_space, | |
| 510 | + | file_size, mime_type, shasum, data, expires_at, updated_at) | |
| 511 | + | VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) | |
| 512 | + | RETURNING id` | |
| 807 | 513 | err := me.Db.QueryRow( | |
| 808 | - | sqlInsertPost, | |
| 514 | + | query, | |
| 809 | 515 | post.UserID, | |
| 810 | 516 | post.Filename, | |
| 811 | 517 | post.Slug, |
| ... | ... | @@ -830,8 +536,13 @@ func (me *PsqlDB) InsertPost(post *db.Post) (*db.Post, error) { | |
| 830 | 536 | } | |
| 831 | 537 | ||
| 832 | 538 | func (me *PsqlDB) UpdatePost(post *db.Post) (*db.Post, error) { | |
| 539 | + | query := ` | |
| 540 | + | UPDATE posts | |
| 541 | + | SET slug = $1, title = $2, text = $3, description = $4, updated_at = $5, publish_at = $6, | |
| 542 | + | file_size = $7, shasum = $8, data = $9, hidden = $11, expires_at = $12 | |
| 543 | + | WHERE id = $10` | |
| 833 | 544 | _, err := me.Db.Exec( | |
| 834 | - | sqlUpdatePost, | |
| 545 | + | query, | |
| 835 | 546 | post.Slug, | |
| 836 | 547 | post.Title, | |
| 837 | 548 | post.Text, |
| ... | ... | @@ -854,14 +565,27 @@ func (me *PsqlDB) UpdatePost(post *db.Post) (*db.Post, error) { | |
| 854 | 565 | ||
| 855 | 566 | func (me *PsqlDB) RemovePosts(postIDs []string) error { | |
| 856 | 567 | param := "{" + strings.Join(postIDs, ",") + "}" | |
| 857 | - | _, err := me.Db.Exec(sqlRemovePosts, param) | |
| 568 | + | _, err := me.Db.Exec(`DELETE FROM posts WHERE id = ANY($1::uuid[])`, param) | |
| 858 | 569 | return err | |
| 859 | 570 | } | |
| 860 | 571 | ||
| 861 | - | func (me *PsqlDB) FindPostsForUser(page *db.Pager, userID string, space string) (*db.Paginate[*db.Post], error) { | |
| 572 | + | func (me *PsqlDB) FindPostsByUser(page *db.Pager, userID string, space string) (*db.Paginate[*db.Post], error) { | |
| 862 | 573 | var posts []*db.Post | |
| 863 | - | rs, err := me.Db.Query( | |
| 864 | - | sqlSelectPostsForUser, | |
| 574 | + | query := fmt.Sprintf(` | |
| 575 | + | SELECT %s, STRING_AGG(coalesce(post_tags.name, ''), ',') tags | |
| 576 | + | FROM posts | |
| 577 | + | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 578 | + | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 579 | + | WHERE | |
| 580 | + | hidden = FALSE AND | |
| 581 | + | user_id = $1 AND | |
| 582 | + | publish_at::date <= CURRENT_DATE AND | |
| 583 | + | cur_space = $2 | |
| 584 | + | GROUP BY %s | |
| 585 | + | ORDER BY publish_at DESC, slug DESC | |
| 586 | + | LIMIT $3 OFFSET $4`, SelectPost, SelectPost) | |
| 587 | + | rs, err := me.Db.Queryx( | |
| 588 | + | query, | |
| 865 | 589 | userID, | |
| 866 | 590 | space, | |
| 867 | 591 | page.Num, |
| ... | ... | @@ -870,8 +594,9 @@ func (me *PsqlDB) FindPostsForUser(page *db.Pager, userID string, space string) | |
| 870 | 594 | if err != nil { | |
| 871 | 595 | return nil, err | |
| 872 | 596 | } | |
| 597 | + | defer func() { _ = rs.Close() }() | |
| 873 | 598 | for rs.Next() { | |
| 874 | - | post, err := CreatePostWithTagsFromRow(rs) | |
| 599 | + | post, err := CreatePostWithTagsByRow(rs) | |
| 875 | 600 | if err != nil { | |
| 876 | 601 | return nil, err | |
| 877 | 602 | } |
| ... | ... | @@ -884,7 +609,7 @@ func (me *PsqlDB) FindPostsForUser(page *db.Pager, userID string, space string) | |
| 884 | 609 | } | |
| 885 | 610 | ||
| 886 | 611 | var count int | |
| 887 | - | err = me.Db.QueryRow(sqlSelectPostCount, space).Scan(&count) | |
| 612 | + | err = me.Db.QueryRow(`SELECT count(id) FROM posts WHERE hidden = FALSE AND cur_space=$1`, space).Scan(&count) | |
| 888 | 613 | if err != nil { | |
| 889 | 614 | return nil, err | |
| 890 | 615 | } |
| ... | ... | @@ -896,82 +621,49 @@ func (me *PsqlDB) FindPostsForUser(page *db.Pager, userID string, space string) | |
| 896 | 621 | return pager, nil | |
| 897 | 622 | } | |
| 898 | 623 | ||
| 899 | - | func (me *PsqlDB) FindAllPostsForUser(userID string, space string) ([]*db.Post, error) { | |
| 900 | - | var posts []*db.Post | |
| 901 | - | rs, err := me.Db.Query(sqlSelectAllPostsForUser, userID, space) | |
| 902 | - | if err != nil { | |
| 903 | - | return posts, err | |
| 904 | - | } | |
| 905 | - | for rs.Next() { | |
| 906 | - | post, err := CreatePostFromRow(rs) | |
| 907 | - | if err != nil { | |
| 908 | - | return nil, err | |
| 909 | - | } | |
| 910 | - | ||
| 911 | - | posts = append(posts, post) | |
| 912 | - | } | |
| 913 | - | if rs.Err() != nil { | |
| 914 | - | return posts, rs.Err() | |
| 915 | - | } | |
| 916 | - | return posts, nil | |
| 917 | - | } | |
| 918 | - | ||
| 919 | - | func (me *PsqlDB) FindPosts() ([]*db.Post, error) { | |
| 624 | + | func (me *PsqlDB) FindAllPostsByUser(userID string, space string) ([]*db.Post, error) { | |
| 920 | 625 | var posts []*db.Post | |
| 921 | - | rs, err := me.Db.Query(sqlSelectPosts) | |
| 922 | - | if err != nil { | |
| 923 | - | return posts, err | |
| 924 | - | } | |
| 925 | - | for rs.Next() { | |
| 926 | - | post, err := CreatePostFromRow(rs) | |
| 927 | - | if err != nil { | |
| 928 | - | return nil, err | |
| 929 | - | } | |
| 930 | - | ||
| 931 | - | posts = append(posts, post) | |
| 932 | - | } | |
| 933 | - | if rs.Err() != nil { | |
| 934 | - | return posts, rs.Err() | |
| 626 | + | query := fmt.Sprintf(` | |
| 627 | + | SELECT %s | |
| 628 | + | FROM posts | |
| 629 | + | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 630 | + | WHERE | |
| 631 | + | user_id = $1 AND | |
| 632 | + | cur_space = $2 | |
| 633 | + | ORDER BY publish_at DESC`, SelectPost) | |
| 634 | + | err := me.Db.Select(&posts, query, userID, space) | |
| 635 | + | if err != nil { | |
| 636 | + | return nil, err | |
| 935 | 637 | } | |
| 936 | 638 | return posts, nil | |
| 937 | 639 | } | |
| 938 | 640 | ||
| 939 | - | func (me *PsqlDB) FindExpiredPosts(space string) ([]*db.Post, error) { | |
| 641 | + | func (me *PsqlDB) FindPosts() ([]*db.Post, error) { | |
| 940 | 642 | var posts []*db.Post | |
| 941 | - | rs, err := me.Db.Query(sqlSelectExpiredPosts, space) | |
| 643 | + | query := fmt.Sprintf(` | |
| 644 | + | SELECT %s | |
| 645 | + | FROM posts | |
| 646 | + | LEFT JOIN app_users ON app_users.id = posts.user_id`, SelectPost) | |
| 647 | + | err := me.Db.Select(&posts, query) | |
| 942 | 648 | if err != nil { | |
| 943 | - | return posts, err | |
| 944 | - | } | |
| 945 | - | for rs.Next() { | |
| 946 | - | post, err := CreatePostFromRow(rs) | |
| 947 | - | if err != nil { | |
| 948 | - | return nil, err | |
| 949 | - | } | |
| 950 | - | ||
| 951 | - | posts = append(posts, post) | |
| 952 | - | } | |
| 953 | - | if rs.Err() != nil { | |
| 954 | - | return posts, rs.Err() | |
| 649 | + | return nil, err | |
| 955 | 650 | } | |
| 956 | 651 | return posts, nil | |
| 957 | 652 | } | |
| 958 | 653 | ||
| 959 | - | func (me *PsqlDB) FindUpdatedPostsForUser(userID string, space string) ([]*db.Post, error) { | |
| 654 | + | func (me *PsqlDB) FindExpiredPosts(space string) ([]*db.Post, error) { | |
| 960 | 655 | var posts []*db.Post | |
| 961 | - | rs, err := me.Db.Query(sqlSelectUpdatedPostsForUser, userID, space) | |
| 656 | + | query := fmt.Sprintf(` | |
| 657 | + | SELECT %s | |
| 658 | + | FROM posts | |
| 659 | + | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 660 | + | WHERE | |
| 661 | + | cur_space = $1 AND | |
| 662 | + | expires_at <= now(); | |
| 663 | + | `, SelectPost) | |
| 664 | + | err := me.Db.Select(&posts, query, space) | |
| 962 | 665 | if err != nil { | |
| 963 | - | return posts, err | |
| 964 | - | } | |
| 965 | - | for rs.Next() { | |
| 966 | - | post, err := CreatePostFromRow(rs) | |
| 967 | - | if err != nil { | |
| 968 | - | return nil, err | |
| 969 | - | } | |
| 970 | - | ||
| 971 | - | posts = append(posts, post) | |
| 972 | - | } | |
| 973 | - | if rs.Err() != nil { | |
| 974 | - | return posts, rs.Err() | |
| 666 | + | return nil, err | |
| 975 | 667 | } | |
| 976 | 668 | return posts, nil | |
| 977 | 669 | } |
| ... | ... | @@ -1033,10 +725,11 @@ func (me *PsqlDB) visitUnique(opts *db.SummaryOpts) ([]*db.VisitInterval, error) | |
| 1033 | 725 | GROUP BY interval_start`, opts.Interval, where) | |
| 1034 | 726 | ||
| 1035 | 727 | intervals := []*db.VisitInterval{} | |
| 1036 | - | rs, err := me.Db.Query(uniqueVisitors, opts.Origin, with, opts.UserID) | |
| 728 | + | rs, err := me.Db.Queryx(uniqueVisitors, opts.Origin, with, opts.UserID) | |
| 1037 | 729 | if err != nil { | |
| 1038 | 730 | return nil, err | |
| 1039 | 731 | } | |
| 732 | + | defer func() { _ = rs.Close() }() | |
| 1040 | 733 | ||
| 1041 | 734 | for rs.Next() { | |
| 1042 | 735 | interval := &db.VisitInterval{} |
| ... | ... | @@ -1068,10 +761,11 @@ func (me *PsqlDB) visitReferer(opts *db.SummaryOpts) ([]*db.VisitUrl, error) { | |
| 1068 | 761 | LIMIT 10`, where) | |
| 1069 | 762 | ||
| 1070 | 763 | intervals := []*db.VisitUrl{} | |
| 1071 | - | rs, err := me.Db.Query(topUrls, opts.Origin, with, opts.UserID) | |
| 764 | + | rs, err := me.Db.Queryx(topUrls, opts.Origin, with, opts.UserID) | |
| 1072 | 765 | if err != nil { | |
| 1073 | 766 | return nil, err | |
| 1074 | 767 | } | |
| 768 | + | defer func() { _ = rs.Close() }() | |
| 1075 | 769 | ||
| 1076 | 770 | for rs.Next() { | |
| 1077 | 771 | interval := &db.VisitUrl{} |
| ... | ... | @@ -1103,10 +797,11 @@ func (me *PsqlDB) visitUrl(opts *db.SummaryOpts) ([]*db.VisitUrl, error) { | |
| 1103 | 797 | LIMIT 10`, where) | |
| 1104 | 798 | ||
| 1105 | 799 | intervals := []*db.VisitUrl{} | |
| 1106 | - | rs, err := me.Db.Query(topUrls, opts.Origin, with, opts.UserID) | |
| 800 | + | rs, err := me.Db.Queryx(topUrls, opts.Origin, with, opts.UserID) | |
| 1107 | 801 | if err != nil { | |
| 1108 | 802 | return nil, err | |
| 1109 | 803 | } | |
| 804 | + | defer func() { _ = rs.Close() }() | |
| 1110 | 805 | ||
| 1111 | 806 | for rs.Next() { | |
| 1112 | 807 | interval := &db.VisitUrl{} |
| ... | ... | @@ -1142,10 +837,11 @@ func (me *PsqlDB) VisitUrlNotFound(opts *db.SummaryOpts) ([]*db.VisitUrl, error) | |
| 1142 | 837 | LIMIT %d`, where, limit) | |
| 1143 | 838 | ||
| 1144 | 839 | intervals := []*db.VisitUrl{} | |
| 1145 | - | rs, err := me.Db.Query(topUrls, opts.Origin, with, opts.UserID) | |
| 840 | + | rs, err := me.Db.Queryx(topUrls, opts.Origin, with, opts.UserID) | |
| 1146 | 841 | if err != nil { | |
| 1147 | 842 | return nil, err | |
| 1148 | 843 | } | |
| 844 | + | defer func() { _ = rs.Close() }() | |
| 1149 | 845 | ||
| 1150 | 846 | for rs.Next() { | |
| 1151 | 847 | interval := &db.VisitUrl{} |
| ... | ... | @@ -1175,10 +871,11 @@ func (me *PsqlDB) visitHost(opts *db.SummaryOpts) ([]*db.VisitUrl, error) { | |
| 1175 | 871 | ORDER BY host_count DESC` | |
| 1176 | 872 | ||
| 1177 | 873 | intervals := []*db.VisitUrl{} | |
| 1178 | - | rs, err := me.Db.Query(topUrls, opts.UserID) | |
| 874 | + | rs, err := me.Db.Queryx(topUrls, opts.UserID) | |
| 1179 | 875 | if err != nil { | |
| 1180 | 876 | return nil, err | |
| 1181 | 877 | } | |
| 878 | + | defer func() { _ = rs.Close() }() | |
| 1182 | 879 | ||
| 1183 | 880 | for rs.Next() { | |
| 1184 | 881 | interval := &db.VisitUrl{} |
| ... | ... | @@ -1233,41 +930,23 @@ func (me *PsqlDB) FindVisitSiteList(opts *db.SummaryOpts) ([]*db.VisitUrl, error | |
| 1233 | 930 | ||
| 1234 | 931 | func (me *PsqlDB) FindUsers() ([]*db.User, error) { | |
| 1235 | 932 | var users []*db.User | |
| 1236 | - | rs, err := me.Db.Query(sqlSelectUsers) | |
| 933 | + | err := me.Db.Select(&users, `SELECT id, COALESCE(name, '') as name, created_at FROM app_users ORDER BY name ASC`) | |
| 1237 | 934 | if err != nil { | |
| 1238 | - | return users, err | |
| 1239 | - | } | |
| 1240 | - | for rs.Next() { | |
| 1241 | - | var name sql.NullString | |
| 1242 | - | user := &db.User{} | |
| 1243 | - | err := rs.Scan( | |
| 1244 | - | &user.ID, | |
| 1245 | - | &name, | |
| 1246 | - | &user.CreatedAt, | |
| 1247 | - | ) | |
| 1248 | - | if err != nil { | |
| 1249 | - | return users, err | |
| 1250 | - | } | |
| 1251 | - | user.Name = name.String | |
| 1252 | - | ||
| 1253 | - | users = append(users, user) | |
| 1254 | - | } | |
| 1255 | - | if rs.Err() != nil { | |
| 1256 | - | return users, rs.Err() | |
| 935 | + | return nil, err | |
| 1257 | 936 | } | |
| 1258 | 937 | return users, nil | |
| 1259 | 938 | } | |
| 1260 | 939 | ||
| 1261 | - | func (me *PsqlDB) removeTagsForPost(tx *sql.Tx, postID string) error { | |
| 1262 | - | _, err := tx.Exec(sqlRemoveTagsByPost, postID) | |
| 940 | + | func (me *PsqlDB) removeTagsByPost(tx *sqlx.Tx, postID string) error { | |
| 941 | + | _, err := tx.Exec(`DELETE FROM post_tags WHERE post_id = $1`, postID) | |
| 1263 | 942 | return err | |
| 1264 | 943 | } | |
| 1265 | 944 | ||
| 1266 | - | func (me *PsqlDB) insertTagsForPost(tx *sql.Tx, tags []string, postID string) ([]string, error) { | |
| 945 | + | func (me *PsqlDB) insertTagsByPost(tx *sqlx.Tx, tags []string, postID string) ([]string, error) { | |
| 1267 | 946 | ids := make([]string, 0) | |
| 1268 | 947 | for _, tag := range tags { | |
| 1269 | 948 | id := "" | |
| 1270 | - | err := tx.QueryRow(sqlInsertTag, postID, tag).Scan(&id) | |
| 949 | + | err := tx.QueryRow(`INSERT INTO post_tags (post_id, name) VALUES($1, $2) RETURNING id;`, postID, tag).Scan(&id) | |
| 1271 | 950 | if err != nil { | |
| 1272 | 951 | return nil, err | |
| 1273 | 952 | } |
| ... | ... | @@ -1277,22 +956,21 @@ func (me *PsqlDB) insertTagsForPost(tx *sql.Tx, tags []string, postID string) ([ | |
| 1277 | 956 | return ids, nil | |
| 1278 | 957 | } | |
| 1279 | 958 | ||
| 1280 | - | func (me *PsqlDB) ReplaceTagsForPost(tags []string, postID string) error { | |
| 1281 | - | ctx := context.Background() | |
| 1282 | - | tx, err := me.Db.BeginTx(ctx, nil) | |
| 959 | + | func (me *PsqlDB) ReplaceTagsByPost(tags []string, postID string) error { | |
| 960 | + | tx, err := me.Db.Beginx() | |
| 1283 | 961 | if err != nil { | |
| 1284 | 962 | return err | |
| 1285 | 963 | } | |
| 1286 | 964 | defer func() { | |
| 1287 | - | err = tx.Rollback() | |
| 965 | + | _ = tx.Rollback() | |
| 1288 | 966 | }() | |
| 1289 | 967 | ||
| 1290 | - | err = me.removeTagsForPost(tx, postID) | |
| 968 | + | err = me.removeTagsByPost(tx, postID) | |
| 1291 | 969 | if err != nil { | |
| 1292 | 970 | return err | |
| 1293 | 971 | } | |
| 1294 | 972 | ||
| 1295 | - | _, err = me.insertTagsForPost(tx, tags, postID) | |
| 973 | + | _, err = me.insertTagsByPost(tx, tags, postID) | |
| 1296 | 974 | if err != nil { | |
| 1297 | 975 | return err | |
| 1298 | 976 | } |
| ... | ... | @@ -1301,12 +979,12 @@ func (me *PsqlDB) ReplaceTagsForPost(tags []string, postID string) error { | |
| 1301 | 979 | return err | |
| 1302 | 980 | } | |
| 1303 | 981 | ||
| 1304 | - | func (me *PsqlDB) removeAliasesForPost(tx *sql.Tx, postID string) error { | |
| 1305 | - | _, err := tx.Exec(sqlRemoveAliasesByPost, postID) | |
| 982 | + | func (me *PsqlDB) removeAliasesByPost(tx *sqlx.Tx, postID string) error { | |
| 983 | + | _, err := tx.Exec(`DELETE FROM post_aliases WHERE post_id = $1`, postID) | |
| 1306 | 984 | return err | |
| 1307 | 985 | } | |
| 1308 | 986 | ||
| 1309 | - | func (me *PsqlDB) insertAliasesForPost(tx *sql.Tx, aliases []string, postID string) ([]string, error) { | |
| 987 | + | func (me *PsqlDB) insertAliasesByPost(tx *sqlx.Tx, aliases []string, postID string) ([]string, error) { | |
| 1310 | 988 | // hardcoded | |
| 1311 | 989 | denyList := []string{ | |
| 1312 | 990 | "rss", |
| ... | ... | @@ -1337,7 +1015,7 @@ func (me *PsqlDB) insertAliasesForPost(tx *sql.Tx, aliases []string, postID stri | |
| 1337 | 1015 | continue | |
| 1338 | 1016 | } | |
| 1339 | 1017 | id := "" | |
| 1340 | - | err := tx.QueryRow(sqlInsertAliases, postID, alias).Scan(&id) | |
| 1018 | + | err := tx.QueryRow(`INSERT INTO post_aliases (post_id, slug) VALUES($1, $2) RETURNING id;`, postID, alias).Scan(&id) | |
| 1341 | 1019 | if err != nil { | |
| 1342 | 1020 | return nil, err | |
| 1343 | 1021 | } |
| ... | ... | @@ -1347,22 +1025,21 @@ func (me *PsqlDB) insertAliasesForPost(tx *sql.Tx, aliases []string, postID stri | |
| 1347 | 1025 | return ids, nil | |
| 1348 | 1026 | } | |
| 1349 | 1027 | ||
| 1350 | - | func (me *PsqlDB) ReplaceAliasesForPost(aliases []string, postID string) error { | |
| 1351 | - | ctx := context.Background() | |
| 1352 | - | tx, err := me.Db.BeginTx(ctx, nil) | |
| 1028 | + | func (me *PsqlDB) ReplaceAliasesByPost(aliases []string, postID string) error { | |
| 1029 | + | tx, err := me.Db.Beginx() | |
| 1353 | 1030 | if err != nil { | |
| 1354 | 1031 | return err | |
| 1355 | 1032 | } | |
| 1356 | 1033 | defer func() { | |
| 1357 | - | err = tx.Rollback() | |
| 1034 | + | _ = tx.Rollback() | |
| 1358 | 1035 | }() | |
| 1359 | 1036 | ||
| 1360 | - | err = me.removeAliasesForPost(tx, postID) | |
| 1037 | + | err = me.removeAliasesByPost(tx, postID) | |
| 1361 | 1038 | if err != nil { | |
| 1362 | 1039 | return err | |
| 1363 | 1040 | } | |
| 1364 | 1041 | ||
| 1365 | - | _, err = me.insertAliasesForPost(tx, aliases, postID) | |
| 1042 | + | _, err = me.insertAliasesByPost(tx, aliases, postID) | |
| 1366 | 1043 | if err != nil { | |
| 1367 | 1044 | return err | |
| 1368 | 1045 | } |
| ... | ... | @@ -1373,8 +1050,22 @@ func (me *PsqlDB) ReplaceAliasesForPost(aliases []string, postID string) error { | |
| 1373 | 1050 | ||
| 1374 | 1051 | func (me *PsqlDB) FindUserPostsByTag(page *db.Pager, tag, userID, space string) (*db.Paginate[*db.Post], error) { | |
| 1375 | 1052 | var posts []*db.Post | |
| 1376 | - | rs, err := me.Db.Query( | |
| 1377 | - | sqlSelectUserPostsByTag, | |
| 1053 | + | query := fmt.Sprintf(` | |
| 1054 | + | SELECT %s | |
| 1055 | + | FROM posts | |
| 1056 | + | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 1057 | + | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 1058 | + | WHERE | |
| 1059 | + | hidden = FALSE AND | |
| 1060 | + | user_id = $1 AND | |
| 1061 | + | (post_tags.name = $2 OR hidden = true) AND | |
| 1062 | + | publish_at::date <= CURRENT_DATE AND | |
| 1063 | + | cur_space = $3 | |
| 1064 | + | ORDER BY publish_at DESC | |
| 1065 | + | LIMIT $4 OFFSET $5`, SelectPost) | |
| 1066 | + | err := me.Db.Select( | |
| 1067 | + | &posts, | |
| 1068 | + | query, | |
| 1378 | 1069 | userID, | |
| 1379 | 1070 | tag, | |
| 1380 | 1071 | space, |
| ... | ... | @@ -1384,21 +1075,9 @@ func (me *PsqlDB) FindUserPostsByTag(page *db.Pager, tag, userID, space string) | |
| 1384 | 1075 | if err != nil { | |
| 1385 | 1076 | return nil, err | |
| 1386 | 1077 | } | |
| 1387 | - | for rs.Next() { | |
| 1388 | - | post, err := CreatePostFromRow(rs) | |
| 1389 | - | if err != nil { | |
| 1390 | - | return nil, err | |
| 1391 | - | } | |
| 1392 | - | ||
| 1393 | - | posts = append(posts, post) | |
| 1394 | - | } | |
| 1395 | - | ||
| 1396 | - | if rs.Err() != nil { | |
| 1397 | - | return nil, rs.Err() | |
| 1398 | - | } | |
| 1399 | 1078 | ||
| 1400 | 1079 | var count int | |
| 1401 | - | err = me.Db.QueryRow(sqlSelectPostCount, space).Scan(&count) | |
| 1080 | + | err = me.Db.QueryRow(`SELECT count(id) FROM posts WHERE hidden = FALSE AND cur_space=$1`, space).Scan(&count) | |
| 1402 | 1081 | if err != nil { | |
| 1403 | 1082 | return nil, err | |
| 1404 | 1083 | } |
| ... | ... | @@ -1411,8 +1090,30 @@ func (me *PsqlDB) FindUserPostsByTag(page *db.Pager, tag, userID, space string) | |
| 1411 | 1090 | } | |
| 1412 | 1091 | ||
| 1413 | 1092 | func (me *PsqlDB) FindPostsByTag(pager *db.Pager, tag, space string) (*db.Paginate[*db.Post], error) { | |
| 1414 | - | rs, err := me.Db.Query( | |
| 1415 | - | sqlSelectPostsByTag, | |
| 1093 | + | query := ` | |
| 1094 | + | SELECT | |
| 1095 | + | posts.id, | |
| 1096 | + | user_id, | |
| 1097 | + | filename, | |
| 1098 | + | slug, | |
| 1099 | + | title, | |
| 1100 | + | text, | |
| 1101 | + | description, | |
| 1102 | + | publish_at, | |
| 1103 | + | app_users.name as username, | |
| 1104 | + | posts.updated_at, | |
| 1105 | + | posts.mime_type | |
| 1106 | + | FROM posts | |
| 1107 | + | LEFT JOIN app_users ON app_users.id = posts.user_id | |
| 1108 | + | LEFT JOIN post_tags ON post_tags.post_id = posts.id | |
| 1109 | + | WHERE | |
| 1110 | + | post_tags.name = $3 AND | |
| 1111 | + | publish_at::date <= CURRENT_DATE AND | |
| 1112 | + | cur_space = $4 | |
| 1113 | + | ORDER BY publish_at DESC | |
| 1114 | + | LIMIT $1 OFFSET $2` | |
| 1115 | + | rs, err := me.Db.Queryx( | |
| 1116 | + | query, | |
| 1416 | 1117 | pager.Num, | |
| 1417 | 1118 | pager.Num*pager.Page, | |
| 1418 | 1119 | tag, |
| ... | ... | @@ -1421,16 +1122,26 @@ func (me *PsqlDB) FindPostsByTag(pager *db.Pager, tag, space string) (*db.Pagina | |
| 1421 | 1122 | if err != nil { | |
| 1422 | 1123 | return nil, err | |
| 1423 | 1124 | } | |
| 1125 | + | defer func() { _ = rs.Close() }() | |
| 1424 | 1126 | ||
| 1425 | 1127 | return me.postPager(rs, pager.Num, space, tag) | |
| 1426 | 1128 | } | |
| 1427 | 1129 | ||
| 1428 | 1130 | func (me *PsqlDB) FindPopularTags(space string) ([]string, error) { | |
| 1429 | 1131 | tags := make([]string, 0) | |
| 1430 | - | rs, err := me.Db.Query(sqlSelectPopularTags, space) | |
| 1132 | + | query := ` | |
| 1133 | + | SELECT name, count(post_id) as "tally" | |
| 1134 | + | FROM post_tags | |
| 1135 | + | LEFT JOIN posts ON posts.id = post_id | |
| 1136 | + | WHERE posts.cur_space = $1 | |
| 1137 | + | GROUP BY name | |
| 1138 | + | ORDER BY tally DESC | |
| 1139 | + | LIMIT 5` | |
| 1140 | + | rs, err := me.Db.Queryx(query, space) | |
| 1431 | 1141 | if err != nil { | |
| 1432 | 1142 | return tags, err | |
| 1433 | 1143 | } | |
| 1144 | + | defer func() { _ = rs.Close() }() | |
| 1434 | 1145 | for rs.Next() { | |
| 1435 | 1146 | name := "" | |
| 1436 | 1147 | tally := 0 |
| ... | ... | @@ -1447,112 +1158,30 @@ func (me *PsqlDB) FindPopularTags(space string) ([]string, error) { | |
| 1447 | 1158 | return tags, nil | |
| 1448 | 1159 | } | |
| 1449 | 1160 | ||
| 1450 | - | func (me *PsqlDB) FindTagsForUser(userID string, space string) ([]string, error) { | |
| 1451 | - | tags := []string{} | |
| 1452 | - | rs, err := me.Db.Query(sqlSelectTagsForUser, userID, space) | |
| 1453 | - | if err != nil { | |
| 1454 | - | return tags, err | |
| 1455 | - | } | |
| 1456 | - | for rs.Next() { | |
| 1457 | - | name := "" | |
| 1458 | - | err := rs.Scan(&name) | |
| 1459 | - | if err != nil { | |
| 1460 | - | return tags, err | |
| 1461 | - | } | |
| 1462 | - | ||
| 1463 | - | tags = append(tags, name) | |
| 1464 | - | } | |
| 1465 | - | if rs.Err() != nil { | |
| 1466 | - | return tags, rs.Err() | |
| 1467 | - | } | |
| 1468 | - | return tags, nil | |
| 1469 | - | } | |
| 1470 | - | ||
| 1471 | - | func (me *PsqlDB) FindTagsForPost(postID string) ([]string, error) { | |
| 1472 | - | tags := make([]string, 0) | |
| 1473 | - | rs, err := me.Db.Query(sqlSelectTagsForPost, postID) | |
| 1474 | - | if err != nil { | |
| 1475 | - | return tags, err | |
| 1476 | - | } | |
| 1477 | - | ||
| 1478 | - | for rs.Next() { | |
| 1479 | - | name := "" | |
| 1480 | - | err := rs.Scan(&name) | |
| 1481 | - | if err != nil { | |
| 1482 | - | return tags, err | |
| 1483 | - | } | |
| 1484 | - | ||
| 1485 | - | tags = append(tags, name) | |
| 1486 | - | } | |
| 1487 | - | ||
| 1488 | - | if rs.Err() != nil { | |
| 1489 | - | return tags, rs.Err() | |
| 1490 | - | } | |
| 1491 | - | ||
| 1492 | - | return tags, nil | |
| 1493 | - | } | |
| 1494 | - | ||
| 1495 | 1161 | func (me *PsqlDB) FindFeature(userID string, feature string) (*db.FeatureFlag, error) { | |
| 1496 | 1162 | ff := &db.FeatureFlag{} | |
| 1497 | - | // payment history is allowed to be null | |
| 1498 | - | // https://devtidbits.com/2020/08/03/go-sql-error-converting-null-to-string-is-unsupported/ | |
| 1499 | - | var paymentHistoryID sql.NullString | |
| 1500 | - | err := me.Db.QueryRow(sqlSelectFeatureForUser, userID, feature).Scan( | |
| 1501 | - | &ff.ID, | |
| 1502 | - | &ff.UserID, | |
| 1503 | - | &paymentHistoryID, | |
| 1504 | - | &ff.Name, | |
| 1505 | - | &ff.Data, | |
| 1506 | - | &ff.CreatedAt, | |
| 1507 | - | &ff.ExpiresAt, | |
| 1508 | - | ) | |
| 1163 | + | err := me.Db.Get(ff, `SELECT * FROM feature_flags WHERE user_id = $1 AND name = $2 ORDER BY expires_at DESC LIMIT 1`, userID, feature) | |
| 1509 | 1164 | if err != nil { | |
| 1510 | 1165 | return nil, err | |
| 1511 | 1166 | } | |
| 1512 | - | ||
| 1513 | - | ff.PaymentHistoryID = paymentHistoryID | |
| 1514 | - | ||
| 1515 | 1167 | return ff, nil | |
| 1516 | 1168 | } | |
| 1517 | 1169 | ||
| 1518 | - | func (me *PsqlDB) FindFeaturesForUser(userID string) ([]*db.FeatureFlag, error) { | |
| 1170 | + | func (me *PsqlDB) FindFeaturesByUser(userID string) ([]*db.FeatureFlag, error) { | |
| 1519 | 1171 | var features []*db.FeatureFlag | |
| 1520 | 1172 | // https://stackoverflow.com/a/16920077 | |
| 1521 | - | query := `SELECT DISTINCT ON (name) | |
| 1522 | - | id, user_id, payment_history_id, name, data, created_at, expires_at | |
| 1173 | + | query := `SELECT DISTINCT ON (name) * | |
| 1523 | 1174 | FROM feature_flags | |
| 1524 | 1175 | WHERE user_id=$1 | |
| 1525 | 1176 | ORDER BY name, expires_at DESC;` | |
| 1526 | - | rs, err := me.Db.Query(query, userID) | |
| 1177 | + | err := me.Db.Select(&features, query, userID) | |
| 1527 | 1178 | if err != nil { | |
| 1528 | - | return features, err | |
| 1529 | - | } | |
| 1530 | - | for rs.Next() { | |
| 1531 | - | var paymentHistoryID sql.NullString | |
| 1532 | - | ff := &db.FeatureFlag{} | |
| 1533 | - | err := rs.Scan( | |
| 1534 | - | &ff.ID, | |
| 1535 | - | &ff.UserID, | |
| 1536 | - | &paymentHistoryID, | |
| 1537 | - | &ff.Name, | |
| 1538 | - | &ff.Data, | |
| 1539 | - | &ff.CreatedAt, | |
| 1540 | - | &ff.ExpiresAt, | |
| 1541 | - | ) | |
| 1542 | - | if err != nil { | |
| 1543 | - | return features, err | |
| 1544 | - | } | |
| 1545 | - | ff.PaymentHistoryID = paymentHistoryID | |
| 1546 | - | ||
| 1547 | - | features = append(features, ff) | |
| 1548 | - | } | |
| 1549 | - | if rs.Err() != nil { | |
| 1550 | - | return features, rs.Err() | |
| 1179 | + | return nil, err | |
| 1551 | 1180 | } | |
| 1552 | 1181 | return features, nil | |
| 1553 | 1182 | } | |
| 1554 | 1183 | ||
| 1555 | - | func (me *PsqlDB) HasFeatureForUser(userID string, feature string) bool { | |
| 1184 | + | func (me *PsqlDB) HasFeatureByUser(userID string, feature string) bool { | |
| 1556 | 1185 | ff, err := me.FindFeature(userID, feature) | |
| 1557 | 1186 | if err != nil { | |
| 1558 | 1187 | return false |
| ... | ... | @@ -1560,28 +1189,18 @@ func (me *PsqlDB) HasFeatureForUser(userID string, feature string) bool { | |
| 1560 | 1189 | return ff.IsValid() | |
| 1561 | 1190 | } | |
| 1562 | 1191 | ||
| 1563 | - | func (me *PsqlDB) FindTotalSizeForUser(userID string) (int, error) { | |
| 1564 | - | var fileSize int | |
| 1565 | - | err := me.Db.QueryRow(sqlSelectSizeForUser, userID).Scan(&fileSize) | |
| 1566 | - | if err != nil { | |
| 1567 | - | return 0, err | |
| 1568 | - | } | |
| 1569 | - | return fileSize, nil | |
| 1570 | - | } | |
| 1571 | - | ||
| 1572 | 1192 | func (me *PsqlDB) InsertFeedItems(postID string, items []*db.FeedItem) error { | |
| 1573 | - | ctx := context.Background() | |
| 1574 | - | tx, err := me.Db.BeginTx(ctx, nil) | |
| 1193 | + | tx, err := me.Db.Beginx() | |
| 1575 | 1194 | if err != nil { | |
| 1576 | 1195 | return err | |
| 1577 | 1196 | } | |
| 1578 | 1197 | defer func() { | |
| 1579 | - | err = tx.Rollback() | |
| 1198 | + | _ = tx.Rollback() | |
| 1580 | 1199 | }() | |
| 1581 | 1200 | ||
| 1582 | 1201 | for _, item := range items { | |
| 1583 | 1202 | _, err := tx.Exec( | |
| 1584 | - | sqlInsertFeedItems, | |
| 1203 | + | `INSERT INTO feed_items (post_id, guid, data) VALUES ($1, $2, $3) RETURNING id;`, | |
| 1585 | 1204 | item.PostID, | |
| 1586 | 1205 | item.GUID, | |
| 1587 | 1206 | item.Data, |
| ... | ... | @@ -1599,33 +1218,11 @@ func (me *PsqlDB) InsertFeedItems(postID string, items []*db.FeedItem) error { | |
| 1599 | 1218 | } | |
| 1600 | 1219 | ||
| 1601 | 1220 | func (me *PsqlDB) FindFeedItemsByPostID(postID string) ([]*db.FeedItem, error) { | |
| 1602 | - | // sqlSelectFeedItemsByPost | |
| 1603 | - | items := make([]*db.FeedItem, 0) | |
| 1604 | - | rs, err := me.Db.Query(sqlSelectFeedItemsByPost, postID) | |
| 1221 | + | var items []*db.FeedItem | |
| 1222 | + | err := me.Db.Select(&items, `SELECT * FROM feed_items WHERE post_id=$1`, postID) | |
| 1605 | 1223 | if err != nil { | |
| 1606 | - | return items, err | |
| 1607 | - | } | |
| 1608 | - | ||
| 1609 | - | for rs.Next() { | |
| 1610 | - | item := &db.FeedItem{} | |
| 1611 | - | err := rs.Scan( | |
| 1612 | - | &item.ID, | |
| 1613 | - | &item.PostID, | |
| 1614 | - | &item.GUID, | |
| 1615 | - | &item.Data, | |
| 1616 | - | &item.CreatedAt, | |
| 1617 | - | ) | |
| 1618 | - | if err != nil { | |
| 1619 | - | return items, err | |
| 1620 | - | } | |
| 1621 | - | ||
| 1622 | - | items = append(items, item) | |
| 1623 | - | } | |
| 1624 | - | ||
| 1625 | - | if rs.Err() != nil { | |
| 1626 | - | return items, rs.Err() | |
| 1224 | + | return nil, err | |
| 1627 | 1225 | } | |
| 1628 | - | ||
| 1629 | 1226 | return items, nil | |
| 1630 | 1227 | } | |
| 1631 | 1228 |
| ... | ... | @@ -1635,7 +1232,7 @@ func (me *PsqlDB) InsertProject(userID, name, projectDir string) (string, error) | |
| 1635 | 1232 | } | |
| 1636 | 1233 | ||
| 1637 | 1234 | var id string | |
| 1638 | - | err := me.Db.QueryRow(sqlInsertProject, userID, name, projectDir).Scan(&id) | |
| 1235 | + | err := me.Db.QueryRow(`INSERT INTO projects (user_id, name, project_dir) VALUES ($1, $2, $3) RETURNING id;`, userID, name, projectDir).Scan(&id) | |
| 1639 | 1236 | if err != nil { | |
| 1640 | 1237 | return "", err | |
| 1641 | 1238 | } |
| ... | ... | @@ -1643,33 +1240,22 @@ func (me *PsqlDB) InsertProject(userID, name, projectDir string) (string, error) | |
| 1643 | 1240 | } | |
| 1644 | 1241 | ||
| 1645 | 1242 | func (me *PsqlDB) UpdateProject(userID, name string) error { | |
| 1646 | - | _, err := me.Db.Exec(sqlUpdateProject, userID, name, time.Now()) | |
| 1243 | + | _, err := me.Db.Exec(`UPDATE projects SET updated_at = $3 WHERE user_id = $1 AND name = $2;`, userID, name, time.Now()) | |
| 1647 | 1244 | return err | |
| 1648 | 1245 | } | |
| 1649 | 1246 | ||
| 1650 | 1247 | func (me *PsqlDB) FindProjectByName(userID, name string) (*db.Project, error) { | |
| 1651 | 1248 | project := &db.Project{} | |
| 1652 | - | r := me.Db.QueryRow(sqlFindProjectByName, userID, name) | |
| 1653 | - | err := r.Scan( | |
| 1654 | - | &project.ID, | |
| 1655 | - | &project.UserID, | |
| 1656 | - | &project.Name, | |
| 1657 | - | &project.ProjectDir, | |
| 1658 | - | &project.Acl, | |
| 1659 | - | &project.Blocked, | |
| 1660 | - | &project.CreatedAt, | |
| 1661 | - | &project.UpdatedAt, | |
| 1662 | - | ) | |
| 1249 | + | err := me.Db.Get(project, `SELECT * FROM projects WHERE user_id = $1 AND name = $2;`, userID, name) | |
| 1663 | 1250 | if err != nil { | |
| 1664 | 1251 | return nil, err | |
| 1665 | 1252 | } | |
| 1666 | - | ||
| 1667 | 1253 | return project, nil | |
| 1668 | 1254 | } | |
| 1669 | 1255 | ||
| 1670 | 1256 | func (me *PsqlDB) InsertToken(userID, name string) (string, error) { | |
| 1671 | 1257 | var token string | |
| 1672 | - | err := me.Db.QueryRow(sqlInsertToken, userID, name).Scan(&token) | |
| 1258 | + | err := me.Db.QueryRow(`INSERT INTO tokens (user_id, name) VALUES($1, $2) RETURNING token;`, userID, name).Scan(&token) | |
| 1673 | 1259 | if err != nil { | |
| 1674 | 1260 | return "", err | |
| 1675 | 1261 | } |
| ... | ... | @@ -1677,7 +1263,7 @@ func (me *PsqlDB) InsertToken(userID, name string) (string, error) { | |
| 1677 | 1263 | } | |
| 1678 | 1264 | ||
| 1679 | 1265 | func (me *PsqlDB) UpsertToken(userID, name string) (string, error) { | |
| 1680 | - | token, _ := me.FindTokenByName(userID, name) | |
| 1266 | + | token, _ := me.findTokenByName(userID, name) | |
| 1681 | 1267 | if token != "" { | |
| 1682 | 1268 | return token, nil | |
| 1683 | 1269 | } |
| ... | ... | @@ -1686,9 +1272,9 @@ func (me *PsqlDB) UpsertToken(userID, name string) (string, error) { | |
| 1686 | 1272 | return token, err | |
| 1687 | 1273 | } | |
| 1688 | 1274 | ||
| 1689 | - | func (me *PsqlDB) FindTokenByName(userID, name string) (string, error) { | |
| 1275 | + | func (me *PsqlDB) findTokenByName(userID, name string) (string, error) { | |
| 1690 | 1276 | var token string | |
| 1691 | - | err := me.Db.QueryRow(sqlSelectTokenByNameForUser, userID, name).Scan(&token) | |
| 1277 | + | err := me.Db.QueryRow(`SELECT token FROM tokens WHERE user_id = $1 AND name = $2`, userID, name).Scan(&token) | |
| 1692 | 1278 | if err != nil { | |
| 1693 | 1279 | return "", err | |
| 1694 | 1280 | } |
| ... | ... | @@ -1696,29 +1282,17 @@ func (me *PsqlDB) FindTokenByName(userID, name string) (string, error) { | |
| 1696 | 1282 | } | |
| 1697 | 1283 | ||
| 1698 | 1284 | func (me *PsqlDB) RemoveToken(tokenID string) error { | |
| 1699 | - | _, err := me.Db.Exec(sqlRemoveToken, tokenID) | |
| 1285 | + | _, err := me.Db.Exec(`DELETE FROM tokens WHERE id = $1`, tokenID) | |
| 1700 | 1286 | return err | |
| 1701 | 1287 | } | |
| 1702 | 1288 | ||
| 1703 | - | func (me *PsqlDB) FindTokensForUser(userID string) ([]*db.Token, error) { | |
| 1704 | - | var keys []*db.Token | |
| 1705 | - | rs, err := me.Db.Query(sqlSelectTokensForUser, userID) | |
| 1289 | + | func (me *PsqlDB) FindTokensByUser(userID string) ([]*db.Token, error) { | |
| 1290 | + | var tokens []*db.Token | |
| 1291 | + | err := me.Db.Select(&tokens, `SELECT * FROM tokens WHERE user_id = $1`, userID) | |
| 1706 | 1292 | if err != nil { | |
| 1707 | - | return keys, err | |
| 1708 | - | } | |
| 1709 | - | for rs.Next() { | |
| 1710 | - | pk := &db.Token{} | |
| 1711 | - | err := rs.Scan(&pk.ID, &pk.UserID, &pk.Name, &pk.CreatedAt, &pk.ExpiresAt) | |
| 1712 | - | if err != nil { | |
| 1713 | - | return keys, err | |
| 1714 | - | } | |
| 1715 | - | ||
| 1716 | - | keys = append(keys, pk) | |
| 1717 | - | } | |
| 1718 | - | if rs.Err() != nil { | |
| 1719 | - | return keys, rs.Err() | |
| 1293 | + | return nil, err | |
| 1720 | 1294 | } | |
| 1721 | - | return keys, nil | |
| 1295 | + | return tokens, nil | |
| 1722 | 1296 | } | |
| 1723 | 1297 | ||
| 1724 | 1298 | func (me *PsqlDB) InsertFeature(userID, name string, expiresAt time.Time) (*db.FeatureFlag, error) { |
| ... | ... | @@ -1763,13 +1337,12 @@ func (me *PsqlDB) AddPicoPlusUser(username, email, paymentType, txId string) err | |
| 1763 | 1337 | return err | |
| 1764 | 1338 | } | |
| 1765 | 1339 | ||
| 1766 | - | ctx := context.Background() | |
| 1767 | - | tx, err := me.Db.BeginTx(ctx, nil) | |
| 1340 | + | tx, err := me.Db.Beginx() | |
| 1768 | 1341 | if err != nil { | |
| 1769 | 1342 | return err | |
| 1770 | 1343 | } | |
| 1771 | 1344 | defer func() { | |
| 1772 | - | err = tx.Rollback() | |
| 1345 | + | _ = tx.Rollback() | |
| 1773 | 1346 | }() | |
| 1774 | 1347 | ||
| 1775 | 1348 | var paymentHistoryId sql.NullString |
| ... | ... | @@ -1849,69 +1422,32 @@ func (me *PsqlDB) InsertTunsEventLog(log *db.TunsEventLog) error { | |
| 1849 | 1422 | } | |
| 1850 | 1423 | ||
| 1851 | 1424 | func (me *PsqlDB) FindTunsEventLogsByAddr(userID, addr string) ([]*db.TunsEventLog, error) { | |
| 1852 | - | logs := []*db.TunsEventLog{} | |
| 1853 | - | rs, err := me.Db.Query( | |
| 1854 | - | `SELECT id, user_id, server_id, remote_addr, event_type, tunnel_type, connection_type, tunnel_id, created_at | |
| 1855 | - | FROM tuns_event_logs WHERE user_id=$1 AND tunnel_id=$2 ORDER BY created_at DESC`, userID, addr) | |
| 1425 | + | var logs []*db.TunsEventLog | |
| 1426 | + | err := me.Db.Select(&logs, | |
| 1427 | + | `SELECT * FROM tuns_event_logs WHERE user_id=$1 AND tunnel_id=$2 ORDER BY created_at DESC`, userID, addr) | |
| 1856 | 1428 | if err != nil { | |
| 1857 | 1429 | return nil, err | |
| 1858 | 1430 | } | |
| 1859 | - | ||
| 1860 | - | for rs.Next() { | |
| 1861 | - | log := db.TunsEventLog{} | |
| 1862 | - | err := rs.Scan( | |
| 1863 | - | &log.ID, &log.UserId, &log.ServerID, &log.RemoteAddr, | |
| 1864 | - | &log.EventType, &log.TunnelType, &log.ConnectionType, | |
| 1865 | - | &log.TunnelID, &log.CreatedAt, | |
| 1866 | - | ) | |
| 1867 | - | if err != nil { | |
| 1868 | - | return nil, err | |
| 1869 | - | } | |
| 1870 | - | logs = append(logs, &log) | |
| 1871 | - | } | |
| 1872 | - | ||
| 1873 | - | if rs.Err() != nil { | |
| 1874 | - | return nil, rs.Err() | |
| 1875 | - | } | |
| 1876 | - | ||
| 1877 | 1431 | return logs, nil | |
| 1878 | 1432 | } | |
| 1879 | 1433 | ||
| 1880 | 1434 | func (me *PsqlDB) FindTunsEventLogs(userID string) ([]*db.TunsEventLog, error) { | |
| 1881 | - | logs := []*db.TunsEventLog{} | |
| 1882 | - | rs, err := me.Db.Query( | |
| 1883 | - | `SELECT id, user_id, server_id, remote_addr, event_type, tunnel_type, connection_type, tunnel_id, created_at | |
| 1884 | - | FROM tuns_event_logs WHERE user_id=$1 ORDER BY created_at DESC`, userID) | |
| 1435 | + | var logs []*db.TunsEventLog | |
| 1436 | + | err := me.Db.Select(&logs, | |
| 1437 | + | `SELECT * FROM tuns_event_logs WHERE user_id=$1 ORDER BY created_at DESC`, userID) | |
| 1885 | 1438 | if err != nil { | |
| 1886 | 1439 | return nil, err | |
| 1887 | 1440 | } | |
| 1888 | - | ||
| 1889 | - | for rs.Next() { | |
| 1890 | - | log := db.TunsEventLog{} | |
| 1891 | - | err := rs.Scan( | |
| 1892 | - | &log.ID, &log.UserId, &log.ServerID, &log.RemoteAddr, | |
| 1893 | - | &log.EventType, &log.TunnelType, &log.ConnectionType, | |
| 1894 | - | &log.TunnelID, &log.CreatedAt, | |
| 1895 | - | ) | |
| 1896 | - | if err != nil { | |
| 1897 | - | return nil, err | |
| 1898 | - | } | |
| 1899 | - | logs = append(logs, &log) | |
| 1900 | - | } | |
| 1901 | - | ||
| 1902 | - | if rs.Err() != nil { | |
| 1903 | - | return nil, rs.Err() | |
| 1904 | - | } | |
| 1905 | - | ||
| 1906 | 1441 | return logs, nil | |
| 1907 | 1442 | } | |
| 1908 | 1443 | ||
| 1909 | 1444 | func (me *PsqlDB) FindUserStats(userID string) (*db.UserStats, error) { | |
| 1910 | 1445 | stats := db.UserStats{} | |
| 1911 | - | rs, err := me.Db.Query(`SELECT cur_space, count(id), min(created_at), max(created_at), max(updated_at) FROM posts WHERE user_id=$1 GROUP BY cur_space`, userID) | |
| 1446 | + | rs, err := me.Db.Queryx(`SELECT cur_space, count(id), min(created_at), max(created_at), max(updated_at) FROM posts WHERE user_id=$1 GROUP BY cur_space`, userID) | |
| 1912 | 1447 | if err != nil { | |
| 1913 | 1448 | return nil, err | |
| 1914 | 1449 | } | |
| 1450 | + | defer func() { _ = rs.Close() }() | |
| 1915 | 1451 | ||
| 1916 | 1452 | for rs.Next() { | |
| 1917 | 1453 | stat := db.UserServiceStats{} |
| ... | ... | @@ -1942,79 +1478,29 @@ func (me *PsqlDB) FindUserStats(userID string) (*db.UserStats, error) { | |
| 1942 | 1478 | } | |
| 1943 | 1479 | ||
| 1944 | 1480 | func (me *PsqlDB) FindAccessLogs(userID string, fromDate *time.Time) ([]*db.AccessLog, error) { | |
| 1945 | - | logs := []*db.AccessLog{} | |
| 1946 | - | rs, err := me.Db.Query( | |
| 1947 | - | `SELECT id, user_id, service, pubkey, identity, created_at FROM access_logs WHERE user_id=$1 AND created_at >= $2 ORDER BY created_at DESC`, userID, fromDate) | |
| 1481 | + | var logs []*db.AccessLog | |
| 1482 | + | err := me.Db.Select(&logs, `SELECT * FROM access_logs WHERE user_id=$1 AND created_at >= $2 ORDER BY created_at DESC`, userID, fromDate) | |
| 1948 | 1483 | if err != nil { | |
| 1949 | 1484 | return nil, err | |
| 1950 | 1485 | } | |
| 1951 | - | ||
| 1952 | - | for rs.Next() { | |
| 1953 | - | log := db.AccessLog{} | |
| 1954 | - | err := rs.Scan( | |
| 1955 | - | &log.ID, &log.UserID, &log.Service, &log.Pubkey, &log.Identity, &log.CreatedAt, | |
| 1956 | - | ) | |
| 1957 | - | if err != nil { | |
| 1958 | - | return nil, err | |
| 1959 | - | } | |
| 1960 | - | logs = append(logs, &log) | |
| 1961 | - | } | |
| 1962 | - | ||
| 1963 | - | if rs.Err() != nil { | |
| 1964 | - | return nil, rs.Err() | |
| 1965 | - | } | |
| 1966 | - | ||
| 1967 | 1486 | return logs, nil | |
| 1968 | 1487 | } | |
| 1969 | 1488 | ||
| 1970 | 1489 | func (me *PsqlDB) FindAccessLogsByPubkey(pubkey string, fromDate *time.Time) ([]*db.AccessLog, error) { | |
| 1971 | - | logs := []*db.AccessLog{} | |
| 1972 | - | rs, err := me.Db.Query( | |
| 1973 | - | `SELECT id, user_id, service, pubkey, identity, created_at FROM access_logs WHERE pubkey=$1 AND created_at >= $2 ORDER BY created_at DESC`, pubkey, fromDate) | |
| 1490 | + | var logs []*db.AccessLog | |
| 1491 | + | err := me.Db.Select(&logs, `SELECT * FROM access_logs WHERE pubkey=$1 AND created_at >= $2 ORDER BY created_at DESC`, pubkey, fromDate) | |
| 1974 | 1492 | if err != nil { | |
| 1975 | 1493 | return nil, err | |
| 1976 | 1494 | } | |
| 1977 | - | ||
| 1978 | - | for rs.Next() { | |
| 1979 | - | log := db.AccessLog{} | |
| 1980 | - | err := rs.Scan( | |
| 1981 | - | &log.ID, &log.UserID, &log.Service, &log.Pubkey, &log.Identity, &log.CreatedAt, | |
| 1982 | - | ) | |
| 1983 | - | if err != nil { | |
| 1984 | - | return nil, err | |
| 1985 | - | } | |
| 1986 | - | logs = append(logs, &log) | |
| 1987 | - | } | |
| 1988 | - | ||
| 1989 | - | if rs.Err() != nil { | |
| 1990 | - | return nil, rs.Err() | |
| 1991 | - | } | |
| 1992 | - | ||
| 1993 | 1495 | return logs, nil | |
| 1994 | 1496 | } | |
| 1995 | 1497 | ||
| 1996 | 1498 | func (me *PsqlDB) FindPubkeysInAccessLogs(userID string) ([]string, error) { | |
| 1997 | - | pubkeys := []string{} | |
| 1998 | - | rs, err := me.Db.Query( | |
| 1999 | - | `SELECT DISTINCT(pubkey) FROM access_logs WHERE user_id=$1`, userID, | |
| 2000 | - | ) | |
| 1499 | + | var pubkeys []string | |
| 1500 | + | err := me.Db.Select(&pubkeys, `SELECT DISTINCT(pubkey) FROM access_logs WHERE user_id=$1`, userID) | |
| 2001 | 1501 | if err != nil { | |
| 2002 | 1502 | return nil, err | |
| 2003 | 1503 | } | |
| 2004 | - | ||
| 2005 | - | for rs.Next() { | |
| 2006 | - | pubkey := "" | |
| 2007 | - | err := rs.Scan(&pubkey) | |
| 2008 | - | if err != nil { | |
| 2009 | - | return nil, err | |
| 2010 | - | } | |
| 2011 | - | pubkeys = append(pubkeys, pubkey) | |
| 2012 | - | } | |
| 2013 | - | ||
| 2014 | - | if rs.Err() != nil { | |
| 2015 | - | return nil, rs.Err() | |
| 2016 | - | } | |
| 2017 | - | ||
| 2018 | 1504 | return pubkeys, nil | |
| 2019 | 1505 | } | |
| 2020 | 1506 |
+1472,
-0
| ... | ... | @@ -0,0 +1,1472 @@ | |
| 1 | + | package postgres | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "context" | |
| 5 | + | "fmt" | |
| 6 | + | "log/slog" | |
| 7 | + | "os" | |
| 8 | + | "os/exec" | |
| 9 | + | "path/filepath" | |
| 10 | + | "runtime" | |
| 11 | + | "sort" | |
| 12 | + | "testing" | |
| 13 | + | "time" | |
| 14 | + | ||
| 15 | + | "github.com/jmoiron/sqlx" | |
| 16 | + | _ "github.com/lib/pq" | |
| 17 | + | "github.com/picosh/pico/pkg/db" | |
| 18 | + | "github.com/testcontainers/testcontainers-go" | |
| 19 | + | "github.com/testcontainers/testcontainers-go/modules/postgres" | |
| 20 | + | "github.com/testcontainers/testcontainers-go/wait" | |
| 21 | + | ) | |
| 22 | + | ||
| 23 | + | var testDB *PsqlDB | |
| 24 | + | var testLogger *slog.Logger | |
| 25 | + | var skipTests bool | |
| 26 | + | ||
| 27 | + | func setupContainerRuntime() bool { | |
| 28 | + | // Check if DATABASE_URL is set for external postgres (CI/CD or manual testing) | |
| 29 | + | if os.Getenv("TEST_DATABASE_URL") != "" { | |
| 30 | + | return true | |
| 31 | + | } | |
| 32 | + | ||
| 33 | + | // Try podman first | |
| 34 | + | if cmd := exec.Command("podman", "info"); cmd.Run() == nil { | |
| 35 | + | // For podman, we need to ensure the socket is running | |
| 36 | + | // User should run: systemctl --user start podman.socket | |
| 37 | + | _ = os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true") | |
| 38 | + | ||
| 39 | + | // Check if socket exists and is accessible | |
| 40 | + | xdgRuntime := os.Getenv("XDG_RUNTIME_DIR") | |
| 41 | + | if xdgRuntime != "" { | |
| 42 | + | socketPath := xdgRuntime + "/podman/podman.sock" | |
| 43 | + | if _, err := os.Stat(socketPath); err == nil { | |
| 44 | + | _ = os.Setenv("DOCKER_HOST", "unix://"+socketPath) | |
| 45 | + | return true | |
| 46 | + | } | |
| 47 | + | } | |
| 48 | + | // Socket not available, need to start it | |
| 49 | + | fmt.Println("Podman detected but socket not running. Run: systemctl --user start podman.socket") | |
| 50 | + | return false | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | // Try docker | |
| 54 | + | if cmd := exec.Command("docker", "info"); cmd.Run() == nil { | |
| 55 | + | return true | |
| 56 | + | } | |
| 57 | + | ||
| 58 | + | return false | |
| 59 | + | } | |
| 60 | + | ||
| 61 | + | func TestMain(m *testing.M) { | |
| 62 | + | ctx := context.Background() | |
| 63 | + | testLogger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelError})) | |
| 64 | + | ||
| 65 | + | // Check for external database URL first (for CI/CD or manual testing) | |
| 66 | + | if dbURL := os.Getenv("TEST_DATABASE_URL"); dbURL != "" { | |
| 67 | + | testDB = NewDB(dbURL, testLogger) | |
| 68 | + | if err := setupTestSchema(testDB.Db); err != nil { | |
| 69 | + | panic(fmt.Sprintf("failed to setup schema: %s", err)) | |
| 70 | + | } | |
| 71 | + | code := m.Run() | |
| 72 | + | _ = testDB.Close() | |
| 73 | + | os.Exit(code) | |
| 74 | + | } | |
| 75 | + | ||
| 76 | + | if !setupContainerRuntime() { | |
| 77 | + | fmt.Println("Container runtime not available, skipping integration tests") | |
| 78 | + | fmt.Println("To run tests, either:") | |
| 79 | + | fmt.Println(" - Set TEST_DATABASE_URL to a postgres connection string") | |
| 80 | + | fmt.Println(" - Start podman socket: systemctl --user start podman.socket") | |
| 81 | + | fmt.Println(" - Start docker daemon") | |
| 82 | + | skipTests = true | |
| 83 | + | os.Exit(0) | |
| 84 | + | } | |
| 85 | + | ||
| 86 | + | pgContainer, err := postgres.Run(ctx, | |
| 87 | + | "postgres:14", | |
| 88 | + | postgres.WithDatabase("pico_test"), | |
| 89 | + | postgres.WithUsername("postgres"), | |
| 90 | + | postgres.WithPassword("postgres"), | |
| 91 | + | testcontainers.WithWaitStrategy( | |
| 92 | + | wait.ForLog("database system is ready to accept connections"). | |
| 93 | + | WithOccurrence(2). | |
| 94 | + | WithStartupTimeout(30*time.Second)), | |
| 95 | + | ) | |
| 96 | + | if err != nil { | |
| 97 | + | fmt.Printf("Failed to start postgres container (Docker may not be running): %s\n", err) | |
| 98 | + | skipTests = true | |
| 99 | + | os.Exit(0) | |
| 100 | + | } | |
| 101 | + | ||
| 102 | + | connStr, err := pgContainer.ConnectionString(ctx, "sslmode=disable") | |
| 103 | + | if err != nil { | |
| 104 | + | panic(fmt.Sprintf("failed to get connection string: %s", err)) | |
| 105 | + | } | |
| 106 | + | ||
| 107 | + | testDB = NewDB(connStr, testLogger) | |
| 108 | + | ||
| 109 | + | if err := setupTestSchema(testDB.Db); err != nil { | |
| 110 | + | panic(fmt.Sprintf("failed to setup schema: %s", err)) | |
| 111 | + | } | |
| 112 | + | ||
| 113 | + | code := m.Run() | |
| 114 | + | ||
| 115 | + | _ = testDB.Close() | |
| 116 | + | _ = pgContainer.Terminate(ctx) | |
| 117 | + | ||
| 118 | + | os.Exit(code) | |
| 119 | + | } | |
| 120 | + | ||
| 121 | + | func getProjectRoot() string { | |
| 122 | + | _, filename, _, ok := runtime.Caller(0) | |
| 123 | + | if !ok { | |
| 124 | + | panic("failed to get current file path") | |
| 125 | + | } | |
| 126 | + | // storage_test.go is in pkg/db/postgres/, so go up 4 levels to get project root | |
| 127 | + | return filepath.Join(filepath.Dir(filename), "..", "..", "..") | |
| 128 | + | } | |
| 129 | + | ||
| 130 | + | func setupTestSchema(db *sqlx.DB) error { | |
| 131 | + | projectRoot := getProjectRoot() | |
| 132 | + | migrationsDir := filepath.Join(projectRoot, "sql", "migrations") | |
| 133 | + | ||
| 134 | + | // Read all migration files | |
| 135 | + | entries, err := os.ReadDir(migrationsDir) | |
| 136 | + | if err != nil { | |
| 137 | + | return fmt.Errorf("failed to read migrations directory: %w", err) | |
| 138 | + | } | |
| 139 | + | ||
| 140 | + | // Sort by filename (they're date-prefixed, so alphabetical order is correct) | |
| 141 | + | var migrationFiles []string | |
| 142 | + | for _, entry := range entries { | |
| 143 | + | if !entry.IsDir() && filepath.Ext(entry.Name()) == ".sql" { | |
| 144 | + | migrationFiles = append(migrationFiles, entry.Name()) | |
| 145 | + | } | |
| 146 | + | } | |
| 147 | + | sort.Strings(migrationFiles) | |
| 148 | + | ||
| 149 | + | // Execute each migration in order | |
| 150 | + | for _, filename := range migrationFiles { | |
| 151 | + | migrationPath := filepath.Join(migrationsDir, filename) | |
| 152 | + | content, err := os.ReadFile(migrationPath) | |
| 153 | + | if err != nil { | |
| 154 | + | return fmt.Errorf("failed to read migration %s: %w", filename, err) | |
| 155 | + | } | |
| 156 | + | ||
| 157 | + | _, err = db.Exec(string(content)) | |
| 158 | + | if err != nil { | |
| 159 | + | return fmt.Errorf("failed to execute migration %s: %w", filename, err) | |
| 160 | + | } | |
| 161 | + | } | |
| 162 | + | ||
| 163 | + | return nil | |
| 164 | + | } | |
| 165 | + | ||
| 166 | + | func cleanupTestData(t *testing.T) { | |
| 167 | + | t.Helper() | |
| 168 | + | tables := []string{ | |
| 169 | + | "access_logs", "tuns_event_logs", "analytics_visits", | |
| 170 | + | "feed_items", "post_aliases", "post_tags", "posts", | |
| 171 | + | "projects", "feature_flags", "payment_history", "tokens", | |
| 172 | + | "public_keys", "app_users", | |
| 173 | + | } | |
| 174 | + | for _, table := range tables { | |
| 175 | + | _, err := testDB.Db.Exec(fmt.Sprintf("DELETE FROM %s", table)) | |
| 176 | + | if err != nil { | |
| 177 | + | t.Fatalf("failed to clean up %s: %v", table, err) | |
| 178 | + | } | |
| 179 | + | } | |
| 180 | + | } | |
| 181 | + | ||
| 182 | + | func mustInsertPost(t *testing.T, post *db.Post) *db.Post { | |
| 183 | + | t.Helper() | |
| 184 | + | now := time.Now() | |
| 185 | + | if post.UpdatedAt == nil { | |
| 186 | + | post.UpdatedAt = &now | |
| 187 | + | } | |
| 188 | + | if post.PublishAt == nil { | |
| 189 | + | post.PublishAt = &now | |
| 190 | + | } | |
| 191 | + | created, err := testDB.InsertPost(post) | |
| 192 | + | if err != nil { | |
| 193 | + | t.Fatalf("InsertPost failed: %v", err) | |
| 194 | + | } | |
| 195 | + | return created | |
| 196 | + | } | |
| 197 | + | ||
| 198 | + | // ============ User Management Tests ============ | |
| 199 | + | ||
| 200 | + | func TestRegisterUser_Success(t *testing.T) { | |
| 201 | + | cleanupTestData(t) | |
| 202 | + | ||
| 203 | + | user, err := testDB.RegisterUser("testuser", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI testkey", "test comment") | |
| 204 | + | if err != nil { | |
| 205 | + | t.Fatalf("RegisterUser failed: %v", err) | |
| 206 | + | } | |
| 207 | + | if user == nil { | |
| 208 | + | t.Fatal("expected user, got nil") | |
| 209 | + | } | |
| 210 | + | if user.Name != "testuser" { | |
| 211 | + | t.Errorf("expected name 'testuser', got '%s'", user.Name) | |
| 212 | + | } | |
| 213 | + | if user.PublicKey == nil { | |
| 214 | + | t.Fatal("expected public key, got nil") | |
| 215 | + | } | |
| 216 | + | } | |
| 217 | + | ||
| 218 | + | func TestRegisterUser_DuplicateName(t *testing.T) { | |
| 219 | + | cleanupTestData(t) | |
| 220 | + | ||
| 221 | + | _, err := testDB.RegisterUser("duplicateuser", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI key1", "comment1") | |
| 222 | + | if err != nil { | |
| 223 | + | t.Fatalf("first RegisterUser failed: %v", err) | |
| 224 | + | } | |
| 225 | + | ||
| 226 | + | _, err = testDB.RegisterUser("duplicateuser", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI key2", "comment2") | |
| 227 | + | if err == nil { | |
| 228 | + | t.Error("expected error for duplicate name, got nil") | |
| 229 | + | } | |
| 230 | + | } | |
| 231 | + | ||
| 232 | + | func TestRegisterUser_DeniedName(t *testing.T) { | |
| 233 | + | cleanupTestData(t) | |
| 234 | + | ||
| 235 | + | _, err := testDB.RegisterUser("admin", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI adminkey", "comment") | |
| 236 | + | if err == nil { | |
| 237 | + | t.Error("expected error for denied name 'admin', got nil") | |
| 238 | + | } | |
| 239 | + | } | |
| 240 | + | ||
| 241 | + | func TestRegisterUser_InvalidName(t *testing.T) { | |
| 242 | + | cleanupTestData(t) | |
| 243 | + | ||
| 244 | + | _, err := testDB.RegisterUser("user@invalid", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI invalidkey", "comment") | |
| 245 | + | if err == nil { | |
| 246 | + | t.Error("expected error for invalid name, got nil") | |
| 247 | + | } | |
| 248 | + | } | |
| 249 | + | ||
| 250 | + | func TestFindUser(t *testing.T) { | |
| 251 | + | cleanupTestData(t) | |
| 252 | + | ||
| 253 | + | created, err := testDB.RegisterUser("findme", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI findmekey", "comment") | |
| 254 | + | if err != nil { | |
| 255 | + | t.Fatalf("RegisterUser failed: %v", err) | |
| 256 | + | } | |
| 257 | + | ||
| 258 | + | found, err := testDB.FindUser(created.ID) | |
| 259 | + | if err != nil { | |
| 260 | + | t.Fatalf("FindUser failed: %v", err) | |
| 261 | + | } | |
| 262 | + | if found.Name != "findme" { | |
| 263 | + | t.Errorf("expected name 'findme', got '%s'", found.Name) | |
| 264 | + | } | |
| 265 | + | } | |
| 266 | + | ||
| 267 | + | func TestFindUserByName(t *testing.T) { | |
| 268 | + | cleanupTestData(t) | |
| 269 | + | ||
| 270 | + | _, err := testDB.RegisterUser("nameduser", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI namedkey", "comment") | |
| 271 | + | if err != nil { | |
| 272 | + | t.Fatalf("RegisterUser failed: %v", err) | |
| 273 | + | } | |
| 274 | + | ||
| 275 | + | found, err := testDB.FindUserByName("nameduser") | |
| 276 | + | if err != nil { | |
| 277 | + | t.Fatalf("FindUserByName failed: %v", err) | |
| 278 | + | } | |
| 279 | + | if found.Name != "nameduser" { | |
| 280 | + | t.Errorf("expected name 'nameduser', got '%s'", found.Name) | |
| 281 | + | } | |
| 282 | + | } | |
| 283 | + | ||
| 284 | + | func TestFindUserByPubkey(t *testing.T) { | |
| 285 | + | cleanupTestData(t) | |
| 286 | + | ||
| 287 | + | pubkey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI pubkeyuser" | |
| 288 | + | _, err := testDB.RegisterUser("pubkeyuser", pubkey, "comment") | |
| 289 | + | if err != nil { | |
| 290 | + | t.Fatalf("RegisterUser failed: %v", err) | |
| 291 | + | } | |
| 292 | + | ||
| 293 | + | found, err := testDB.FindUserByPubkey(pubkey) | |
| 294 | + | if err != nil { | |
| 295 | + | t.Fatalf("FindUserByPubkey failed: %v", err) | |
| 296 | + | } | |
| 297 | + | if found.Name != "pubkeyuser" { | |
| 298 | + | t.Errorf("expected name 'pubkeyuser', got '%s'", found.Name) | |
| 299 | + | } | |
| 300 | + | } | |
| 301 | + | ||
| 302 | + | func TestFindUserByKey(t *testing.T) { | |
| 303 | + | cleanupTestData(t) | |
| 304 | + | ||
| 305 | + | pubkey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI forkeyfind" | |
| 306 | + | _, err := testDB.RegisterUser("forkeyfind", pubkey, "comment") | |
| 307 | + | if err != nil { | |
| 308 | + | t.Fatalf("RegisterUser failed: %v", err) | |
| 309 | + | } | |
| 310 | + | ||
| 311 | + | found, err := testDB.FindUserByKey("forkeyfind", pubkey) | |
| 312 | + | if err != nil { | |
| 313 | + | t.Fatalf("FindUserByKey failed: %v", err) | |
| 314 | + | } | |
| 315 | + | if found.Name != "forkeyfind" { | |
| 316 | + | t.Errorf("expected name 'forkeyfind', got '%s'", found.Name) | |
| 317 | + | } | |
| 318 | + | } | |
| 319 | + | ||
| 320 | + | func TestFindUsers(t *testing.T) { | |
| 321 | + | cleanupTestData(t) | |
| 322 | + | ||
| 323 | + | _, _ = testDB.RegisterUser("user1", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI user1key", "comment") | |
| 324 | + | _, _ = testDB.RegisterUser("user2", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI user2key", "comment") | |
| 325 | + | ||
| 326 | + | users, err := testDB.FindUsers() | |
| 327 | + | if err != nil { | |
| 328 | + | t.Fatalf("FindUsers failed: %v", err) | |
| 329 | + | } | |
| 330 | + | if len(users) != 2 { | |
| 331 | + | t.Errorf("expected 2 users, got %d", len(users)) | |
| 332 | + | } | |
| 333 | + | } | |
| 334 | + | ||
| 335 | + | // ============ Public Key Management Tests ============ | |
| 336 | + | ||
| 337 | + | func TestInsertPublicKey_Success(t *testing.T) { | |
| 338 | + | cleanupTestData(t) | |
| 339 | + | ||
| 340 | + | user, err := testDB.RegisterUser("keyowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI keyowner1", "comment") | |
| 341 | + | if err != nil { | |
| 342 | + | t.Fatalf("RegisterUser failed: %v", err) | |
| 343 | + | } | |
| 344 | + | ||
| 345 | + | err = testDB.InsertPublicKey(user.ID, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI secondkey", "second key") | |
| 346 | + | if err != nil { | |
| 347 | + | t.Fatalf("InsertPublicKey failed: %v", err) | |
| 348 | + | } | |
| 349 | + | ||
| 350 | + | keys, err := testDB.FindKeysByUser(user) | |
| 351 | + | if err != nil { | |
| 352 | + | t.Fatalf("FindKeysByUser failed: %v", err) | |
| 353 | + | } | |
| 354 | + | if len(keys) != 2 { | |
| 355 | + | t.Errorf("expected 2 keys, got %d", len(keys)) | |
| 356 | + | } | |
| 357 | + | } | |
| 358 | + | ||
| 359 | + | func TestInsertPublicKey_Duplicate(t *testing.T) { | |
| 360 | + | cleanupTestData(t) | |
| 361 | + | ||
| 362 | + | user, _ := testDB.RegisterUser("dupkeyowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI dupkey", "comment") | |
| 363 | + | ||
| 364 | + | err := testDB.InsertPublicKey(user.ID, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI dupkey", "same key") | |
| 365 | + | if err == nil { | |
| 366 | + | t.Error("expected error for duplicate key, got nil") | |
| 367 | + | } | |
| 368 | + | } | |
| 369 | + | ||
| 370 | + | func TestUpdatePublicKey(t *testing.T) { | |
| 371 | + | cleanupTestData(t) | |
| 372 | + | ||
| 373 | + | user, _ := testDB.RegisterUser("updatekeyowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI updatekeyowner", "original") | |
| 374 | + | ||
| 375 | + | updated, err := testDB.UpdatePublicKey(user.PublicKey.ID, "new-name") | |
| 376 | + | if err != nil { | |
| 377 | + | t.Fatalf("UpdatePublicKey failed: %v", err) | |
| 378 | + | } | |
| 379 | + | if updated.Name != "new-name" { | |
| 380 | + | t.Errorf("expected name 'new-name', got '%s'", updated.Name) | |
| 381 | + | } | |
| 382 | + | } | |
| 383 | + | ||
| 384 | + | func TestFindKeysByUser(t *testing.T) { | |
| 385 | + | cleanupTestData(t) | |
| 386 | + | ||
| 387 | + | user, _ := testDB.RegisterUser("multikeyowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI multikeyowner1", "key1") | |
| 388 | + | _ = testDB.InsertPublicKey(user.ID, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI multikeyowner2", "key2") | |
| 389 | + | ||
| 390 | + | keys, err := testDB.FindKeysByUser(user) | |
| 391 | + | if err != nil { | |
| 392 | + | t.Fatalf("FindKeysByUser failed: %v", err) | |
| 393 | + | } | |
| 394 | + | if len(keys) != 2 { | |
| 395 | + | t.Errorf("expected 2 keys, got %d", len(keys)) | |
| 396 | + | } | |
| 397 | + | } | |
| 398 | + | ||
| 399 | + | func TestRemoveKeys(t *testing.T) { | |
| 400 | + | cleanupTestData(t) | |
| 401 | + | ||
| 402 | + | user, _ := testDB.RegisterUser("removekeyowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI removekeyowner", "key1") | |
| 403 | + | _ = testDB.InsertPublicKey(user.ID, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI removekeyowner2", "key2") | |
| 404 | + | ||
| 405 | + | keys, _ := testDB.FindKeysByUser(user) | |
| 406 | + | if len(keys) != 2 { | |
| 407 | + | t.Fatalf("expected 2 keys before removal, got %d", len(keys)) | |
| 408 | + | } | |
| 409 | + | ||
| 410 | + | err := testDB.RemoveKeys([]string{keys[1].ID}) | |
| 411 | + | if err != nil { | |
| 412 | + | t.Fatalf("RemoveKeys failed: %v", err) | |
| 413 | + | } | |
| 414 | + | ||
| 415 | + | keys, _ = testDB.FindKeysByUser(user) | |
| 416 | + | if len(keys) != 1 { | |
| 417 | + | t.Errorf("expected 1 key after removal, got %d", len(keys)) | |
| 418 | + | } | |
| 419 | + | } | |
| 420 | + | ||
| 421 | + | // ============ Token Management Tests ============ | |
| 422 | + | ||
| 423 | + | func TestInsertToken(t *testing.T) { | |
| 424 | + | cleanupTestData(t) | |
| 425 | + | ||
| 426 | + | user, _ := testDB.RegisterUser("tokenowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI tokenowner", "comment") | |
| 427 | + | ||
| 428 | + | token, err := testDB.InsertToken(user.ID, "my-token") | |
| 429 | + | if err != nil { | |
| 430 | + | t.Fatalf("InsertToken failed: %v", err) | |
| 431 | + | } | |
| 432 | + | if token == "" { | |
| 433 | + | t.Error("expected token string, got empty") | |
| 434 | + | } | |
| 435 | + | } | |
| 436 | + | ||
| 437 | + | func TestUpsertToken(t *testing.T) { | |
| 438 | + | cleanupTestData(t) | |
| 439 | + | ||
| 440 | + | user, _ := testDB.RegisterUser("upserttokenowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI upserttokenowner", "comment") | |
| 441 | + | ||
| 442 | + | token1, err := testDB.UpsertToken(user.ID, "upsert-token") | |
| 443 | + | if err != nil { | |
| 444 | + | t.Fatalf("first UpsertToken failed: %v", err) | |
| 445 | + | } | |
| 446 | + | ||
| 447 | + | token2, err := testDB.UpsertToken(user.ID, "upsert-token") | |
| 448 | + | if err != nil { | |
| 449 | + | t.Fatalf("second UpsertToken failed: %v", err) | |
| 450 | + | } | |
| 451 | + | ||
| 452 | + | if token1 != token2 { | |
| 453 | + | t.Errorf("expected same token, got different: %s vs %s", token1, token2) | |
| 454 | + | } | |
| 455 | + | } | |
| 456 | + | ||
| 457 | + | func TestFindTokensByUser(t *testing.T) { | |
| 458 | + | cleanupTestData(t) | |
| 459 | + | ||
| 460 | + | user, _ := testDB.RegisterUser("tokensowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI tokensowner", "comment") | |
| 461 | + | _, _ = testDB.InsertToken(user.ID, "token1") | |
| 462 | + | _, _ = testDB.InsertToken(user.ID, "token2") | |
| 463 | + | ||
| 464 | + | tokens, err := testDB.FindTokensByUser(user.ID) | |
| 465 | + | if err != nil { | |
| 466 | + | t.Fatalf("FindTokensByUser failed: %v", err) | |
| 467 | + | } | |
| 468 | + | if len(tokens) != 2 { | |
| 469 | + | t.Errorf("expected 2 tokens, got %d", len(tokens)) | |
| 470 | + | } | |
| 471 | + | } | |
| 472 | + | ||
| 473 | + | func TestFindUserByToken_Valid(t *testing.T) { | |
| 474 | + | cleanupTestData(t) | |
| 475 | + | ||
| 476 | + | user, _ := testDB.RegisterUser("validtokenowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI validtokenowner", "comment") | |
| 477 | + | token, _ := testDB.InsertToken(user.ID, "valid-token") | |
| 478 | + | ||
| 479 | + | found, err := testDB.FindUserByToken(token) | |
| 480 | + | if err != nil { | |
| 481 | + | t.Fatalf("FindUserByToken failed: %v", err) | |
| 482 | + | } | |
| 483 | + | if found.Name != "validtokenowner" { | |
| 484 | + | t.Errorf("expected name 'validtokenowner', got '%s'", found.Name) | |
| 485 | + | } | |
| 486 | + | } | |
| 487 | + | ||
| 488 | + | func TestFindUserByToken_Expired(t *testing.T) { | |
| 489 | + | cleanupTestData(t) | |
| 490 | + | ||
| 491 | + | user, _ := testDB.RegisterUser("expiredtokenowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI expiredtokenowner", "comment") | |
| 492 | + | token, _ := testDB.InsertToken(user.ID, "expired-token") | |
| 493 | + | ||
| 494 | + | _, err := testDB.Db.Exec("UPDATE tokens SET expires_at = NOW() - INTERVAL '1 day' WHERE token = $1", token) | |
| 495 | + | if err != nil { | |
| 496 | + | t.Fatalf("failed to expire token: %v", err) | |
| 497 | + | } | |
| 498 | + | ||
| 499 | + | _, err = testDB.FindUserByToken(token) | |
| 500 | + | if err == nil { | |
| 501 | + | t.Error("expected error for expired token, got nil") | |
| 502 | + | } | |
| 503 | + | } | |
| 504 | + | ||
| 505 | + | func TestRemoveToken(t *testing.T) { | |
| 506 | + | cleanupTestData(t) | |
| 507 | + | ||
| 508 | + | user, _ := testDB.RegisterUser("removetokenowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI removetokenowner", "comment") | |
| 509 | + | _, _ = testDB.InsertToken(user.ID, "remove-token") | |
| 510 | + | ||
| 511 | + | tokens, _ := testDB.FindTokensByUser(user.ID) | |
| 512 | + | if len(tokens) != 1 { | |
| 513 | + | t.Fatalf("expected 1 token, got %d", len(tokens)) | |
| 514 | + | } | |
| 515 | + | ||
| 516 | + | err := testDB.RemoveToken(tokens[0].ID) | |
| 517 | + | if err != nil { | |
| 518 | + | t.Fatalf("RemoveToken failed: %v", err) | |
| 519 | + | } | |
| 520 | + | ||
| 521 | + | tokens, _ = testDB.FindTokensByUser(user.ID) | |
| 522 | + | if len(tokens) != 0 { | |
| 523 | + | t.Errorf("expected 0 tokens after removal, got %d", len(tokens)) | |
| 524 | + | } | |
| 525 | + | } | |
| 526 | + | ||
| 527 | + | // ============ Post CRUD Tests ============ | |
| 528 | + | ||
| 529 | + | func TestInsertPost(t *testing.T) { | |
| 530 | + | cleanupTestData(t) | |
| 531 | + | ||
| 532 | + | user, _ := testDB.RegisterUser("postowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI postowner", "comment") | |
| 533 | + | ||
| 534 | + | now := time.Now() | |
| 535 | + | post := &db.Post{ | |
| 536 | + | UserID: user.ID, | |
| 537 | + | Filename: "test.md", | |
| 538 | + | Slug: "test-post", | |
| 539 | + | Title: "Test Post", | |
| 540 | + | Text: "Post content", | |
| 541 | + | Description: "A test post", | |
| 542 | + | PublishAt: &now, | |
| 543 | + | UpdatedAt: &now, | |
| 544 | + | Space: "prose", | |
| 545 | + | MimeType: "text/markdown", | |
| 546 | + | } | |
| 547 | + | ||
| 548 | + | created, err := testDB.InsertPost(post) | |
| 549 | + | if err != nil { | |
| 550 | + | t.Fatalf("InsertPost failed: %v", err) | |
| 551 | + | } | |
| 552 | + | if created.ID == "" { | |
| 553 | + | t.Error("expected post ID, got empty") | |
| 554 | + | } | |
| 555 | + | if created.Title != "Test Post" { | |
| 556 | + | t.Errorf("expected title 'Test Post', got '%s'", created.Title) | |
| 557 | + | } | |
| 558 | + | } | |
| 559 | + | ||
| 560 | + | func TestUpdatePost(t *testing.T) { | |
| 561 | + | cleanupTestData(t) | |
| 562 | + | ||
| 563 | + | user, _ := testDB.RegisterUser("updatepostowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI updatepostowner", "comment") | |
| 564 | + | ||
| 565 | + | now := time.Now() | |
| 566 | + | post := mustInsertPost(t, &db.Post{ | |
| 567 | + | UserID: user.ID, | |
| 568 | + | Filename: "update.md", | |
| 569 | + | Slug: "update-post", | |
| 570 | + | Title: "Original Title", | |
| 571 | + | Text: "Original content", | |
| 572 | + | Space: "prose", | |
| 573 | + | }) | |
| 574 | + | ||
| 575 | + | post.Title = "Updated Title" | |
| 576 | + | post.Text = "Updated content" | |
| 577 | + | post.UpdatedAt = &now | |
| 578 | + | ||
| 579 | + | updated, err := testDB.UpdatePost(post) | |
| 580 | + | if err != nil { | |
| 581 | + | t.Fatalf("UpdatePost failed: %v", err) | |
| 582 | + | } | |
| 583 | + | if updated.Title != "Updated Title" { | |
| 584 | + | t.Errorf("expected title 'Updated Title', got '%s'", updated.Title) | |
| 585 | + | } | |
| 586 | + | } | |
| 587 | + | ||
| 588 | + | func TestRemovePosts(t *testing.T) { | |
| 589 | + | cleanupTestData(t) | |
| 590 | + | ||
| 591 | + | user, _ := testDB.RegisterUser("removepostowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI removepostowner", "comment") | |
| 592 | + | ||
| 593 | + | post := mustInsertPost(t, &db.Post{ | |
| 594 | + | UserID: user.ID, | |
| 595 | + | Filename: "remove.md", | |
| 596 | + | Slug: "remove-post", | |
| 597 | + | Title: "To Remove", | |
| 598 | + | Space: "prose", | |
| 599 | + | }) | |
| 600 | + | ||
| 601 | + | err := testDB.RemovePosts([]string{post.ID}) | |
| 602 | + | if err != nil { | |
| 603 | + | t.Fatalf("RemovePosts failed: %v", err) | |
| 604 | + | } | |
| 605 | + | ||
| 606 | + | _, err = testDB.FindPost(post.ID) | |
| 607 | + | if err == nil { | |
| 608 | + | t.Error("expected error finding removed post, got nil") | |
| 609 | + | } | |
| 610 | + | } | |
| 611 | + | ||
| 612 | + | func TestFindPost(t *testing.T) { | |
| 613 | + | cleanupTestData(t) | |
| 614 | + | ||
| 615 | + | user, _ := testDB.RegisterUser("findpostowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI findpostowner", "comment") | |
| 616 | + | ||
| 617 | + | created := mustInsertPost(t, &db.Post{ | |
| 618 | + | UserID: user.ID, | |
| 619 | + | Filename: "find.md", | |
| 620 | + | Slug: "find-post", | |
| 621 | + | Title: "Find Me", | |
| 622 | + | Space: "prose", | |
| 623 | + | }) | |
| 624 | + | ||
| 625 | + | found, err := testDB.FindPost(created.ID) | |
| 626 | + | if err != nil { | |
| 627 | + | t.Fatalf("FindPost failed: %v", err) | |
| 628 | + | } | |
| 629 | + | if found.Title != "Find Me" { | |
| 630 | + | t.Errorf("expected title 'Find Me', got '%s'", found.Title) | |
| 631 | + | } | |
| 632 | + | } | |
| 633 | + | ||
| 634 | + | func TestFindPostWithFilename(t *testing.T) { | |
| 635 | + | cleanupTestData(t) | |
| 636 | + | ||
| 637 | + | user, _ := testDB.RegisterUser("filenamepostowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI filenamepostowner", "comment") | |
| 638 | + | ||
| 639 | + | _ = mustInsertPost(t, &db.Post{ | |
| 640 | + | UserID: user.ID, | |
| 641 | + | Filename: "byfilename.md", | |
| 642 | + | Slug: "byfilename-post", | |
| 643 | + | Title: "By Filename", | |
| 644 | + | Space: "prose", | |
| 645 | + | }) | |
| 646 | + | ||
| 647 | + | found, err := testDB.FindPostWithFilename("byfilename.md", user.ID, "prose") | |
| 648 | + | if err != nil { | |
| 649 | + | t.Fatalf("FindPostWithFilename failed: %v", err) | |
| 650 | + | } | |
| 651 | + | if found.Title != "By Filename" { | |
| 652 | + | t.Errorf("expected title 'By Filename', got '%s'", found.Title) | |
| 653 | + | } | |
| 654 | + | } | |
| 655 | + | ||
| 656 | + | func TestFindPostWithSlug(t *testing.T) { | |
| 657 | + | cleanupTestData(t) | |
| 658 | + | ||
| 659 | + | user, _ := testDB.RegisterUser("slugpostowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI slugpostowner", "comment") | |
| 660 | + | ||
| 661 | + | _ = mustInsertPost(t, &db.Post{ | |
| 662 | + | UserID: user.ID, | |
| 663 | + | Filename: "byslug.md", | |
| 664 | + | Slug: "byslug-post", | |
| 665 | + | Title: "By Slug", | |
| 666 | + | Space: "prose", | |
| 667 | + | }) | |
| 668 | + | ||
| 669 | + | found, err := testDB.FindPostWithSlug("byslug-post", user.ID, "prose") | |
| 670 | + | if err != nil { | |
| 671 | + | t.Fatalf("FindPostWithSlug failed: %v", err) | |
| 672 | + | } | |
| 673 | + | if found.Title != "By Slug" { | |
| 674 | + | t.Errorf("expected title 'By Slug', got '%s'", found.Title) | |
| 675 | + | } | |
| 676 | + | } | |
| 677 | + | ||
| 678 | + | func TestFindPosts(t *testing.T) { | |
| 679 | + | cleanupTestData(t) | |
| 680 | + | ||
| 681 | + | user, _ := testDB.RegisterUser("postsowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI postsowner", "comment") | |
| 682 | + | ||
| 683 | + | _ = mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "post1.md", Slug: "post1", Title: "Post 1", Space: "prose"}) | |
| 684 | + | _ = mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "post2.md", Slug: "post2", Title: "Post 2", Space: "prose"}) | |
| 685 | + | ||
| 686 | + | posts, err := testDB.FindPosts() | |
| 687 | + | if err != nil { | |
| 688 | + | t.Fatalf("FindPosts failed: %v", err) | |
| 689 | + | } | |
| 690 | + | if len(posts) != 2 { | |
| 691 | + | t.Errorf("expected 2 posts, got %d", len(posts)) | |
| 692 | + | } | |
| 693 | + | } | |
| 694 | + | ||
| 695 | + | func TestFindPostsByUser(t *testing.T) { | |
| 696 | + | cleanupTestData(t) | |
| 697 | + | ||
| 698 | + | user, _ := testDB.RegisterUser("userpostsowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI userpostsowner", "comment") | |
| 699 | + | now := time.Now() | |
| 700 | + | ||
| 701 | + | _ = mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "userpost1.md", Slug: "userpost1", Title: "User Post 1", Space: "prose", PublishAt: &now}) | |
| 702 | + | _ = mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "userpost2.md", Slug: "userpost2", Title: "User Post 2", Space: "prose", PublishAt: &now}) | |
| 703 | + | ||
| 704 | + | pager := &db.Pager{Num: 10, Page: 0} | |
| 705 | + | result, err := testDB.FindPostsByUser(pager, user.ID, "prose") | |
| 706 | + | if err != nil { | |
| 707 | + | t.Fatalf("FindPostsByUser failed: %v", err) | |
| 708 | + | } | |
| 709 | + | if len(result.Data) != 2 { | |
| 710 | + | t.Errorf("expected 2 posts, got %d", len(result.Data)) | |
| 711 | + | } | |
| 712 | + | } | |
| 713 | + | ||
| 714 | + | func TestFindAllPostsByUser(t *testing.T) { | |
| 715 | + | cleanupTestData(t) | |
| 716 | + | ||
| 717 | + | user, _ := testDB.RegisterUser("allpostsowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI allpostsowner", "comment") | |
| 718 | + | ||
| 719 | + | _ = mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "allpost1.md", Slug: "allpost1", Title: "All Post 1", Space: "prose"}) | |
| 720 | + | _ = mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "allpost2.md", Slug: "allpost2", Title: "All Post 2", Space: "prose"}) | |
| 721 | + | ||
| 722 | + | posts, err := testDB.FindAllPostsByUser(user.ID, "prose") | |
| 723 | + | if err != nil { | |
| 724 | + | t.Fatalf("FindAllPostsByUser failed: %v", err) | |
| 725 | + | } | |
| 726 | + | if len(posts) != 2 { | |
| 727 | + | t.Errorf("expected 2 posts, got %d", len(posts)) | |
| 728 | + | } | |
| 729 | + | } | |
| 730 | + | ||
| 731 | + | func TestFindUsersWithPost(t *testing.T) { | |
| 732 | + | cleanupTestData(t) | |
| 733 | + | ||
| 734 | + | user, _ := testDB.RegisterUser("feedspostowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI feedspostowner", "comment") | |
| 735 | + | ||
| 736 | + | _ = mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "feed.txt", Slug: "feed", Title: "Feed", Space: "feeds"}) | |
| 737 | + | ||
| 738 | + | users, err := testDB.FindUsersWithPost("feeds") | |
| 739 | + | if err != nil { | |
| 740 | + | t.Fatalf("FindUsersWithPost failed: %v", err) | |
| 741 | + | } | |
| 742 | + | if len(users) != 1 { | |
| 743 | + | t.Errorf("expected 1 user, got %d", len(users)) | |
| 744 | + | } | |
| 745 | + | } | |
| 746 | + | ||
| 747 | + | func TestFindExpiredPosts(t *testing.T) { | |
| 748 | + | cleanupTestData(t) | |
| 749 | + | ||
| 750 | + | user, _ := testDB.RegisterUser("expiredpostowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI expiredpostowner", "comment") | |
| 751 | + | ||
| 752 | + | expired := time.Now().Add(-24 * time.Hour) | |
| 753 | + | _ = mustInsertPost(t, &db.Post{ | |
| 754 | + | UserID: user.ID, | |
| 755 | + | Filename: "expired.txt", | |
| 756 | + | Slug: "expired", | |
| 757 | + | Title: "Expired", | |
| 758 | + | Space: "pastes", | |
| 759 | + | ExpiresAt: &expired, | |
| 760 | + | }) | |
| 761 | + | ||
| 762 | + | posts, err := testDB.FindExpiredPosts("pastes") | |
| 763 | + | if err != nil { | |
| 764 | + | t.Fatalf("FindExpiredPosts failed: %v", err) | |
| 765 | + | } | |
| 766 | + | if len(posts) != 1 { | |
| 767 | + | t.Errorf("expected 1 expired post, got %d", len(posts)) | |
| 768 | + | } | |
| 769 | + | } | |
| 770 | + | ||
| 771 | + | func TestFindPostsByFeed(t *testing.T) { | |
| 772 | + | cleanupTestData(t) | |
| 773 | + | ||
| 774 | + | user, _ := testDB.RegisterUser("feedowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI feedowner", "comment") | |
| 775 | + | ||
| 776 | + | now := time.Now() | |
| 777 | + | _ = mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "feedpost.md", Slug: "feedpost", Title: "Feed Post", Space: "prose", PublishAt: &now}) | |
| 778 | + | ||
| 779 | + | pager := &db.Pager{Num: 10, Page: 0} | |
| 780 | + | result, err := testDB.FindPostsByFeed(pager, "prose") | |
| 781 | + | if err != nil { | |
| 782 | + | t.Fatalf("FindPostsByFeed failed: %v", err) | |
| 783 | + | } | |
| 784 | + | if len(result.Data) < 1 { | |
| 785 | + | t.Errorf("expected at least 1 post in feed, got %d", len(result.Data)) | |
| 786 | + | } | |
| 787 | + | } | |
| 788 | + | ||
| 789 | + | // ============ Tags Tests ============ | |
| 790 | + | ||
| 791 | + | func TestReplaceTagsByPost(t *testing.T) { | |
| 792 | + | cleanupTestData(t) | |
| 793 | + | ||
| 794 | + | user, _ := testDB.RegisterUser("tagspostowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI tagspostowner", "comment") | |
| 795 | + | post := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "tagged.md", Slug: "tagged", Title: "Tagged", Space: "prose"}) | |
| 796 | + | ||
| 797 | + | err := testDB.ReplaceTagsByPost([]string{"tag1", "tag2"}, post.ID) | |
| 798 | + | if err != nil { | |
| 799 | + | t.Fatalf("ReplaceTagsByPost failed: %v", err) | |
| 800 | + | } | |
| 801 | + | ||
| 802 | + | found, _ := testDB.FindPostWithFilename("tagged.md", user.ID, "prose") | |
| 803 | + | if len(found.Tags) != 2 { | |
| 804 | + | t.Errorf("expected 2 tags, got %d", len(found.Tags)) | |
| 805 | + | } | |
| 806 | + | } | |
| 807 | + | ||
| 808 | + | func TestFindUserPostsByTag(t *testing.T) { | |
| 809 | + | cleanupTestData(t) | |
| 810 | + | ||
| 811 | + | user, _ := testDB.RegisterUser("usertagowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI usertagowner", "comment") | |
| 812 | + | now := time.Now() | |
| 813 | + | post := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "usertag.md", Slug: "usertag", Title: "User Tag", Space: "prose", PublishAt: &now}) | |
| 814 | + | _ = testDB.ReplaceTagsByPost([]string{"mytag"}, post.ID) | |
| 815 | + | ||
| 816 | + | pager := &db.Pager{Num: 10, Page: 0} | |
| 817 | + | result, err := testDB.FindUserPostsByTag(pager, "mytag", user.ID, "prose") | |
| 818 | + | if err != nil { | |
| 819 | + | t.Fatalf("FindUserPostsByTag failed: %v", err) | |
| 820 | + | } | |
| 821 | + | if len(result.Data) != 1 { | |
| 822 | + | t.Errorf("expected 1 post with tag, got %d", len(result.Data)) | |
| 823 | + | } | |
| 824 | + | } | |
| 825 | + | ||
| 826 | + | func TestFindPostsByTag(t *testing.T) { | |
| 827 | + | cleanupTestData(t) | |
| 828 | + | ||
| 829 | + | user, _ := testDB.RegisterUser("tagsearchowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI tagsearchowner", "comment") | |
| 830 | + | now := time.Now() | |
| 831 | + | post := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "tagsearch.md", Slug: "tagsearch", Title: "Tag Search", Space: "prose", PublishAt: &now}) | |
| 832 | + | _ = testDB.ReplaceTagsByPost([]string{"searchtag"}, post.ID) | |
| 833 | + | ||
| 834 | + | pager := &db.Pager{Num: 10, Page: 0} | |
| 835 | + | result, err := testDB.FindPostsByTag(pager, "searchtag", "prose") | |
| 836 | + | if err != nil { | |
| 837 | + | t.Fatalf("FindPostsByTag failed: %v", err) | |
| 838 | + | } | |
| 839 | + | if len(result.Data) != 1 { | |
| 840 | + | t.Errorf("expected 1 post with tag, got %d", len(result.Data)) | |
| 841 | + | } | |
| 842 | + | } | |
| 843 | + | ||
| 844 | + | func TestFindPopularTags(t *testing.T) { | |
| 845 | + | cleanupTestData(t) | |
| 846 | + | ||
| 847 | + | user, _ := testDB.RegisterUser("populartagowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI populartagowner", "comment") | |
| 848 | + | post1 := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "pop1.md", Slug: "pop1", Title: "Pop 1", Space: "prose"}) | |
| 849 | + | post2 := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "pop2.md", Slug: "pop2", Title: "Pop 2", Space: "prose"}) | |
| 850 | + | _ = testDB.ReplaceTagsByPost([]string{"popular"}, post1.ID) | |
| 851 | + | _ = testDB.ReplaceTagsByPost([]string{"popular"}, post2.ID) | |
| 852 | + | ||
| 853 | + | tags, err := testDB.FindPopularTags("prose") | |
| 854 | + | if err != nil { | |
| 855 | + | t.Fatalf("FindPopularTags failed: %v", err) | |
| 856 | + | } | |
| 857 | + | if len(tags) < 1 { | |
| 858 | + | t.Errorf("expected at least 1 popular tag, got %d", len(tags)) | |
| 859 | + | } | |
| 860 | + | } | |
| 861 | + | ||
| 862 | + | // ============ Aliases Tests ============ | |
| 863 | + | ||
| 864 | + | func TestReplaceAliasesByPost(t *testing.T) { | |
| 865 | + | cleanupTestData(t) | |
| 866 | + | ||
| 867 | + | user, _ := testDB.RegisterUser("aliasowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI aliasowner", "comment") | |
| 868 | + | post := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "aliased.md", Slug: "aliased", Title: "Aliased", Space: "prose"}) | |
| 869 | + | ||
| 870 | + | err := testDB.ReplaceAliasesByPost([]string{"alias1", "alias2"}, post.ID) | |
| 871 | + | if err != nil { | |
| 872 | + | t.Fatalf("ReplaceAliasesByPost failed: %v", err) | |
| 873 | + | } | |
| 874 | + | } | |
| 875 | + | ||
| 876 | + | func TestFindPostWithSlug_Alias(t *testing.T) { | |
| 877 | + | cleanupTestData(t) | |
| 878 | + | ||
| 879 | + | user, _ := testDB.RegisterUser("aliassearchowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI aliassearchowner", "comment") | |
| 880 | + | post := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "original.md", Slug: "original", Title: "Original", Space: "prose"}) | |
| 881 | + | _ = testDB.ReplaceAliasesByPost([]string{"my-alias"}, post.ID) | |
| 882 | + | ||
| 883 | + | found, err := testDB.FindPostWithSlug("my-alias", user.ID, "prose") | |
| 884 | + | if err != nil { | |
| 885 | + | t.Fatalf("FindPostWithSlug for alias failed: %v", err) | |
| 886 | + | } | |
| 887 | + | if found.Title != "Original" { | |
| 888 | + | t.Errorf("expected title 'Original', got '%s'", found.Title) | |
| 889 | + | } | |
| 890 | + | } | |
| 891 | + | ||
| 892 | + | // ============ Analytics Tests ============ | |
| 893 | + | ||
| 894 | + | func TestInsertVisit(t *testing.T) { | |
| 895 | + | cleanupTestData(t) | |
| 896 | + | ||
| 897 | + | user, _ := testDB.RegisterUser("visitowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI visitowner", "comment") | |
| 898 | + | ||
| 899 | + | visit := &db.AnalyticsVisits{ | |
| 900 | + | UserID: user.ID, | |
| 901 | + | Host: "example.com", | |
| 902 | + | Path: "/test", | |
| 903 | + | IpAddress: "192.168.1.1", | |
| 904 | + | UserAgent: "TestAgent/1.0", | |
| 905 | + | Referer: "https://referrer.com", | |
| 906 | + | Status: 200, | |
| 907 | + | } | |
| 908 | + | ||
| 909 | + | err := testDB.InsertVisit(visit) | |
| 910 | + | if err != nil { | |
| 911 | + | t.Fatalf("InsertVisit failed: %v", err) | |
| 912 | + | } | |
| 913 | + | } | |
| 914 | + | ||
| 915 | + | func TestVisitSummary(t *testing.T) { | |
| 916 | + | cleanupTestData(t) | |
| 917 | + | ||
| 918 | + | user, _ := testDB.RegisterUser("summaryowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI summaryowner", "comment") | |
| 919 | + | ||
| 920 | + | visit := &db.AnalyticsVisits{ | |
| 921 | + | UserID: user.ID, | |
| 922 | + | Host: "summary.com", | |
| 923 | + | Path: "/page", | |
| 924 | + | IpAddress: "192.168.1.2", | |
| 925 | + | Status: 200, | |
| 926 | + | } | |
| 927 | + | _ = testDB.InsertVisit(visit) | |
| 928 | + | ||
| 929 | + | opts := &db.SummaryOpts{ | |
| 930 | + | Interval: "day", | |
| 931 | + | Origin: time.Now().Add(-24 * time.Hour), | |
| 932 | + | Host: "summary.com", | |
| 933 | + | UserID: user.ID, | |
| 934 | + | } | |
| 935 | + | ||
| 936 | + | summary, err := testDB.VisitSummary(opts) | |
| 937 | + | if err != nil { | |
| 938 | + | t.Fatalf("VisitSummary failed: %v", err) | |
| 939 | + | } | |
| 940 | + | if summary == nil { | |
| 941 | + | t.Error("expected summary, got nil") | |
| 942 | + | } | |
| 943 | + | } | |
| 944 | + | ||
| 945 | + | func TestFindVisitSiteList(t *testing.T) { | |
| 946 | + | cleanupTestData(t) | |
| 947 | + | ||
| 948 | + | user, _ := testDB.RegisterUser("sitelistowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI sitelistowner", "comment") | |
| 949 | + | ||
| 950 | + | _ = testDB.InsertVisit(&db.AnalyticsVisits{ | |
| 951 | + | UserID: user.ID, | |
| 952 | + | Host: "site1.com", | |
| 953 | + | Path: "/", | |
| 954 | + | IpAddress: "192.168.1.3", | |
| 955 | + | Status: 200, | |
| 956 | + | }) | |
| 957 | + | ||
| 958 | + | opts := &db.SummaryOpts{UserID: user.ID} | |
| 959 | + | sites, err := testDB.FindVisitSiteList(opts) | |
| 960 | + | if err != nil { | |
| 961 | + | t.Fatalf("FindVisitSiteList failed: %v", err) | |
| 962 | + | } | |
| 963 | + | if len(sites) < 1 { | |
| 964 | + | t.Errorf("expected at least 1 site, got %d", len(sites)) | |
| 965 | + | } | |
| 966 | + | } | |
| 967 | + | ||
| 968 | + | func TestVisitUrlNotFound(t *testing.T) { | |
| 969 | + | cleanupTestData(t) | |
| 970 | + | ||
| 971 | + | user, _ := testDB.RegisterUser("notfoundowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI notfoundowner", "comment") | |
| 972 | + | ||
| 973 | + | _ = testDB.InsertVisit(&db.AnalyticsVisits{ | |
| 974 | + | UserID: user.ID, | |
| 975 | + | Host: "notfound.com", | |
| 976 | + | Path: "/missing", | |
| 977 | + | IpAddress: "192.168.1.4", | |
| 978 | + | Status: 404, | |
| 979 | + | }) | |
| 980 | + | ||
| 981 | + | opts := &db.SummaryOpts{ | |
| 982 | + | Origin: time.Now().Add(-24 * time.Hour), | |
| 983 | + | Host: "notfound.com", | |
| 984 | + | UserID: user.ID, | |
| 985 | + | } | |
| 986 | + | notFound, err := testDB.VisitUrlNotFound(opts) | |
| 987 | + | if err != nil { | |
| 988 | + | t.Fatalf("VisitUrlNotFound failed: %v", err) | |
| 989 | + | } | |
| 990 | + | if len(notFound) < 1 { | |
| 991 | + | t.Errorf("expected at least 1 not found URL, got %d", len(notFound)) | |
| 992 | + | } | |
| 993 | + | } | |
| 994 | + | ||
| 995 | + | // ============ Features Tests ============ | |
| 996 | + | ||
| 997 | + | func TestInsertFeature(t *testing.T) { | |
| 998 | + | cleanupTestData(t) | |
| 999 | + | ||
| 1000 | + | user, _ := testDB.RegisterUser("featureowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI featureowner", "comment") | |
| 1001 | + | ||
| 1002 | + | expiresAt := time.Now().Add(365 * 24 * time.Hour) | |
| 1003 | + | feature, err := testDB.InsertFeature(user.ID, "plus", expiresAt) | |
| 1004 | + | if err != nil { | |
| 1005 | + | t.Fatalf("InsertFeature failed: %v", err) | |
| 1006 | + | } | |
| 1007 | + | if feature.Name != "plus" { | |
| 1008 | + | t.Errorf("expected feature name 'plus', got '%s'", feature.Name) | |
| 1009 | + | } | |
| 1010 | + | } | |
| 1011 | + | ||
| 1012 | + | func TestFindFeature(t *testing.T) { | |
| 1013 | + | cleanupTestData(t) | |
| 1014 | + | ||
| 1015 | + | user, _ := testDB.RegisterUser("findfeatureowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI findfeatureowner", "comment") | |
| 1016 | + | expiresAt := time.Now().Add(365 * 24 * time.Hour) | |
| 1017 | + | _, _ = testDB.InsertFeature(user.ID, "plus", expiresAt) | |
| 1018 | + | ||
| 1019 | + | feature, err := testDB.FindFeature(user.ID, "plus") | |
| 1020 | + | if err != nil { | |
| 1021 | + | t.Fatalf("FindFeature failed: %v", err) | |
| 1022 | + | } | |
| 1023 | + | if feature.Name != "plus" { | |
| 1024 | + | t.Errorf("expected feature name 'plus', got '%s'", feature.Name) | |
| 1025 | + | } | |
| 1026 | + | } | |
| 1027 | + | ||
| 1028 | + | func TestFindFeaturesByUser(t *testing.T) { | |
| 1029 | + | cleanupTestData(t) | |
| 1030 | + | ||
| 1031 | + | user, _ := testDB.RegisterUser("featuresowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI featuresowner", "comment") | |
| 1032 | + | expiresAt := time.Now().Add(365 * 24 * time.Hour) | |
| 1033 | + | _, _ = testDB.InsertFeature(user.ID, "plus", expiresAt) | |
| 1034 | + | _, _ = testDB.InsertFeature(user.ID, "pro", expiresAt) | |
| 1035 | + | ||
| 1036 | + | features, err := testDB.FindFeaturesByUser(user.ID) | |
| 1037 | + | if err != nil { | |
| 1038 | + | t.Fatalf("FindFeaturesByUser failed: %v", err) | |
| 1039 | + | } | |
| 1040 | + | if len(features) != 2 { | |
| 1041 | + | t.Errorf("expected 2 features, got %d", len(features)) | |
| 1042 | + | } | |
| 1043 | + | } | |
| 1044 | + | ||
| 1045 | + | func TestHasFeatureByUser(t *testing.T) { | |
| 1046 | + | cleanupTestData(t) | |
| 1047 | + | ||
| 1048 | + | user, _ := testDB.RegisterUser("hasfeatureowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI hasfeatureowner", "comment") | |
| 1049 | + | expiresAt := time.Now().Add(365 * 24 * time.Hour) | |
| 1050 | + | _, _ = testDB.InsertFeature(user.ID, "plus", expiresAt) | |
| 1051 | + | ||
| 1052 | + | has := testDB.HasFeatureByUser(user.ID, "plus") | |
| 1053 | + | if !has { | |
| 1054 | + | t.Error("expected HasFeatureByUser to return true") | |
| 1055 | + | } | |
| 1056 | + | ||
| 1057 | + | hasNot := testDB.HasFeatureByUser(user.ID, "nonexistent") | |
| 1058 | + | if hasNot { | |
| 1059 | + | t.Error("expected HasFeatureByUser to return false for nonexistent feature") | |
| 1060 | + | } | |
| 1061 | + | } | |
| 1062 | + | ||
| 1063 | + | func TestRemoveFeature(t *testing.T) { | |
| 1064 | + | cleanupTestData(t) | |
| 1065 | + | ||
| 1066 | + | user, _ := testDB.RegisterUser("removefeatureowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI removefeatureowner", "comment") | |
| 1067 | + | expiresAt := time.Now().Add(365 * 24 * time.Hour) | |
| 1068 | + | _, _ = testDB.InsertFeature(user.ID, "plus", expiresAt) | |
| 1069 | + | ||
| 1070 | + | err := testDB.RemoveFeature(user.ID, "plus") | |
| 1071 | + | if err != nil { | |
| 1072 | + | t.Fatalf("RemoveFeature failed: %v", err) | |
| 1073 | + | } | |
| 1074 | + | ||
| 1075 | + | _, err = testDB.FindFeature(user.ID, "plus") | |
| 1076 | + | if err == nil { | |
| 1077 | + | t.Error("expected error finding removed feature, got nil") | |
| 1078 | + | } | |
| 1079 | + | } | |
| 1080 | + | ||
| 1081 | + | func TestAddPicoPlusUser(t *testing.T) { | |
| 1082 | + | cleanupTestData(t) | |
| 1083 | + | ||
| 1084 | + | _, _ = testDB.RegisterUser("picoplusowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI picoplusowner", "comment") | |
| 1085 | + | ||
| 1086 | + | err := testDB.AddPicoPlusUser("picoplusowner", "test@example.com", "stripe", "tx123") | |
| 1087 | + | if err != nil { | |
| 1088 | + | t.Fatalf("AddPicoPlusUser failed: %v", err) | |
| 1089 | + | } | |
| 1090 | + | } | |
| 1091 | + | ||
| 1092 | + | // ============ Feed Items Tests ============ | |
| 1093 | + | ||
| 1094 | + | func TestInsertFeedItems(t *testing.T) { | |
| 1095 | + | cleanupTestData(t) | |
| 1096 | + | ||
| 1097 | + | user, _ := testDB.RegisterUser("feeditemsowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI feeditemsowner", "comment") | |
| 1098 | + | post := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "feed.txt", Slug: "feed", Title: "Feed", Space: "feeds"}) | |
| 1099 | + | ||
| 1100 | + | items := []*db.FeedItem{ | |
| 1101 | + | {PostID: post.ID, GUID: "guid-1", Data: db.FeedItemData{Title: "Item 1", Link: "http://example.com/1"}}, | |
| 1102 | + | {PostID: post.ID, GUID: "guid-2", Data: db.FeedItemData{Title: "Item 2", Link: "http://example.com/2"}}, | |
| 1103 | + | } | |
| 1104 | + | ||
| 1105 | + | err := testDB.InsertFeedItems(post.ID, items) | |
| 1106 | + | if err != nil { | |
| 1107 | + | t.Fatalf("InsertFeedItems failed: %v", err) | |
| 1108 | + | } | |
| 1109 | + | } | |
| 1110 | + | ||
| 1111 | + | func TestFindFeedItemsByPostID(t *testing.T) { | |
| 1112 | + | cleanupTestData(t) | |
| 1113 | + | ||
| 1114 | + | user, _ := testDB.RegisterUser("findfeeditemsowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI findfeeditemsowner", "comment") | |
| 1115 | + | post := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "findfeed.txt", Slug: "findfeed", Title: "Find Feed", Space: "feeds"}) | |
| 1116 | + | ||
| 1117 | + | items := []*db.FeedItem{ | |
| 1118 | + | {PostID: post.ID, GUID: "find-guid-1", Data: db.FeedItemData{Title: "Find Item 1"}}, | |
| 1119 | + | } | |
| 1120 | + | _ = testDB.InsertFeedItems(post.ID, items) | |
| 1121 | + | ||
| 1122 | + | found, err := testDB.FindFeedItemsByPostID(post.ID) | |
| 1123 | + | if err != nil { | |
| 1124 | + | t.Fatalf("FindFeedItemsByPostID failed: %v", err) | |
| 1125 | + | } | |
| 1126 | + | if len(found) != 1 { | |
| 1127 | + | t.Errorf("expected 1 feed item, got %d", len(found)) | |
| 1128 | + | } | |
| 1129 | + | } | |
| 1130 | + | ||
| 1131 | + | // ============ Projects Tests ============ | |
| 1132 | + | ||
| 1133 | + | func TestUpsertProject(t *testing.T) { | |
| 1134 | + | cleanupTestData(t) | |
| 1135 | + | ||
| 1136 | + | user, _ := testDB.RegisterUser("projectowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI projectowner", "comment") | |
| 1137 | + | ||
| 1138 | + | project, err := testDB.UpsertProject(user.ID, "my-project", "my-project") | |
| 1139 | + | if err != nil { | |
| 1140 | + | t.Fatalf("UpsertProject failed: %v", err) | |
| 1141 | + | } | |
| 1142 | + | if project.Name != "my-project" { | |
| 1143 | + | t.Errorf("expected project name 'my-project', got '%s'", project.Name) | |
| 1144 | + | } | |
| 1145 | + | ||
| 1146 | + | project2, err := testDB.UpsertProject(user.ID, "my-project", "my-project") | |
| 1147 | + | if err != nil { | |
| 1148 | + | t.Fatalf("UpsertProject (update) failed: %v", err) | |
| 1149 | + | } | |
| 1150 | + | if project2.ID != project.ID { | |
| 1151 | + | t.Error("expected same project ID on upsert") | |
| 1152 | + | } | |
| 1153 | + | } | |
| 1154 | + | ||
| 1155 | + | func TestFindProjectByName(t *testing.T) { | |
| 1156 | + | cleanupTestData(t) | |
| 1157 | + | ||
| 1158 | + | user, _ := testDB.RegisterUser("findprojectowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI findprojectowner", "comment") | |
| 1159 | + | _, _ = testDB.UpsertProject(user.ID, "findme-project", "findme-project") | |
| 1160 | + | ||
| 1161 | + | project, err := testDB.FindProjectByName(user.ID, "findme-project") | |
| 1162 | + | if err != nil { | |
| 1163 | + | t.Fatalf("FindProjectByName failed: %v", err) | |
| 1164 | + | } | |
| 1165 | + | if project.Name != "findme-project" { | |
| 1166 | + | t.Errorf("expected project name 'findme-project', got '%s'", project.Name) | |
| 1167 | + | } | |
| 1168 | + | } | |
| 1169 | + | ||
| 1170 | + | // ============ User Stats Tests ============ | |
| 1171 | + | ||
| 1172 | + | func TestFindUserStats(t *testing.T) { | |
| 1173 | + | cleanupTestData(t) | |
| 1174 | + | ||
| 1175 | + | user, _ := testDB.RegisterUser("statsowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI statsowner", "comment") | |
| 1176 | + | _ = mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "stat.md", Slug: "stat", Title: "Stat", Space: "prose"}) | |
| 1177 | + | _, _ = testDB.UpsertProject(user.ID, "stat-project", "stat-project") | |
| 1178 | + | ||
| 1179 | + | stats, err := testDB.FindUserStats(user.ID) | |
| 1180 | + | if err != nil { | |
| 1181 | + | t.Fatalf("FindUserStats failed: %v", err) | |
| 1182 | + | } | |
| 1183 | + | if stats.Prose.Num != 1 { | |
| 1184 | + | t.Errorf("expected 1 prose post, got %d", stats.Prose.Num) | |
| 1185 | + | } | |
| 1186 | + | if stats.Pages.Num != 1 { | |
| 1187 | + | t.Errorf("expected 1 project, got %d", stats.Pages.Num) | |
| 1188 | + | } | |
| 1189 | + | } | |
| 1190 | + | ||
| 1191 | + | // ============ Tuns Event Logs Tests ============ | |
| 1192 | + | ||
| 1193 | + | func TestInsertTunsEventLog(t *testing.T) { | |
| 1194 | + | cleanupTestData(t) | |
| 1195 | + | ||
| 1196 | + | user, _ := testDB.RegisterUser("tunsowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI tunsowner", "comment") | |
| 1197 | + | ||
| 1198 | + | log := &db.TunsEventLog{ | |
| 1199 | + | UserId: user.ID, | |
| 1200 | + | ServerID: "server-1", | |
| 1201 | + | RemoteAddr: "192.168.1.1:1234", | |
| 1202 | + | EventType: "connect", | |
| 1203 | + | TunnelType: "http", | |
| 1204 | + | ConnectionType: "tcp", | |
| 1205 | + | TunnelID: "tunnel-123", | |
| 1206 | + | } | |
| 1207 | + | ||
| 1208 | + | err := testDB.InsertTunsEventLog(log) | |
| 1209 | + | if err != nil { | |
| 1210 | + | t.Fatalf("InsertTunsEventLog failed: %v", err) | |
| 1211 | + | } | |
| 1212 | + | } | |
| 1213 | + | ||
| 1214 | + | func TestFindTunsEventLogs(t *testing.T) { | |
| 1215 | + | cleanupTestData(t) | |
| 1216 | + | ||
| 1217 | + | user, _ := testDB.RegisterUser("findtunsowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI findtunsowner", "comment") | |
| 1218 | + | _ = testDB.InsertTunsEventLog(&db.TunsEventLog{ | |
| 1219 | + | UserId: user.ID, | |
| 1220 | + | ServerID: "server-1", | |
| 1221 | + | RemoteAddr: "192.168.1.1:1234", | |
| 1222 | + | EventType: "connect", | |
| 1223 | + | TunnelType: "http", | |
| 1224 | + | ConnectionType: "tcp", | |
| 1225 | + | TunnelID: "tunnel-456", | |
| 1226 | + | }) | |
| 1227 | + | ||
| 1228 | + | logs, err := testDB.FindTunsEventLogs(user.ID) | |
| 1229 | + | if err != nil { | |
| 1230 | + | t.Fatalf("FindTunsEventLogs failed: %v", err) | |
| 1231 | + | } | |
| 1232 | + | if len(logs) != 1 { | |
| 1233 | + | t.Errorf("expected 1 log, got %d", len(logs)) | |
| 1234 | + | } | |
| 1235 | + | } | |
| 1236 | + | ||
| 1237 | + | func TestFindTunsEventLogsByAddr(t *testing.T) { | |
| 1238 | + | cleanupTestData(t) | |
| 1239 | + | ||
| 1240 | + | user, _ := testDB.RegisterUser("tunsaddrowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI tunsaddrowner", "comment") | |
| 1241 | + | _ = testDB.InsertTunsEventLog(&db.TunsEventLog{ | |
| 1242 | + | UserId: user.ID, | |
| 1243 | + | ServerID: "server-1", | |
| 1244 | + | RemoteAddr: "192.168.1.1:1234", | |
| 1245 | + | EventType: "connect", | |
| 1246 | + | TunnelType: "http", | |
| 1247 | + | ConnectionType: "tcp", | |
| 1248 | + | TunnelID: "tunnel-789", | |
| 1249 | + | }) | |
| 1250 | + | ||
| 1251 | + | logs, err := testDB.FindTunsEventLogsByAddr(user.ID, "tunnel-789") | |
| 1252 | + | if err != nil { | |
| 1253 | + | t.Fatalf("FindTunsEventLogsByAddr failed: %v", err) | |
| 1254 | + | } | |
| 1255 | + | if len(logs) != 1 { | |
| 1256 | + | t.Errorf("expected 1 log, got %d", len(logs)) | |
| 1257 | + | } | |
| 1258 | + | } | |
| 1259 | + | ||
| 1260 | + | // ============ Access Logs Tests ============ | |
| 1261 | + | ||
| 1262 | + | func TestInsertAccessLog(t *testing.T) { | |
| 1263 | + | cleanupTestData(t) | |
| 1264 | + | ||
| 1265 | + | user, _ := testDB.RegisterUser("accesslogowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI accesslogowner", "comment") | |
| 1266 | + | ||
| 1267 | + | log := &db.AccessLog{ | |
| 1268 | + | UserID: user.ID, | |
| 1269 | + | Service: "pgs", | |
| 1270 | + | Pubkey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI accesslogowner", | |
| 1271 | + | Identity: "accesslogowner", | |
| 1272 | + | } | |
| 1273 | + | ||
| 1274 | + | err := testDB.InsertAccessLog(log) | |
| 1275 | + | if err != nil { | |
| 1276 | + | t.Fatalf("InsertAccessLog failed: %v", err) | |
| 1277 | + | } | |
| 1278 | + | } | |
| 1279 | + | ||
| 1280 | + | func TestFindAccessLogs(t *testing.T) { | |
| 1281 | + | cleanupTestData(t) | |
| 1282 | + | ||
| 1283 | + | user, _ := testDB.RegisterUser("findaccesslogowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI findaccesslogowner", "comment") | |
| 1284 | + | _ = testDB.InsertAccessLog(&db.AccessLog{ | |
| 1285 | + | UserID: user.ID, | |
| 1286 | + | Service: "pgs", | |
| 1287 | + | Pubkey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI findaccesslogowner", | |
| 1288 | + | Identity: "findaccesslogowner", | |
| 1289 | + | }) | |
| 1290 | + | ||
| 1291 | + | fromDate := time.Now().Add(-24 * time.Hour) | |
| 1292 | + | logs, err := testDB.FindAccessLogs(user.ID, &fromDate) | |
| 1293 | + | if err != nil { | |
| 1294 | + | t.Fatalf("FindAccessLogs failed: %v", err) | |
| 1295 | + | } | |
| 1296 | + | if len(logs) != 1 { | |
| 1297 | + | t.Errorf("expected 1 log, got %d", len(logs)) | |
| 1298 | + | } | |
| 1299 | + | } | |
| 1300 | + | ||
| 1301 | + | func TestFindPubkeysInAccessLogs(t *testing.T) { | |
| 1302 | + | cleanupTestData(t) | |
| 1303 | + | ||
| 1304 | + | user, _ := testDB.RegisterUser("pubkeylogowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI pubkeylogowner", "comment") | |
| 1305 | + | _ = testDB.InsertAccessLog(&db.AccessLog{ | |
| 1306 | + | UserID: user.ID, | |
| 1307 | + | Service: "pgs", | |
| 1308 | + | Pubkey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI pubkeylogowner", | |
| 1309 | + | Identity: "pubkeylogowner", | |
| 1310 | + | }) | |
| 1311 | + | ||
| 1312 | + | pubkeys, err := testDB.FindPubkeysInAccessLogs(user.ID) | |
| 1313 | + | if err != nil { | |
| 1314 | + | t.Fatalf("FindPubkeysInAccessLogs failed: %v", err) | |
| 1315 | + | } | |
| 1316 | + | if len(pubkeys) != 1 { | |
| 1317 | + | t.Errorf("expected 1 pubkey, got %d", len(pubkeys)) | |
| 1318 | + | } | |
| 1319 | + | } | |
| 1320 | + | ||
| 1321 | + | func TestFindAccessLogsByPubkey(t *testing.T) { | |
| 1322 | + | cleanupTestData(t) | |
| 1323 | + | ||
| 1324 | + | user, _ := testDB.RegisterUser("accessbypubkeyowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI accessbypubkeyowner", "comment") | |
| 1325 | + | pubkey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI accessbypubkeyowner" | |
| 1326 | + | _ = testDB.InsertAccessLog(&db.AccessLog{ | |
| 1327 | + | UserID: user.ID, | |
| 1328 | + | Service: "pgs", | |
| 1329 | + | Pubkey: pubkey, | |
| 1330 | + | Identity: "accessbypubkeyowner", | |
| 1331 | + | }) | |
| 1332 | + | ||
| 1333 | + | fromDate := time.Now().Add(-24 * time.Hour) | |
| 1334 | + | logs, err := testDB.FindAccessLogsByPubkey(pubkey, &fromDate) | |
| 1335 | + | if err != nil { | |
| 1336 | + | t.Fatalf("FindAccessLogsByPubkey failed: %v", err) | |
| 1337 | + | } | |
| 1338 | + | if len(logs) != 1 { | |
| 1339 | + | t.Errorf("expected 1 log, got %d", len(logs)) | |
| 1340 | + | } | |
| 1341 | + | } | |
| 1342 | + | ||
| 1343 | + | // ============ JSONB Roundtrip Tests ============ | |
| 1344 | + | ||
| 1345 | + | func TestPostData_JSONBRoundtrip(t *testing.T) { | |
| 1346 | + | cleanupTestData(t) | |
| 1347 | + | ||
| 1348 | + | user, _ := testDB.RegisterUser("postdataowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI postdataowner", "comment") | |
| 1349 | + | ||
| 1350 | + | now := time.Now().Truncate(time.Second) | |
| 1351 | + | postData := db.PostData{ | |
| 1352 | + | ImgPath: "/images/test.png", | |
| 1353 | + | LastDigest: &now, | |
| 1354 | + | Attempts: 5, | |
| 1355 | + | } | |
| 1356 | + | ||
| 1357 | + | post := mustInsertPost(t, &db.Post{ | |
| 1358 | + | UserID: user.ID, | |
| 1359 | + | Filename: "jsonb.md", | |
| 1360 | + | Slug: "jsonb", | |
| 1361 | + | Title: "JSONB Test", | |
| 1362 | + | Space: "prose", | |
| 1363 | + | Data: postData, | |
| 1364 | + | }) | |
| 1365 | + | ||
| 1366 | + | found, err := testDB.FindPost(post.ID) | |
| 1367 | + | if err != nil { | |
| 1368 | + | t.Fatalf("FindPost failed: %v", err) | |
| 1369 | + | } | |
| 1370 | + | if found.Data.ImgPath != "/images/test.png" { | |
| 1371 | + | t.Errorf("expected ImgPath '/images/test.png', got '%s'", found.Data.ImgPath) | |
| 1372 | + | } | |
| 1373 | + | if found.Data.Attempts != 5 { | |
| 1374 | + | t.Errorf("expected Attempts 5, got %d", found.Data.Attempts) | |
| 1375 | + | } | |
| 1376 | + | } | |
| 1377 | + | ||
| 1378 | + | func TestProjectAcl_JSONBRoundtrip(t *testing.T) { | |
| 1379 | + | cleanupTestData(t) | |
| 1380 | + | ||
| 1381 | + | user, _ := testDB.RegisterUser("aclowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI aclowner", "comment") | |
| 1382 | + | ||
| 1383 | + | project, err := testDB.UpsertProject(user.ID, "acl-project", "acl-project") | |
| 1384 | + | if err != nil { | |
| 1385 | + | t.Fatalf("UpsertProject failed: %v", err) | |
| 1386 | + | } | |
| 1387 | + | ||
| 1388 | + | found, err := testDB.FindProjectByName(user.ID, "acl-project") | |
| 1389 | + | if err != nil { | |
| 1390 | + | t.Fatalf("FindProjectByName failed: %v", err) | |
| 1391 | + | } | |
| 1392 | + | if found.Acl.Type != "public" { | |
| 1393 | + | t.Errorf("expected Acl.Type 'public', got '%s'", found.Acl.Type) | |
| 1394 | + | } | |
| 1395 | + | _ = project | |
| 1396 | + | } | |
| 1397 | + | ||
| 1398 | + | func TestFeedItemData_JSONBRoundtrip(t *testing.T) { | |
| 1399 | + | cleanupTestData(t) | |
| 1400 | + | ||
| 1401 | + | user, _ := testDB.RegisterUser("feedjsonbowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI feedjsonbowner", "comment") | |
| 1402 | + | post := mustInsertPost(t, &db.Post{UserID: user.ID, Filename: "feedjsonb.txt", Slug: "feedjsonb", Title: "Feed JSONB", Space: "feeds"}) | |
| 1403 | + | ||
| 1404 | + | now := time.Now().Truncate(time.Second) | |
| 1405 | + | items := []*db.FeedItem{ | |
| 1406 | + | { | |
| 1407 | + | PostID: post.ID, | |
| 1408 | + | GUID: "jsonb-guid", | |
| 1409 | + | Data: db.FeedItemData{ | |
| 1410 | + | Title: "JSONB Item", | |
| 1411 | + | Description: "Description", | |
| 1412 | + | Content: "Content", | |
| 1413 | + | Link: "http://example.com", | |
| 1414 | + | PublishedAt: &now, | |
| 1415 | + | }, | |
| 1416 | + | }, | |
| 1417 | + | } | |
| 1418 | + | _ = testDB.InsertFeedItems(post.ID, items) | |
| 1419 | + | ||
| 1420 | + | found, err := testDB.FindFeedItemsByPostID(post.ID) | |
| 1421 | + | if err != nil { | |
| 1422 | + | t.Fatalf("FindFeedItemsByPostID failed: %v", err) | |
| 1423 | + | } | |
| 1424 | + | if len(found) != 1 { | |
| 1425 | + | t.Fatalf("expected 1 item, got %d", len(found)) | |
| 1426 | + | } | |
| 1427 | + | if found[0].Data.Title != "JSONB Item" { | |
| 1428 | + | t.Errorf("expected title 'JSONB Item', got '%s'", found[0].Data.Title) | |
| 1429 | + | } | |
| 1430 | + | } | |
| 1431 | + | ||
| 1432 | + | func TestFeatureFlagData_JSONBRoundtrip(t *testing.T) { | |
| 1433 | + | cleanupTestData(t) | |
| 1434 | + | ||
| 1435 | + | user, _ := testDB.RegisterUser("featurejsonbowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI featurejsonbowner", "comment") | |
| 1436 | + | ||
| 1437 | + | err := testDB.AddPicoPlusUser("featurejsonbowner", "test@example.com", "stripe", "tx456") | |
| 1438 | + | if err != nil { | |
| 1439 | + | t.Fatalf("AddPicoPlusUser failed: %v", err) | |
| 1440 | + | } | |
| 1441 | + | ||
| 1442 | + | feature, err := testDB.FindFeature(user.ID, "plus") | |
| 1443 | + | if err != nil { | |
| 1444 | + | t.Fatalf("FindFeature failed: %v", err) | |
| 1445 | + | } | |
| 1446 | + | if feature.Data.StorageMax != 10000000000 { | |
| 1447 | + | t.Errorf("expected StorageMax 10000000000, got %d", feature.Data.StorageMax) | |
| 1448 | + | } | |
| 1449 | + | if feature.Data.FileMax != 50000000 { | |
| 1450 | + | t.Errorf("expected FileMax 50000000, got %d", feature.Data.FileMax) | |
| 1451 | + | } | |
| 1452 | + | } | |
| 1453 | + | ||
| 1454 | + | func TestPaymentHistoryData_JSONBRoundtrip(t *testing.T) { | |
| 1455 | + | cleanupTestData(t) | |
| 1456 | + | ||
| 1457 | + | user, _ := testDB.RegisterUser("paymentjsonbowner", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI paymentjsonbowner", "comment") | |
| 1458 | + | ||
| 1459 | + | err := testDB.AddPicoPlusUser("paymentjsonbowner", "payment@example.com", "stripe", "tx789") | |
| 1460 | + | if err != nil { | |
| 1461 | + | t.Fatalf("AddPicoPlusUser failed: %v", err) | |
| 1462 | + | } | |
| 1463 | + | ||
| 1464 | + | var txId string | |
| 1465 | + | err = testDB.Db.QueryRow("SELECT data->>'tx_id' FROM payment_history WHERE user_id = $1", user.ID).Scan(&txId) | |
| 1466 | + | if err != nil { | |
| 1467 | + | t.Fatalf("failed to query payment history: %v", err) | |
| 1468 | + | } | |
| 1469 | + | if txId != "tx789" { | |
| 1470 | + | t.Errorf("expected tx_id 'tx789', got '%s'", txId) | |
| 1471 | + | } | |
| 1472 | + | } |
+13,
-74
| ... | ... | @@ -1,7 +1,6 @@ | |
| 1 | 1 | package stub | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | - | "database/sql" | |
| 5 | 4 | "fmt" | |
| 6 | 5 | "log/slog" | |
| 7 | 6 | "time" |
| ... | ... | @@ -29,27 +28,15 @@ func (me *StubDB) RegisterUser(username, pubkey, comment string) (*db.User, erro | |
| 29 | 28 | return nil, errNotImpl | |
| 30 | 29 | } | |
| 31 | 30 | ||
| 32 | - | func (me *StubDB) RemoveUsers(userIDs []string) error { | |
| 33 | - | return errNotImpl | |
| 34 | - | } | |
| 35 | - | ||
| 36 | - | func (me *StubDB) InsertPublicKey(userID, key, name string, tx *sql.Tx) error { | |
| 37 | - | return errNotImpl | |
| 38 | - | } | |
| 39 | - | ||
| 40 | 31 | func (me *StubDB) UpdatePublicKey(pubkeyID, name string) (*db.PublicKey, error) { | |
| 41 | 32 | return nil, errNotImpl | |
| 42 | 33 | } | |
| 43 | 34 | ||
| 44 | - | func (me *StubDB) FindPublicKeyForKey(key string) (*db.PublicKey, error) { | |
| 45 | - | return nil, errNotImpl | |
| 46 | - | } | |
| 47 | - | ||
| 48 | - | func (me *StubDB) FindPublicKey(pubkeyID string) (*db.PublicKey, error) { | |
| 49 | - | return nil, errNotImpl | |
| 35 | + | func (me *StubDB) InsertPublicKey(userID, key, name string) error { | |
| 36 | + | return errNotImpl | |
| 50 | 37 | } | |
| 51 | 38 | ||
| 52 | - | func (me *StubDB) FindKeysForUser(user *db.User) ([]*db.PublicKey, error) { | |
| 39 | + | func (me *StubDB) FindKeysByUser(user *db.User) ([]*db.PublicKey, error) { | |
| 53 | 40 | return []*db.PublicKey{}, errNotImpl | |
| 54 | 41 | } | |
| 55 | 42 |
| ... | ... | @@ -57,11 +44,7 @@ func (me *StubDB) RemoveKeys(keyIDs []string) error { | |
| 57 | 44 | return errNotImpl | |
| 58 | 45 | } | |
| 59 | 46 | ||
| 60 | - | func (me *StubDB) FindPostsBeforeDate(date *time.Time, space string) ([]*db.Post, error) { | |
| 61 | - | return []*db.Post{}, errNotImpl | |
| 62 | - | } | |
| 63 | - | ||
| 64 | - | func (me *StubDB) FindUserForKey(username string, key string) (*db.User, error) { | |
| 47 | + | func (me *StubDB) FindUserByKey(username string, key string) (*db.User, error) { | |
| 65 | 48 | return nil, errNotImpl | |
| 66 | 49 | } | |
| 67 | 50 |
| ... | ... | @@ -73,26 +56,14 @@ func (me *StubDB) FindUser(userID string) (*db.User, error) { | |
| 73 | 56 | return nil, errNotImpl | |
| 74 | 57 | } | |
| 75 | 58 | ||
| 76 | - | func (me *StubDB) ValidateName(name string) (bool, error) { | |
| 77 | - | return false, errNotImpl | |
| 78 | - | } | |
| 79 | - | ||
| 80 | 59 | func (me *StubDB) FindUserByName(name string) (*db.User, error) { | |
| 81 | 60 | return nil, errNotImpl | |
| 82 | 61 | } | |
| 83 | 62 | ||
| 84 | - | func (me *StubDB) FindUserForNameAndKey(name string, key string) (*db.User, error) { | |
| 63 | + | func (me *StubDB) FindUserByToken(token string) (*db.User, error) { | |
| 85 | 64 | return nil, errNotImpl | |
| 86 | 65 | } | |
| 87 | 66 | ||
| 88 | - | func (me *StubDB) FindUserForToken(token string) (*db.User, error) { | |
| 89 | - | return nil, errNotImpl | |
| 90 | - | } | |
| 91 | - | ||
| 92 | - | func (me *StubDB) SetUserName(userID string, name string) error { | |
| 93 | - | return errNotImpl | |
| 94 | - | } | |
| 95 | - | ||
| 96 | 67 | func (me *StubDB) FindPostWithFilename(filename string, persona_id string, space string) (*db.Post, error) { | |
| 97 | 68 | return nil, errNotImpl | |
| 98 | 69 | } |
| ... | ... | @@ -105,11 +76,7 @@ func (me *StubDB) FindPost(postID string) (*db.Post, error) { | |
| 105 | 76 | return nil, errNotImpl | |
| 106 | 77 | } | |
| 107 | 78 | ||
| 108 | - | func (me *StubDB) FindPostsForFeed(page *db.Pager, space string) (*db.Paginate[*db.Post], error) { | |
| 109 | - | return &db.Paginate[*db.Post]{}, errNotImpl | |
| 110 | - | } | |
| 111 | - | ||
| 112 | - | func (me *StubDB) FindAllUpdatedPosts(page *db.Pager, space string) (*db.Paginate[*db.Post], error) { | |
| 79 | + | func (me *StubDB) FindPostsByFeed(page *db.Pager, space string) (*db.Paginate[*db.Post], error) { | |
| 113 | 80 | return &db.Paginate[*db.Post]{}, errNotImpl | |
| 114 | 81 | } | |
| 115 | 82 |
| ... | ... | @@ -125,11 +92,11 @@ func (me *StubDB) RemovePosts(postIDs []string) error { | |
| 125 | 92 | return errNotImpl | |
| 126 | 93 | } | |
| 127 | 94 | ||
| 128 | - | func (me *StubDB) FindPostsForUser(page *db.Pager, userID string, space string) (*db.Paginate[*db.Post], error) { | |
| 95 | + | func (me *StubDB) FindPostsByUser(page *db.Pager, userID string, space string) (*db.Paginate[*db.Post], error) { | |
| 129 | 96 | return &db.Paginate[*db.Post]{}, errNotImpl | |
| 130 | 97 | } | |
| 131 | 98 | ||
| 132 | - | func (me *StubDB) FindAllPostsForUser(userID string, space string) ([]*db.Post, error) { | |
| 99 | + | func (me *StubDB) FindAllPostsByUser(userID string, space string) ([]*db.Post, error) { | |
| 133 | 100 | return []*db.Post{}, errNotImpl | |
| 134 | 101 | } | |
| 135 | 102 |
| ... | ... | @@ -141,10 +108,6 @@ func (me *StubDB) FindExpiredPosts(space string) ([]*db.Post, error) { | |
| 141 | 108 | return []*db.Post{}, errNotImpl | |
| 142 | 109 | } | |
| 143 | 110 | ||
| 144 | - | func (me *StubDB) FindUpdatedPostsForUser(userID string, space string) ([]*db.Post, error) { | |
| 145 | - | return []*db.Post{}, errNotImpl | |
| 146 | - | } | |
| 147 | - | ||
| 148 | 111 | func (me *StubDB) Close() error { | |
| 149 | 112 | return errNotImpl | |
| 150 | 113 | } |
| ... | ... | @@ -165,11 +128,11 @@ func (me *StubDB) FindUsers() ([]*db.User, error) { | |
| 165 | 128 | return []*db.User{}, errNotImpl | |
| 166 | 129 | } | |
| 167 | 130 | ||
| 168 | - | func (me *StubDB) ReplaceTagsForPost(tags []string, postID string) error { | |
| 131 | + | func (me *StubDB) ReplaceTagsByPost(tags []string, postID string) error { | |
| 169 | 132 | return errNotImpl | |
| 170 | 133 | } | |
| 171 | 134 | ||
| 172 | - | func (me *StubDB) ReplaceAliasesForPost(aliases []string, postID string) error { | |
| 135 | + | func (me *StubDB) ReplaceAliasesByPost(aliases []string, postID string) error { | |
| 173 | 136 | return errNotImpl | |
| 174 | 137 | } | |
| 175 | 138 |
| ... | ... | @@ -185,26 +148,18 @@ func (me *StubDB) FindPopularTags(space string) ([]string, error) { | |
| 185 | 148 | return []string{}, errNotImpl | |
| 186 | 149 | } | |
| 187 | 150 | ||
| 188 | - | func (me *StubDB) FindTagsForPost(postID string) ([]string, error) { | |
| 189 | - | return []string{}, errNotImpl | |
| 190 | - | } | |
| 191 | - | ||
| 192 | 151 | func (me *StubDB) FindFeature(userID string, feature string) (*db.FeatureFlag, error) { | |
| 193 | 152 | return nil, errNotImpl | |
| 194 | 153 | } | |
| 195 | 154 | ||
| 196 | - | func (me *StubDB) FindFeaturesForUser(userID string) ([]*db.FeatureFlag, error) { | |
| 155 | + | func (me *StubDB) FindFeaturesByUser(userID string) ([]*db.FeatureFlag, error) { | |
| 197 | 156 | return []*db.FeatureFlag{}, errNotImpl | |
| 198 | 157 | } | |
| 199 | 158 | ||
| 200 | - | func (me *StubDB) HasFeatureForUser(userID string, feature string) bool { | |
| 159 | + | func (me *StubDB) HasFeatureByUser(userID string, feature string) bool { | |
| 201 | 160 | return false | |
| 202 | 161 | } | |
| 203 | 162 | ||
| 204 | - | func (me *StubDB) FindTotalSizeForUser(userID string) (int, error) { | |
| 205 | - | return 0, errNotImpl | |
| 206 | - | } | |
| 207 | - | ||
| 208 | 163 | func (me *StubDB) InsertFeedItems(postID string, items []*db.FeedItem) error { | |
| 209 | 164 | return errNotImpl | |
| 210 | 165 | } |
| ... | ... | @@ -217,14 +172,6 @@ func (me *StubDB) UpsertProject(userID, name, projectDir string) (*db.Project, e | |
| 217 | 172 | return nil, errNotImpl | |
| 218 | 173 | } | |
| 219 | 174 | ||
| 220 | - | func (me *StubDB) InsertProject(userID, name, projectDir string) (string, error) { | |
| 221 | - | return "", errNotImpl | |
| 222 | - | } | |
| 223 | - | ||
| 224 | - | func (me *StubDB) UpdateProject(userID, name string) error { | |
| 225 | - | return errNotImpl | |
| 226 | - | } | |
| 227 | - | ||
| 228 | 175 | func (me *StubDB) FindProjectByName(userID, name string) (*db.Project, error) { | |
| 229 | 176 | return &db.Project{}, errNotImpl | |
| 230 | 177 | } |
| ... | ... | @@ -237,15 +184,11 @@ func (me *StubDB) UpsertToken(userID, name string) (string, error) { | |
| 237 | 184 | return "", errNotImpl | |
| 238 | 185 | } | |
| 239 | 186 | ||
| 240 | - | func (me *StubDB) FindTokenByName(userID, name string) (string, error) { | |
| 241 | - | return "", errNotImpl | |
| 242 | - | } | |
| 243 | - | ||
| 244 | 187 | func (me *StubDB) RemoveToken(tokenID string) error { | |
| 245 | 188 | return errNotImpl | |
| 246 | 189 | } | |
| 247 | 190 | ||
| 248 | - | func (me *StubDB) FindTokensForUser(userID string) ([]*db.Token, error) { | |
| 191 | + | func (me *StubDB) FindTokensByUser(userID string) ([]*db.Token, error) { | |
| 249 | 192 | return []*db.Token{}, errNotImpl | |
| 250 | 193 | } | |
| 251 | 194 |
| ... | ... | @@ -261,10 +204,6 @@ func (me *StubDB) AddPicoPlusUser(username, email, paymentType, txId string) err | |
| 261 | 204 | return errNotImpl | |
| 262 | 205 | } | |
| 263 | 206 | ||
| 264 | - | func (me *StubDB) FindTagsForUser(userID string, tag string) ([]string, error) { | |
| 265 | - | return []string{}, errNotImpl | |
| 266 | - | } | |
| 267 | - | ||
| 268 | 207 | func (me *StubDB) FindUserStats(userID string) (*db.UserStats, error) { | |
| 269 | 208 | return nil, errNotImpl | |
| 270 | 209 | } |
+4,
-4
| ... | ... | @@ -197,7 +197,7 @@ func (h *ScpUploadHandler) Write(s *pssh.SSHServerConnSession, entry *sendutils. | |
| 197 | 197 | "aliases", | |
| 198 | 198 | strings.Join(metadata.Aliases, ","), | |
| 199 | 199 | ) | |
| 200 | - | err = h.DBPool.ReplaceAliasesForPost(metadata.Aliases, post.ID) | |
| 200 | + | err = h.DBPool.ReplaceAliasesByPost(metadata.Aliases, post.ID) | |
| 201 | 201 | if err != nil { | |
| 202 | 202 | logger.Error("post could not replace aliases", "err", err.Error()) | |
| 203 | 203 | return "", fmt.Errorf("error for %s: %v", filename, err) |
| ... | ... | @@ -209,7 +209,7 @@ func (h *ScpUploadHandler) Write(s *pssh.SSHServerConnSession, entry *sendutils. | |
| 209 | 209 | "found post tags, replacing with old tags", | |
| 210 | 210 | "tags", strings.Join(metadata.Tags, ","), | |
| 211 | 211 | ) | |
| 212 | - | err = h.DBPool.ReplaceTagsForPost(metadata.Tags, post.ID) | |
| 212 | + | err = h.DBPool.ReplaceTagsByPost(metadata.Tags, post.ID) | |
| 213 | 213 | if err != nil { | |
| 214 | 214 | logger.Error("post could not replace tags", "err", err.Error()) | |
| 215 | 215 | return "", fmt.Errorf("error for %s: %v", filename, err) |
| ... | ... | @@ -249,7 +249,7 @@ func (h *ScpUploadHandler) Write(s *pssh.SSHServerConnSession, entry *sendutils. | |
| 249 | 249 | "found post tags, replacing with old tags", | |
| 250 | 250 | "tags", strings.Join(metadata.Tags, ","), | |
| 251 | 251 | ) | |
| 252 | - | err = h.DBPool.ReplaceTagsForPost(metadata.Tags, post.ID) | |
| 252 | + | err = h.DBPool.ReplaceTagsByPost(metadata.Tags, post.ID) | |
| 253 | 253 | if err != nil { | |
| 254 | 254 | logger.Error("post could not replace tags", "err", err.Error()) | |
| 255 | 255 | return "", fmt.Errorf("error for %s: %v", filename, err) |
| ... | ... | @@ -259,7 +259,7 @@ func (h *ScpUploadHandler) Write(s *pssh.SSHServerConnSession, entry *sendutils. | |
| 259 | 259 | "found post aliases, replacing with old aliases", | |
| 260 | 260 | "aliases", strings.Join(metadata.Aliases, ","), | |
| 261 | 261 | ) | |
| 262 | - | err = h.DBPool.ReplaceAliasesForPost(metadata.Aliases, post.ID) | |
| 262 | + | err = h.DBPool.ReplaceAliasesByPost(metadata.Aliases, post.ID) | |
| 263 | 263 | if err != nil { | |
| 264 | 264 | logger.Error("post could not replace aliases", "err", err.Error()) | |
| 265 | 265 | return "", fmt.Errorf("error for %s: %v", filename, err) |
+1,
-1
| ... | ... | @@ -151,7 +151,7 @@ func BaseList(s *pssh.SSHServerConnSession, fpath string, isDir bool, recursive | |
| 151 | 151 | }) | |
| 152 | 152 | ||
| 153 | 153 | for _, space := range spaces { | |
| 154 | - | curPosts, e := dbpool.FindAllPostsForUser(user.ID, space) | |
| 154 | + | curPosts, e := dbpool.FindAllPostsByUser(user.ID, space) | |
| 155 | 155 | if e != nil { | |
| 156 | 156 | err = e | |
| 157 | 157 | break |
| ... | ... | @@ -155,7 +155,7 @@ func CleanHost(raw string) (string, error) { | |
| 155 | 155 | var ErrAnalyticsDisabled = errors.New("owner does not have site analytics enabled") | |
| 156 | 156 | ||
| 157 | 157 | func AnalyticsVisitFromVisit(visit *db.AnalyticsVisits, dbpool db.DB, secret string) error { | |
| 158 | - | if !dbpool.HasFeatureForUser(visit.UserID, "analytics") { | |
| 158 | + | if !dbpool.HasFeatureByUser(visit.UserID, "analytics") { | |
| 159 | 159 | return ErrAnalyticsDisabled | |
| 160 | 160 | } | |
| 161 | 161 |
| ... | ... | @@ -206,7 +206,7 @@ func ipFromRequest(r *http.Request) string { | |
| 206 | 206 | } | |
| 207 | 207 | ||
| 208 | 208 | func AnalyticsVisitFromRequest(r *http.Request, dbpool db.DB, userID string) (*db.AnalyticsVisits, error) { | |
| 209 | - | if !dbpool.HasFeatureForUser(userID, "analytics") { | |
| 209 | + | if !dbpool.HasFeatureByUser(userID, "analytics") { | |
| 210 | 210 | return nil, ErrAnalyticsDisabled | |
| 211 | 211 | } | |
| 212 | 212 |
| ... | ... | @@ -77,15 +77,15 @@ type ApiConfig struct { | |
| 77 | 77 | } | |
| 78 | 78 | ||
| 79 | 79 | func (hc *ApiConfig) HasPrivilegedAccess(apiToken string) bool { | |
| 80 | - | user, err := hc.Dbpool.FindUserForToken(apiToken) | |
| 80 | + | user, err := hc.Dbpool.FindUserByToken(apiToken) | |
| 81 | 81 | if err != nil { | |
| 82 | 82 | return false | |
| 83 | 83 | } | |
| 84 | - | return hc.Dbpool.HasFeatureForUser(user.ID, "auth") | |
| 84 | + | return hc.Dbpool.HasFeatureByUser(user.ID, "auth") | |
| 85 | 85 | } | |
| 86 | 86 | ||
| 87 | 87 | func (hc *ApiConfig) HasPlusOrSpace(user *db.User, space string) bool { | |
| 88 | - | return hc.Dbpool.HasFeatureForUser(user.ID, "plus") || hc.Dbpool.HasFeatureForUser(user.ID, space) | |
| 88 | + | return hc.Dbpool.HasFeatureByUser(user.ID, "plus") || hc.Dbpool.HasFeatureByUser(user.ID, space) | |
| 89 | 89 | } | |
| 90 | 90 | ||
| 91 | 91 | func (hc *ApiConfig) CreateCtx(prevCtx context.Context, subdomain string) context.Context { |
+1,
-1
| ... | ... | @@ -393,7 +393,7 @@ func (m *AnalyticsPage) fetchSiteStats(site string, interval string) { | |
| 393 | 393 | } | |
| 394 | 394 | ||
| 395 | 395 | func (m *AnalyticsPage) fetchFeatures() error { | |
| 396 | - | features, err := m.shared.Dbpool.FindFeaturesForUser(m.shared.User.ID) | |
| 396 | + | features, err := m.shared.Dbpool.FindFeaturesByUser(m.shared.User.ID) | |
| 397 | 397 | m.features = features | |
| 398 | 398 | return err | |
| 399 | 399 | } |
+1,
-1
| ... | ... | @@ -127,7 +127,7 @@ func (m *FeaturesList) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 127 | 127 | } | |
| 128 | 128 | ||
| 129 | 129 | func (m *FeaturesList) fetchFeatures() error { | |
| 130 | - | features, err := m.shared.Dbpool.FindFeaturesForUser(m.shared.User.ID) | |
| 130 | + | features, err := m.shared.Dbpool.FindFeaturesByUser(m.shared.User.ID) | |
| 131 | 131 | m.features = features | |
| 132 | 132 | return err | |
| 133 | 133 | } |
+2,
-2
| ... | ... | @@ -43,7 +43,7 @@ func (m *PubkeysPage) Footer() []Shortcut { | |
| 43 | 43 | } | |
| 44 | 44 | ||
| 45 | 45 | func (m *PubkeysPage) fetchKeys() error { | |
| 46 | - | keys, err := m.shared.Dbpool.FindKeysForUser(m.shared.User) | |
| 46 | + | keys, err := m.shared.Dbpool.FindKeysByUser(m.shared.User) | |
| 47 | 47 | if err != nil { | |
| 48 | 48 | return err | |
| 49 | 49 |
| ... | ... | @@ -256,7 +256,7 @@ func (m *AddKeyPage) addPubkey(pubkey string) error { | |
| 256 | 256 | key := utils.KeyForKeyText(pk) | |
| 257 | 257 | ||
| 258 | 258 | return m.shared.Dbpool.InsertPublicKey( | |
| 259 | - | m.shared.User.ID, key, comment, nil, | |
| 259 | + | m.shared.User.ID, key, comment, | |
| 260 | 260 | ) | |
| 261 | 261 | } | |
| 262 | 262 |
+1,
-1
| ... | ... | @@ -41,7 +41,7 @@ func (m *TokensPage) Footer() []Shortcut { | |
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | 43 | func (m *TokensPage) fetchTokens() error { | |
| 44 | - | tokens, err := m.shared.Dbpool.FindTokensForUser(m.shared.User.ID) | |
| 44 | + | tokens, err := m.shared.Dbpool.FindTokensByUser(m.shared.User.ID) | |
| 45 | 45 | if err != nil { | |
| 46 | 46 | return err | |
| 47 | 47 |
+2,
-2
| ... | ... | @@ -289,7 +289,7 @@ func FindUser(shrd *SharedModel) (*db.User, error) { | |
| 289 | 289 | ||
| 290 | 290 | key := utils.KeyForKeyText(shrd.Session.PublicKey()) | |
| 291 | 291 | ||
| 292 | - | user, err := shrd.Dbpool.FindUserForKey(usr, key) | |
| 292 | + | user, err := shrd.Dbpool.FindUserByKey(usr, key) | |
| 293 | 293 | if err != nil { | |
| 294 | 294 | logger.Error("no user found for public key", "err", err.Error()) | |
| 295 | 295 | // we only want to throw an error for specific cases |
| ... | ... | @@ -304,7 +304,7 @@ func FindUser(shrd *SharedModel) (*db.User, error) { | |
| 304 | 304 | ||
| 305 | 305 | // impersonation | |
| 306 | 306 | if strings.HasPrefix(usr, adminPrefix) { | |
| 307 | - | hasFeature := shrd.Dbpool.HasFeatureForUser(user.ID, "admin") | |
| 307 | + | hasFeature := shrd.Dbpool.HasFeatureByUser(user.ID, "admin") | |
| 308 | 308 | if hasFeature { | |
| 309 | 309 | impersonate := strings.TrimPrefix(usr, adminPrefix) | |
| 310 | 310 | user, err = shrd.Dbpool.FindUserByName(impersonate) |