Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4895985390 | ||
|
|
a4a31cbc64 | ||
|
|
a545cefaea | ||
|
|
b2bb1f176f | ||
|
|
a93e10956b | ||
|
|
1c1479d455 | ||
|
|
b8aea51ab3 | ||
|
|
804c82637a | ||
|
|
6df584645b | ||
|
|
e38f108f0b |
@@ -7,7 +7,10 @@ Forum: Go-Backend (`cmd/kver`, `internal/`, Postgres), React-Frontend in
|
||||
## Arbeitsablauf nach jeder Änderung
|
||||
|
||||
1. **Prüfen**: `go build ./... && go test ./...` bzw. `npm run build` in
|
||||
`frontend/`; sichtbare Änderungen im Browser ansehen.
|
||||
`frontend/`; sichtbare Änderungen im Browser ansehen. Die DB-Tests
|
||||
brauchen `KVER_TEST_DSN` aus `dev.env` (`set -a; . ./dev.env; set +a`),
|
||||
sonst werden sie still übersprungen. Nach Änderungen an `go.mod` oder
|
||||
`package.json`: `govulncheck ./...` (`~/go/bin`) und `npm audit`.
|
||||
2. **Changelog**: Ist die Änderung für Nutzende sichtbar, im selben Commit
|
||||
einen kurzen Stichpunkt eintragen:
|
||||
`./changelog.sh 'Stichpunkt'` (HTML erlaubt, z. B. `<kbd>Esc</kbd>`). Das
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
|
||||
"github.com/oschwald/maxminddb-golang"
|
||||
|
||||
"kver/internal/account"
|
||||
"kver/internal/charts"
|
||||
"kver/internal/chat"
|
||||
"kver/internal/database"
|
||||
@@ -69,9 +68,6 @@ func run(ctx context.Context, log *slog.Logger, args []string) error {
|
||||
return err
|
||||
}
|
||||
defer closeLogged(log, "db", db)
|
||||
if err := account.MigrateHandles(ctx, db, log); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) > 0 {
|
||||
return runCommand(ctx, cmdEnv{db: db, log: log, baseURL: cfg.baseURL}, args)
|
||||
@@ -130,11 +126,6 @@ func serve(ctx context.Context, cfg config, db *sql.DB, log *slog.Logger) error
|
||||
Impressions: impression.NewTracker(db, geo, log, time.Now),
|
||||
Chats: chat.NewPurger(db, log, time.Now),
|
||||
}
|
||||
if n, err := httpapi.BackfillTags(ctx, db); err != nil {
|
||||
return err
|
||||
} else if n > 0 {
|
||||
log.Info("hashtags nachgetragen", "beiträge", n)
|
||||
}
|
||||
// Die Worker überdauern das Signal: sie stoppen erst, wenn der Server
|
||||
// keine Requests mehr bedient.
|
||||
stopWorkers := startWorkers(context.WithoutCancel(ctx), deps)
|
||||
|
||||
Generated
+240
-122
@@ -22,10 +22,66 @@
|
||||
"vite": "^8.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/core": {
|
||||
"version": "2.0.0-beta.2",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-2.0.0-beta.2.tgz",
|
||||
"integrity": "sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/wasi-threads": "2.2.0",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"version": "2.0.0-beta.2",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-2.0.0-beta.2.tgz",
|
||||
"integrity": "sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/wasi-threads": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz",
|
||||
"integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/wasm-runtime": {
|
||||
"version": "1.2.6",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.6.tgz",
|
||||
"integrity": "sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@tybys/wasm-util": "^0.10.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=23.5.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Brooooooklyn"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@emnapi/core": "^1.7.1 || 2.0.0-beta.2",
|
||||
"@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@oxc-project/types": {
|
||||
"version": "0.151.0",
|
||||
"resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.151.0.tgz",
|
||||
"integrity": "sha512-J1yXrIlNDZVzE3ada310xeAw7nH8yCAyLPuUIsjKatFPmfn5bS1oW+cM+QsGOtVWd5nhSpbwZWx/rue+r5Z+PA==",
|
||||
"version": "0.156.0",
|
||||
"resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.156.0.tgz",
|
||||
"integrity": "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
@@ -39,9 +95,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@rolldown/binding-android-arm-eabi": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.11.tgz",
|
||||
"integrity": "sha512-A5kXfGKvKWWZE0TtPrfsvT+q4Y5d1QG8gGUzpYjGydM+fARM9MuX90PrXYXe0XbsDVgyxxNzHo6giCj90bsFNw==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.19.tgz",
|
||||
"integrity": "sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
@@ -56,9 +112,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-android-arm64": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.11.tgz",
|
||||
"integrity": "sha512-z6cTycz+iJ4PVkuL4HHW4DfTfoeU/2nqYYuSOrTmH7yHK5Y0LCOnA03V4ZNxavyVaU1oOqUgIg2klN/s+USGOA==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.19.tgz",
|
||||
"integrity": "sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -73,9 +129,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-darwin-arm64": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.11.tgz",
|
||||
"integrity": "sha512-jShvqNtP6vDC6/A5JOAzbVV+DkgHqhl/ScVCJEbt+TUY6QYz7YnXcrg3sLtFBniro0f/Ld50ZwCWA6f7KYD1nQ==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.19.tgz",
|
||||
"integrity": "sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -90,9 +146,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-darwin-x64": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.11.tgz",
|
||||
"integrity": "sha512-f2i2xiNWq1Z1l2++q2fuhZRdLAT3aqxD6vRNm1RAxpUoBcdqNB3C0s1Bt+K+PbEx2F5F4gQp6hqKkphCY/xF9w==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.19.tgz",
|
||||
"integrity": "sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -107,9 +163,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-freebsd-x64": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.11.tgz",
|
||||
"integrity": "sha512-4Ir5FSOKIAMr4r0kExpt1s3bMgzJU3rA45AYOHtQpls0oNeqcYBKrWMlckrYH4KCfGLfkfn1tN1dmZPMVsdXow==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.19.tgz",
|
||||
"integrity": "sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -124,9 +180,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-linux-arm-gnueabihf": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.11.tgz",
|
||||
"integrity": "sha512-/gnRDM+39BROzAN/k1OZjDPnDMcZxB/0EUxKjONO5yVkNEvlsoMDrxGNKgZi/ttFriS2gwlDNzB65pvNbFOXIQ==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.19.tgz",
|
||||
"integrity": "sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
@@ -141,9 +197,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-linux-arm64-gnu": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.11.tgz",
|
||||
"integrity": "sha512-PFaK8HwvAHbaKbBcDNQihjMKYvFnA5hiENx/l5tphTDz1E0WFp32l0A7aq7lyUwGsRw/xSrNIy/gIK4thrSCrw==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.19.tgz",
|
||||
"integrity": "sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -161,9 +217,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-linux-arm64-musl": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.11.tgz",
|
||||
"integrity": "sha512-AskzJUIKRLPxkruR1wLKewGbOw+EYfU/9lOrBFj4AFrEA8hPpKFnODWNu2WLaNs0QNkEb9QIJufmVZZIL/bJlg==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.19.tgz",
|
||||
"integrity": "sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -181,9 +237,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-linux-ppc64-gnu": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.11.tgz",
|
||||
"integrity": "sha512-qlUGAheh2yh8afH7QBgx0PrRHN85hKnNd78x8MeMhXivuevgd8vgf6/CstOzmNKY/lLTHvNTrPy98cLnAugzJw==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.19.tgz",
|
||||
"integrity": "sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
@@ -201,9 +257,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-linux-s390x-gnu": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.11.tgz",
|
||||
"integrity": "sha512-secpEad+0vCbSfn8upFySkDskv+bGPk3THSDS9Y89yc4rb4kzqHp8Dmyd9BkQW4SnhNXBZCl/6CrO//hZahNJQ==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.19.tgz",
|
||||
"integrity": "sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
@@ -221,9 +277,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-linux-x64-gnu": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.11.tgz",
|
||||
"integrity": "sha512-mOVBT3dPpkWm8XBWPmU4bf+U6dYDLeMo/9ojUmis4N0L5uu10qra5vOyngZ7/PSdoE4G9KvRt4bloRxNjLas7A==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.19.tgz",
|
||||
"integrity": "sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -241,9 +297,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-linux-x64-musl": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.11.tgz",
|
||||
"integrity": "sha512-Is78i9A8Ui4SqcxUwFJ9uMmjDn58IbVTjFWYdQestFEgeuEmHMLGNriXnVJKkwG2YiZjw8cP0zCTyDMdDGtOOg==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.19.tgz",
|
||||
"integrity": "sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -261,9 +317,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-openharmony-arm64": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.11.tgz",
|
||||
"integrity": "sha512-dUCXneZ87INUMyQ0D+C0HrEBNUPNXHaPmU5GTjyKTJEiussw9Kaj5Ln8UztPe4epV/ffvgNBEadksdYhmW6xJA==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.19.tgz",
|
||||
"integrity": "sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -277,10 +333,29 @@
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-wasm32-wasi": {
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.2.19.tgz",
|
||||
"integrity": "sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg==",
|
||||
"cpu": [
|
||||
"wasm32"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/core": "2.0.0-beta.2",
|
||||
"@emnapi/runtime": "2.0.0-beta.2",
|
||||
"@napi-rs/wasm-runtime": "1.2.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=23.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-win32-arm64-msvc": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.11.tgz",
|
||||
"integrity": "sha512-jByxb6qfd+bH1xUd0qnfFnb17i9sWBPY2tOavJ0l3tdr3OTu+Kvtm8cd/JV5nFt657b1VqGltxg9olOEfofXWw==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.19.tgz",
|
||||
"integrity": "sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -295,9 +370,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-win32-x64-msvc": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.11.tgz",
|
||||
"integrity": "sha512-/PzKqzAJ03i19oy2ItPvyvaVjOjBCNnfaJs8yvUdGBKmiESgnrJSQ2awd81QzFbbnAmu7YO9ZnJrDCb9VSJPRA==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.19.tgz",
|
||||
"integrity": "sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -312,16 +387,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/pluginutils": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz",
|
||||
"integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==",
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.1.tgz",
|
||||
"integrity": "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@tanstack/query-core": {
|
||||
"version": "5.104.0",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.104.0.tgz",
|
||||
"integrity": "sha512-JrC2r/JQlXt7khBSdUpsgxNvybzOg+aITa+ARRMlP2AFo93Y8vIqz077rp+e61mJetSZ0T6AJbwW1JHer1vrPQ==",
|
||||
"version": "5.108.2",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.108.2.tgz",
|
||||
"integrity": "sha512-0l+0xDKqn71hfJBKaAvFP/X7WYM0TbscEk6nK1pHaWQUWUEA+WJD0VlT8wF+HIJANMV9B/DouPWwDnX3w/l9BA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
@@ -329,25 +404,42 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@tanstack/react-query": {
|
||||
"version": "5.104.0",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.104.0.tgz",
|
||||
"integrity": "sha512-e1TZmDCQnWIfiDVryIHeA6Idj+Lfx1hORLOhXS/l5wcgvtVD4yYqbTDl378sGQKIi2cSgb0TEMC9cKK8GGoJEw==",
|
||||
"version": "5.108.2",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.108.2.tgz",
|
||||
"integrity": "sha512-wV6hEjVGTfh9rvu3uREYW0hgBfS9klDejGelhPY575jD5jg6qbAb1nzT7hR1Q+wemR66ZjtE5p9pAGUwqK8zbg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tanstack/query-core": "5.104.0"
|
||||
"@tanstack/query-core": "5.108.2"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/tannerlinsley"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "^18 || ^19",
|
||||
"react": "^18 || ^19"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@tybys/wasm-util": {
|
||||
"version": "0.10.5",
|
||||
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.5.tgz",
|
||||
"integrity": "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "26.6.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.3.tgz",
|
||||
"integrity": "sha512-dsqMQQoeTLqu9wynDD00q573mNzso3IdQOAfHRJqLCcmCFPoGo9A1bDpUcv/9tnKpErQWv9uKeGfl37EIS02Yg==",
|
||||
"version": "26.6.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.6.tgz",
|
||||
"integrity": "sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -358,7 +450,7 @@
|
||||
"version": "19.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.3.0.tgz",
|
||||
"integrity": "sha512-N0rFCuH9YoxG9/m61l9MfpJKfmLOVU0em7ipIz6TRgSSkvReLB9vL85GB+yr8Bs5leqpvg96JSwF4ZS1s4viQg==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"csstype": "^3.2.2"
|
||||
@@ -368,7 +460,7 @@
|
||||
"version": "19.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.3.0.tgz",
|
||||
"integrity": "sha512-ZI7bU42mZXXKHn/qNLEw2IrbiINU7X5+vfgdixBHkCNpYWXjKgfQ/P+uyGb5CjOLB9UcnTeg3rylQtV2hym44Q==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@types/react": "^19.3.0"
|
||||
@@ -715,9 +807,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@vitejs/plugin-react": {
|
||||
"version": "6.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-6.1.1.tgz",
|
||||
"integrity": "sha512-yxLaQV9gkhS8ezJqCM6+ndU7mDY6gqAg75NQ+0IjwEI8IYOmQCgkRwHKVSfWXW076DsqMo0Dk+0FK1U+M5RgFw==",
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-6.3.0.tgz",
|
||||
"integrity": "sha512-H9E955aVvD2F4zNHCw4eIZbIfF6xKldlh7MNu+hSU7xwQzh65lI/N+CJWqmfhi0PEjDXIt/H7T7J/4wU63KJiw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -727,9 +819,9 @@
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@rolldown/plugin-babel": "^0.1.7 || ^0.2.0",
|
||||
"@rolldown/plugin-babel": "^0.1.7 || ^0.2.0 || ^0.3.0",
|
||||
"babel-plugin-react-compiler": "^1.0.0",
|
||||
"oxc-transform-react": "^0.145.0",
|
||||
"oxc-transform-react": ">=0.152.0 <0.157.0",
|
||||
"vite": "^8.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
@@ -751,10 +843,10 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/csstype": {
|
||||
"version": "3.2.3",
|
||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
||||
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
|
||||
"dev": true,
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.4.tgz",
|
||||
"integrity": "sha512-PoKaoPzQapnEoqUSnHx1u6W6ku8CVEgKsnpmmzU3m1nwkidpPBQ8V/Zq2+bWNrsOKoKLwTGdbx6xF7BXP1zLVQ==",
|
||||
"devOptional": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/detect-libc": {
|
||||
@@ -767,6 +859,12 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/eckey-utils": {
|
||||
"version": "0.7.14",
|
||||
"resolved": "https://registry.npmjs.org/eckey-utils/-/eckey-utils-0.7.14.tgz",
|
||||
"integrity": "sha512-s/mENS+mMnJjDSydy0muBQQHMTWJ1nPe8EiphANZrf+lv/1u35aP9WvWHTWqCBJ21blNIurGF7UoLjtaOpoCFw==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/fdir": {
|
||||
"version": "6.5.0",
|
||||
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
|
||||
@@ -1083,9 +1181,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/nanoid": {
|
||||
"version": "3.3.19",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.19.tgz",
|
||||
"integrity": "sha512-Y2tUNy4ouw6tq5oDSKeQYGOyhkUBhNOcGV/02KC+6kd9eDGqdZd++mjMiIDilrBYvjEnCYvVtsuHCuP+okSfug==",
|
||||
"version": "3.3.20",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz",
|
||||
"integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
@@ -1102,10 +1200,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/openpgp": {
|
||||
"version": "6.3.2",
|
||||
"resolved": "https://registry.npmjs.org/openpgp/-/openpgp-6.3.2.tgz",
|
||||
"integrity": "sha512-wcZTzHz41LV8Y48zH/JlD1JT8YdNmpWOuMAjQ/podvvCwsjBEU37K3znJh4UQcj3hksE5z9TzvhbUbwzsGvlLQ==",
|
||||
"version": "6.3.3",
|
||||
"resolved": "https://registry.npmjs.org/openpgp/-/openpgp-6.3.3.tgz",
|
||||
"integrity": "sha512-W0foQI+Zb7/TCy7Z50gqZejYe3oJkiZJ9OSV4ImuRT8MmoKOJhtAMvRm6w9STlyYluLiuezG7+0Qdqbcmmx7ig==",
|
||||
"license": "LGPL-3.0+",
|
||||
"dependencies": {
|
||||
"eckey-utils": "^0.7.14"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18.0.0",
|
||||
"typescript": ">= 5.0.0"
|
||||
@@ -1140,9 +1241,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/postcss": {
|
||||
"version": "8.5.28",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.28.tgz",
|
||||
"integrity": "sha512-RRuzqDtt5Y9h3quz5hWhK+TPnsmVs6WwSU6LkJMeY4HstUEDuYTG8UJSdawMRzmzAtV+KEoG8N3Qg2qLy5vM/A==",
|
||||
"version": "8.5.33",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz",
|
||||
"integrity": "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
@@ -1160,39 +1261,39 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nanoid": "^3.3.18",
|
||||
"nanoid": "^3.3.20",
|
||||
"picocolors": "^1.1.1",
|
||||
"source-map-js": "^1.2.1"
|
||||
"source-map-js": "^1.2.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^10 || ^12 || >=14"
|
||||
}
|
||||
},
|
||||
"node_modules/react": {
|
||||
"version": "19.3.0",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-19.3.0.tgz",
|
||||
"integrity": "sha512-E8LUcbtBWt20bbl2YoHfx4ZDBdxVTfOKtCZn9cDSJ4l6/nuoApcpIBcj47t2wZoVX8g2ZHuMHbiShgCR1T5Sog==",
|
||||
"version": "19.3.1",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-19.3.1.tgz",
|
||||
"integrity": "sha512-QNhWdt7nrgVWWQG58QuGsAR3jv3Hbe4mb4vz7w2csnHavciZJgda1CPNaldF6eVxv90ud3jUXpKlHL69gO38yw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-dom": {
|
||||
"version": "19.3.0",
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.0.tgz",
|
||||
"integrity": "sha512-JDk8dgif51OjFoDE70+OT9ICyYr+69HlmihNwp1+Nsfbna3t5sIiCa9ZJktDmQ4/1b/rn26hIAR2uYXDMr5r0Q==",
|
||||
"version": "19.3.1",
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.3.1.tgz",
|
||||
"integrity": "sha512-Y0bARz53lhEC1NMCASs0/j+faB/zqt3R8hpvg1e8+61ZVJ4UL0UdC4cBbXfZMcIuhrfgeILTLe+ZeBCavQPtKQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"scheduler": "^0.28.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^19.3.0"
|
||||
"react": "^19.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/react-router": {
|
||||
"version": "8.4.0",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-8.4.0.tgz",
|
||||
"integrity": "sha512-JtydAkBvU9UTEe5qNC+POhu+ZBNM7rlKY2IegwXc7Idj7xfRG16x5RZrw3mju+XlqBxfvb2ky9P3jUp9WyWC1g==",
|
||||
"version": "8.5.2",
|
||||
"resolved": "https://registry.npmjs.org/react-router/-/react-router-8.5.2.tgz",
|
||||
"integrity": "sha512-luPXqNUAIZAmCHbeBysc2KO7VJjckIMZk4ByEetS7Jotit8R6lLSVVeC76UE//AYK6QD6tAnVAPGkvmqMd+b1w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@remix-run/route-pattern": "^0.22.1",
|
||||
@@ -1202,23 +1303,31 @@
|
||||
"node": ">=22.22.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": ">=19.2.0",
|
||||
"@types/react-dom": ">=19.2.0",
|
||||
"react": ">=19.2.7",
|
||||
"react-dom": ">=19.2.7"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/react-dom": {
|
||||
"optional": true
|
||||
},
|
||||
"react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/rolldown": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.11.tgz",
|
||||
"integrity": "sha512-qpSwIyz0jHQq5qXBTNxFmE6664rJ7O+4TvPFOiOaBSrz8IOHc1koKKSqTM2H6u1UG1+TveuC6vaDHKXFOvb1Kw==",
|
||||
"version": "1.2.19",
|
||||
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.19.tgz",
|
||||
"integrity": "sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@oxc-project/types": "=0.151.0",
|
||||
"@oxc-project/types": "=0.156.0",
|
||||
"@rolldown/pluginutils": "^1.0.0"
|
||||
},
|
||||
"bin": {
|
||||
@@ -1228,21 +1337,22 @@
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@rolldown/binding-android-arm-eabi": "1.2.11",
|
||||
"@rolldown/binding-android-arm64": "1.2.11",
|
||||
"@rolldown/binding-darwin-arm64": "1.2.11",
|
||||
"@rolldown/binding-darwin-x64": "1.2.11",
|
||||
"@rolldown/binding-freebsd-x64": "1.2.11",
|
||||
"@rolldown/binding-linux-arm-gnueabihf": "1.2.11",
|
||||
"@rolldown/binding-linux-arm64-gnu": "1.2.11",
|
||||
"@rolldown/binding-linux-arm64-musl": "1.2.11",
|
||||
"@rolldown/binding-linux-ppc64-gnu": "1.2.11",
|
||||
"@rolldown/binding-linux-s390x-gnu": "1.2.11",
|
||||
"@rolldown/binding-linux-x64-gnu": "1.2.11",
|
||||
"@rolldown/binding-linux-x64-musl": "1.2.11",
|
||||
"@rolldown/binding-openharmony-arm64": "1.2.11",
|
||||
"@rolldown/binding-win32-arm64-msvc": "1.2.11",
|
||||
"@rolldown/binding-win32-x64-msvc": "1.2.11"
|
||||
"@rolldown/binding-android-arm-eabi": "1.2.19",
|
||||
"@rolldown/binding-android-arm64": "1.2.19",
|
||||
"@rolldown/binding-darwin-arm64": "1.2.19",
|
||||
"@rolldown/binding-darwin-x64": "1.2.19",
|
||||
"@rolldown/binding-freebsd-x64": "1.2.19",
|
||||
"@rolldown/binding-linux-arm-gnueabihf": "1.2.19",
|
||||
"@rolldown/binding-linux-arm64-gnu": "1.2.19",
|
||||
"@rolldown/binding-linux-arm64-musl": "1.2.19",
|
||||
"@rolldown/binding-linux-ppc64-gnu": "1.2.19",
|
||||
"@rolldown/binding-linux-s390x-gnu": "1.2.19",
|
||||
"@rolldown/binding-linux-x64-gnu": "1.2.19",
|
||||
"@rolldown/binding-linux-x64-musl": "1.2.19",
|
||||
"@rolldown/binding-openharmony-arm64": "1.2.19",
|
||||
"@rolldown/binding-wasm32-wasi": "1.2.19",
|
||||
"@rolldown/binding-win32-arm64-msvc": "1.2.19",
|
||||
"@rolldown/binding-win32-x64-msvc": "1.2.19"
|
||||
}
|
||||
},
|
||||
"node_modules/scheduler": {
|
||||
@@ -1252,13 +1362,13 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/source-map-js": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
||||
"integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.4.tgz",
|
||||
"integrity": "sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==",
|
||||
"dev": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyglobby": {
|
||||
@@ -1278,6 +1388,14 @@
|
||||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.9.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
|
||||
"integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
|
||||
"dev": true,
|
||||
"license": "0BSD",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "7.0.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz",
|
||||
@@ -1321,16 +1439,16 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "8.3.1",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-8.3.1.tgz",
|
||||
"integrity": "sha512-/bvH9E9tmCXRGp2uXY3WbOldqpTwFkbha/8ANaEQ6VkxhH60KyqLwgZq6lG2y+4uT55x9+9eUHMpQ7uGnOCKjA==",
|
||||
"version": "8.3.8",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-8.3.8.tgz",
|
||||
"integrity": "sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lightningcss": "^1.33.0",
|
||||
"picomatch": "^4.0.7",
|
||||
"postcss": "^8.5.28",
|
||||
"rolldown": "~1.2.9",
|
||||
"postcss": "^8.5.32",
|
||||
"rolldown": "~1.2.18",
|
||||
"tinyglobby": "^0.2.17"
|
||||
},
|
||||
"bin": {
|
||||
@@ -1347,7 +1465,7 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/node": "^20.19.0 || >=22.12.0",
|
||||
"@vitejs/devtools": "^0.7.1",
|
||||
"@vitejs/devtools": "^0.7.1 || ^0.8.0",
|
||||
"esbuild": "^0.27.0 || ^0.28.0",
|
||||
"jiti": ">=1.21.0",
|
||||
"less": "^4.0.0",
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
<h2>Changelog</h2>
|
||||
<!-- Neuester Tag oben, darunter kurze Stichpunkte. Einträge per
|
||||
./changelog.sh 'Stichpunkt' (legt den Abschnitt für heute bei Bedarf an). -->
|
||||
<h3>22.11.2026</h3>
|
||||
<ul>
|
||||
<li>Sicherheit: Sitzungen werden serverseitig nur noch als Hash gespeichert. Dafür wurden alle bestehenden Anmeldungen einmalig beendet, bitte neu anmelden.</li>
|
||||
</ul>
|
||||
<h3>21.11.2026</h3>
|
||||
<ul>
|
||||
<li>Bilder können hinter einem Hinweis liegen: dann erscheint erst eine verpixelte Fassung, das Bild selbst nach Klick auf „Inhalt anzeigen“.</li>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useMe } from "./auth";
|
||||
|
||||
export type Notification = {
|
||||
id: number;
|
||||
kind: "reply" | "bump";
|
||||
kind: "reply" | "mention" | "bump";
|
||||
// Was passiert ist, etwa "@bob hat auf deinen Beitrag geantwortet."
|
||||
message: string;
|
||||
// Anfang des zitierten Beitrags, '' = keiner.
|
||||
|
||||
@@ -3,23 +3,22 @@ module kver
|
||||
go 1.26.0
|
||||
|
||||
require (
|
||||
github.com/go-chi/chi/v5 v5.3.0
|
||||
github.com/go-chi/httprate v0.15.0
|
||||
github.com/jackc/pgx/v5 v5.11.0
|
||||
github.com/mozillazg/go-unidecode v0.2.0
|
||||
github.com/go-chi/chi/v5 v5.5.0
|
||||
github.com/go-chi/httprate v0.16.1
|
||||
github.com/jackc/pgx/v5 v5.13.0
|
||||
github.com/oschwald/maxminddb-golang v1.13.1
|
||||
golang.org/x/crypto v0.57.0
|
||||
golang.org/x/image v0.41.0
|
||||
golang.org/x/net v0.59.0
|
||||
golang.org/x/crypto v0.59.0
|
||||
golang.org/x/image v0.48.0
|
||||
golang.org/x/net v0.63.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
||||
github.com/zeebo/xxh3 v1.0.2 // indirect
|
||||
golang.org/x/sync v0.23.0 // indirect
|
||||
golang.org/x/sys v0.48.0 // indirect
|
||||
golang.org/x/text v0.42.0 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.4 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.4.2 // indirect
|
||||
github.com/zeebo/xxh3 v1.1.0 // indirect
|
||||
golang.org/x/sync v0.25.0 // indirect
|
||||
golang.org/x/sys v0.50.0 // indirect
|
||||
golang.org/x/text v0.44.0 // indirect
|
||||
)
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-chi/chi/v5 v5.3.0 h1:halUjDxhshgXHMrao5bB8eNBXo/rnzwr8m5m36glehM=
|
||||
github.com/go-chi/chi/v5 v5.3.0/go.mod h1:R+tYY2hNuVUUjxoPtqUdgBqevM9s9njzkTLutVsOCto=
|
||||
github.com/go-chi/httprate v0.15.0 h1:j54xcWV9KGmPf/X4H32/aTH+wBlrvxL7P+SdnRqxh5g=
|
||||
github.com/go-chi/httprate v0.15.0/go.mod h1:rzGHhVrsBn3IMLYDOZQsSU4fJNWcjui4fWKJcCId1R4=
|
||||
github.com/go-chi/chi/v5 v5.5.0 h1:xdKQ1dJmVJsmgahrXSKhUx8NyVPzpwdlyrrQFpMPJgg=
|
||||
github.com/go-chi/chi/v5 v5.5.0/go.mod h1:d1IG7GtKPSjPyBP365PH8sAGVHk3qfB/IhjFNRH1wWM=
|
||||
github.com/go-chi/httprate v0.16.1 h1:q2M8FmDsI4oEr1oRX43N+VeA0Ujd1tb/EasrSzXy87o=
|
||||
github.com/go-chi/httprate v0.16.1/go.mod h1:A8lo+qRhk+s9LiuP5saS7XCGDXRXMcrueq0NfIuCa/I=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.11.0 h1:IzBBtyK9AHqf98cctWFifYSci2hgQR/cd56wB4p+ogg=
|
||||
github.com/jackc/pgx/v5 v5.11.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/mozillazg/go-unidecode v0.2.0 h1:vFGEzAH9KSwyWmXCOblazEWDh7fOkpmy/Z4ArmamSUc=
|
||||
github.com/mozillazg/go-unidecode v0.2.0/go.mod h1:zB48+/Z5toiRolOZy9ksLryJ976VIwmDmpQ2quyt1aA=
|
||||
github.com/jackc/pgx/v5 v5.13.0 h1:Hl08k64maU0nrRyVUEbwCnK6/gT0EhMrtAqBHz9/gA4=
|
||||
github.com/jackc/pgx/v5 v5.13.0/go.mod h1:u2Fi6no03HCSBYE+ZVdLxbwdu3xyi2vU+K/YNJioSds=
|
||||
github.com/jackc/puddle/v2 v2.2.4 h1:N6Mz6EGB9DL0bz3OEfxJ7eoOpjRHnnjpOh+G8kbLoG8=
|
||||
github.com/jackc/puddle/v2 v2.2.4/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/klauspost/cpuid/v2 v2.4.2 h1:xRw7IZEsAgVCp6trS/DgWbTAqpixhmywgVgBjYGg1bQ=
|
||||
github.com/klauspost/cpuid/v2 v2.4.2/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
|
||||
github.com/oschwald/maxminddb-golang v1.13.1 h1:G3wwjdN9JmIK2o/ermkHM+98oX5fS+k5MbwsmL4MRQE=
|
||||
github.com/oschwald/maxminddb-golang v1.13.1/go.mod h1:K4pgV9N/GcK694KSTmVSDTODk4IsCNThNdTmnaBZ/F8=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@@ -28,20 +26,20 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
||||
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
||||
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
|
||||
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
|
||||
golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
|
||||
golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
|
||||
golang.org/x/image v0.41.0 h1:8wS72eGJMJaBxK6okTzd4WaXumUlTVlb753MlsSvTCo=
|
||||
golang.org/x/image v0.41.0/go.mod h1:uIc348UZMSvS5Z65CVZ7iDPaNobNFEPeJ4kbqTOszmA=
|
||||
golang.org/x/net v0.59.0 h1:5zfYln+w5XCxwrnMMJPufRgNoXEaGxl0wo5GqPXyues=
|
||||
golang.org/x/net v0.59.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
|
||||
golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk=
|
||||
golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
|
||||
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
|
||||
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
|
||||
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
||||
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
||||
golang.org/x/crypto v0.59.0 h1:xS2jhqYbzNrpvkWP2YTDf4TJwBy3ykR03i8vFDxEc7c=
|
||||
golang.org/x/crypto v0.59.0/go.mod h1:veDyUwATGs3c+vN3VfTbzViMGXeTBk3WyhBOkn+F/4U=
|
||||
golang.org/x/image v0.48.0 h1:1AvuPcuoOTJpA7s4VZ5umrb90T3So0rkB/bSGmxkxik=
|
||||
golang.org/x/image v0.48.0/go.mod h1:mmtg64iqJKGqEgy+r13dfybl85tmxUd2lMnmaiSdWYY=
|
||||
golang.org/x/net v0.63.0 h1:HCoTmNh9EpD1PpK8gBNFY4gcTY4N+KQEO8ylfIKqFJ0=
|
||||
golang.org/x/net v0.63.0/go.mod h1:15JLg3IX1bLjHK264EZQEbIpTiR/KVLuo9CTRWd0pig=
|
||||
golang.org/x/sync v0.25.0 h1:dJnifr0nMV8/SBnBvdo4eSGGnrc3O4FFx6IqvtLcmRs=
|
||||
golang.org/x/sync v0.25.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||
golang.org/x/sys v0.50.0 h1:dkKZEFTEKaLr1sjhs0WiKqoi8Jj5nHbS3Njmx1UoMJs=
|
||||
golang.org/x/sys v0.50.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||
golang.org/x/text v0.44.0 h1:YItdp/mQNGnsmrgpcdA5yQ3bnRxCfo/Tj/iByGW9GGo=
|
||||
golang.org/x/text v0.44.0/go.mod h1:S4FR1waQ9LbjQTls97SyRjDaUUVkaM+cXwwuG/G+MwY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
||||
+18
-12
@@ -119,22 +119,28 @@ func (s *Store) UID(ctx context.Context, handle string) (int64, error) {
|
||||
return uid, nil
|
||||
}
|
||||
|
||||
// ErrWrongPassword: das bisherige Passwort beim Ändern stimmt nicht.
|
||||
var ErrWrongPassword = apperr.Forbidden("auth.bad_password", "Das bisherige Passwort ist falsch.").At("pass")
|
||||
// ErrWrongPassword: das eingegebene Passwort stimmt nicht. Der Aufrufer hängt
|
||||
// das Formularfeld an (At), in dem es stand.
|
||||
var ErrWrongPassword = apperr.Forbidden("auth.bad_password", "Das Passwort ist falsch.")
|
||||
|
||||
// VerifyPassword bestätigt eine heikle Aktion mit dem Passwort des Kontos.
|
||||
func (s *Store) VerifyPassword(ctx context.Context, uid int64, password string) error {
|
||||
var hash []byte
|
||||
err := s.db.QueryRowContext(ctx, `SELECT password FROM account WHERE uid = $1`, uid).Scan(&hash)
|
||||
if err != nil {
|
||||
return notFoundOr(err, "passwort")
|
||||
}
|
||||
if bcrypt.CompareHashAndPassword(hash, []byte(password)) != nil {
|
||||
return ErrWrongPassword
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChangePassword setzt ein neues Passwort, wenn current das bisherige ist.
|
||||
// Alle anderen Sessions des Nutzers enden; keepSession (die eigene) bleibt.
|
||||
func (s *Store) ChangePassword(ctx context.Context, uid int64, current, password, keepSession string) error {
|
||||
var old []byte
|
||||
err := s.db.QueryRowContext(ctx, `SELECT password FROM account WHERE uid = $1`, uid).Scan(&old)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return ErrUserNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("passwort lesen: %w", err)
|
||||
}
|
||||
if bcrypt.CompareHashAndPassword(old, []byte(current)) != nil {
|
||||
return ErrWrongPassword
|
||||
if err := s.VerifyPassword(ctx, uid, current); err != nil {
|
||||
return err
|
||||
}
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
|
||||
+7
-148
@@ -2,17 +2,11 @@ package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/mozillazg/go-unidecode"
|
||||
|
||||
"kver/internal/apperr"
|
||||
"kver/internal/database"
|
||||
"kver/internal/runes"
|
||||
)
|
||||
|
||||
@@ -57,152 +51,17 @@ func CleanDisplayName(n string) string {
|
||||
return runes.Truncate(n, maxDisplayRunes)
|
||||
}
|
||||
|
||||
// Deutsche Umschrift vor der allgemeinen: unidecode machte aus "ä" nur "a".
|
||||
var germanTranslit = strings.NewReplacer(
|
||||
"ä", "ae", "ö", "oe", "ü", "ue", "Ä", "Ae", "Ö", "Oe", "Ü", "Ue", "ß", "ss")
|
||||
|
||||
// HandleFrom leitet aus einem alten Unicode-Nutzernamen einen Handle ab:
|
||||
// Umlaute nach deutscher Umschrift, alle anderen Schriften per unidecode
|
||||
// lateinisiert (Chinesisch als Pinyin ohne Töne), Silben ohne Abstand
|
||||
// aneinander, alles übrige außer a-z0-9_ wird "_". Kann zu kurz geraten oder
|
||||
// vergeben sein; das löst die Migration.
|
||||
func HandleFrom(name string) string {
|
||||
var b strings.Builder
|
||||
for _, r := range germanTranslit.Replace(name) {
|
||||
// Je Zeichen umschreiben: unidecode hängt an jede chinesische Silbe
|
||||
// ein Leerzeichen, das sonst zu "_" würde.
|
||||
for _, c := range strings.ToLower(strings.TrimSpace(unidecode.Unidecode(string(r)))) {
|
||||
switch {
|
||||
case c >= 'a' && c <= 'z', c >= '0' && c <= '9', c == '_':
|
||||
b.WriteRune(c)
|
||||
case !strings.HasSuffix(b.String(), "_"):
|
||||
b.WriteByte('_')
|
||||
}
|
||||
}
|
||||
}
|
||||
h := strings.Trim(b.String(), "_")
|
||||
if len(h) > MaxHandleLen {
|
||||
h = strings.TrimRight(h[:MaxHandleLen], "_")
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
// MigrateHandles gibt Konten aus der Zeit vor der Trennung von Handle und
|
||||
// Anzeigename (handle IS NULL) beides: der alte Name wird Anzeigename, der
|
||||
// Handle per HandleFrom daraus abgeleitet. Ältere Konten kommen zuerst und
|
||||
// behalten bei Kollisionen den Handle ohne Zusatz. Danach ist handle Pflicht.
|
||||
// Idempotent: ohne offene Konten passiert nichts. Namen landen nicht im Log;
|
||||
// wer einen anderen Handle als seinen alten Namen bekam, listet
|
||||
// `kver handles` auf.
|
||||
func MigrateHandles(ctx context.Context, db *sql.DB, log *slog.Logger) error {
|
||||
return database.InTx(ctx, db, func(tx *sql.Tx) error {
|
||||
rows, err := tx.QueryContext(ctx,
|
||||
`SELECT uid, legacy_name FROM account WHERE handle IS NULL ORDER BY id FOR UPDATE`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("handles lesen: %w", err)
|
||||
}
|
||||
type pending struct {
|
||||
uid int64
|
||||
name string
|
||||
}
|
||||
var todo []pending
|
||||
for rows.Next() {
|
||||
var p pending
|
||||
if err := rows.Scan(&p.uid, &p.name); err != nil {
|
||||
rows.Close()
|
||||
return fmt.Errorf("handles lesen: %w", err)
|
||||
}
|
||||
todo = append(todo, p)
|
||||
}
|
||||
rows.Close()
|
||||
if err := rows.Err(); err != nil {
|
||||
return fmt.Errorf("handles lesen: %w", err)
|
||||
}
|
||||
|
||||
set := func(p pending, h string) error {
|
||||
if _, err := tx.ExecContext(ctx,
|
||||
`UPDATE account SET handle = $1, display_name = $2 WHERE uid = $3`,
|
||||
h, CleanDisplayName(p.name), p.uid); err != nil {
|
||||
return fmt.Errorf("handle setzen: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// Erst alle Namen, die sich bis auf die Kleinschreibung unverändert
|
||||
// übernehmen lassen, danach der Rest mit Zahl-Zusatz: sonst nähme etwa
|
||||
// das zweite "Anna" als "anna2" einem echten "anna2" den Namen weg.
|
||||
var rest []pending
|
||||
for _, p := range todo {
|
||||
h := HandleFrom(p.name)
|
||||
taken, err := handleTaken(ctx, tx, h)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if h != strings.ToLower(p.name) || !ValidHandle(h) || taken {
|
||||
rest = append(rest, p)
|
||||
} else if err := set(p, h); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, p := range rest {
|
||||
h, err := freeHandle(ctx, tx, HandleFrom(p.name), p.uid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := set(p, h); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
changed := len(rest)
|
||||
if _, err := tx.ExecContext(ctx, `ALTER TABLE account ALTER COLUMN handle SET NOT NULL`); err != nil {
|
||||
return fmt.Errorf("handle als Pflicht setzen: %w", err)
|
||||
}
|
||||
if len(todo) > 0 {
|
||||
log.Info("handles migriert", "konten", len(todo), "abweichend", changed)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// freeHandle liefert base, wenn gültig und frei, sonst base mit angehängter
|
||||
// Zahl (anna2, anna3, ...). Ist base zu kurz, etwa weil von einem Namen
|
||||
// nichts Lateinisches übrig blieb, wird es user<uid>.
|
||||
func freeHandle(ctx context.Context, tx *sql.Tx, base string, uid int64) (string, error) {
|
||||
if len(base) < MinHandleLen {
|
||||
base = "user" + strconv.FormatInt(uid, 10)
|
||||
}
|
||||
for n := 1; ; n++ {
|
||||
h := base
|
||||
if n > 1 {
|
||||
suffix := strconv.Itoa(n)
|
||||
h = base[:min(len(base), MaxHandleLen-len(suffix))] + suffix
|
||||
}
|
||||
taken, err := handleTaken(ctx, tx, h)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !taken {
|
||||
return h, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleTaken(ctx context.Context, tx *sql.Tx, h string) (bool, error) {
|
||||
var taken bool
|
||||
if err := tx.QueryRowContext(ctx,
|
||||
`SELECT EXISTS (SELECT 1 FROM account WHERE handle = $1)`, h).Scan(&taken); err != nil {
|
||||
return false, fmt.Errorf("handle prüfen: %w", err)
|
||||
}
|
||||
return taken, nil
|
||||
}
|
||||
|
||||
// HandleChange ist ein Konto, dessen Handle vom alten Nutzernamen abweicht
|
||||
// (mehr als nur in der Groß-/Kleinschreibung, die der Login ignoriert).
|
||||
// HandleChange ist ein Konto, dessen Handle vom alten Nutzernamen
|
||||
// (legacy_name, bis 11/2026) abweicht -- mehr als nur in der
|
||||
// Groß-/Kleinschreibung, die der Login ignoriert. Die Umschrift der alten
|
||||
// Namen ist längst gelaufen; die Liste bleibt, bis alle Betroffenen ihren
|
||||
// neuen Handle kennen.
|
||||
type HandleChange struct {
|
||||
LegacyName, Handle string
|
||||
}
|
||||
|
||||
// HandleChanges listet die Konten, die sich nach der Migration mit einem
|
||||
// anderen Namen anmelden müssen als bisher.
|
||||
// HandleChanges listet die Konten, die sich mit einem anderen Namen anmelden
|
||||
// müssen als früher.
|
||||
func (s *Store) HandleChanges(ctx context.Context) ([]HandleChange, error) {
|
||||
rows, err := s.db.QueryContext(ctx,
|
||||
`SELECT legacy_name, handle FROM account
|
||||
|
||||
@@ -1,38 +1,10 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"kver/internal/testdb"
|
||||
)
|
||||
|
||||
func TestHandleFrom(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := []struct{ in, want string }{
|
||||
{"alice", "alice"},
|
||||
{"Max_Mustermann", "max_mustermann"},
|
||||
{"Jörg_Größe", "joerg_groesse"},
|
||||
{"Renée", "renee"},
|
||||
{"x.y-z_1", "x_y_z_1"},
|
||||
{"..a--b..", "a_b"},
|
||||
{"北京", "beijing"},
|
||||
{"Москва", "moskva"},
|
||||
{"日", "ri"}, // zu kurz, das fängt freeHandle ab
|
||||
{strings.Repeat("ab", 15), strings.Repeat("ab", 10)},
|
||||
{strings.Repeat("a", 19) + ".b", strings.Repeat("a", 19)},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := HandleFrom(tt.in); got != tt.want {
|
||||
t.Errorf("HandleFrom(%q) = %q, erwartet %q", tt.in, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidHandle(t *testing.T) {
|
||||
t.Parallel()
|
||||
for in, want := range map[string]bool{
|
||||
@@ -62,59 +34,3 @@ func TestCleanDisplayName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateHandles(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
db := testdb.New(t)
|
||||
// Zustand vor der Trennung nachstellen: nur legacy_name, kein Handle.
|
||||
if _, err := db.ExecContext(ctx, `ALTER TABLE account ALTER COLUMN handle DROP NOT NULL`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// In Anlage-Reihenfolge; anna2 ist ein echter Name und muss ihn behalten,
|
||||
// obwohl das jüngere "anna" ausweichen muss.
|
||||
legacy := []string{"Anna", "Jörg", "anna", "anna2", "日", "x.y"}
|
||||
for i, name := range legacy {
|
||||
if _, err := db.ExecContext(ctx,
|
||||
`INSERT INTO account (uid, legacy_name, password, created_at) VALUES ($1, $2, '', 0)`,
|
||||
i+1, name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
log := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
if err := MigrateHandles(ctx, db, log); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{"anna", "joerg", "anna3", "anna2", "user5", "x_y"}
|
||||
for i, w := range want {
|
||||
var handle, display string
|
||||
if err := db.QueryRowContext(ctx,
|
||||
`SELECT handle, display_name FROM account WHERE uid = $1`, i+1).Scan(&handle, &display); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if handle != w || display != legacy[i] {
|
||||
t.Errorf("uid %d (%q): handle %q, anzeigename %q; erwartet %q", i+1, legacy[i], handle, display, w)
|
||||
}
|
||||
}
|
||||
// Zweiter Lauf ändert nichts, und handle ist jetzt Pflicht.
|
||||
if err := MigrateHandles(ctx, db, log); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := db.ExecContext(ctx,
|
||||
`INSERT INTO account (uid, password, created_at) VALUES (99, '', 0)`); err == nil {
|
||||
t.Error("Konto ohne Handle angelegt")
|
||||
}
|
||||
|
||||
changes, err := NewStore(db, time.Now).HandleChanges(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var got []string
|
||||
for _, c := range changes {
|
||||
got = append(got, c.LegacyName+">"+c.Handle)
|
||||
}
|
||||
// "Anna" -> anna fehlt: nur die Schreibweise änderte sich.
|
||||
if w := "Jörg>joerg anna>anna3 日>user5 x.y>x_y"; strings.Join(got, " ") != w {
|
||||
t.Errorf("HandleChanges = %v, erwartet %s", got, w)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"kver/internal/apperr"
|
||||
"kver/internal/database"
|
||||
"kver/internal/runes"
|
||||
)
|
||||
|
||||
// MaxBioRunes begrenzt die Profilbeschreibung.
|
||||
const MaxBioRunes = 300
|
||||
|
||||
// Profile ist das öffentliche Profil eines Kontos (GET /u/{handle}/info).
|
||||
type Profile struct {
|
||||
UID int64 `json:"uid"`
|
||||
Handle string `json:"handle"`
|
||||
DisplayName string `json:"display_name"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
Avatar string `json:"avatar"`
|
||||
// Header ist das Header-Bild, '' = keins.
|
||||
Header string `json:"header"`
|
||||
Bio string `json:"bio"`
|
||||
// Entries zählt die nicht gelöschten Beiträge.
|
||||
Entries int64 `json:"entries"`
|
||||
}
|
||||
|
||||
// Info ist das eigene Konto (GET /user/info).
|
||||
type Info struct {
|
||||
UID int64 `json:"uid"`
|
||||
Handle string `json:"handle"`
|
||||
DisplayName string `json:"display_name"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
LastLogin int64 `json:"last_login"`
|
||||
Avatar string `json:"avatar"`
|
||||
}
|
||||
|
||||
// notFoundOr bildet sql.ErrNoRows auf ErrUserNotFound ab, alles andere auf
|
||||
// einen Lesefehler.
|
||||
func notFoundOr(err error, what string) error {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return ErrUserNotFound
|
||||
}
|
||||
return fmt.Errorf("%s lesen: %w", what, err)
|
||||
}
|
||||
|
||||
// Profile liefert das öffentliche Profil zum Handle (Eingabe wie vom Nutzer).
|
||||
func (s *Store) Profile(ctx context.Context, handle string) (Profile, error) {
|
||||
var p Profile
|
||||
err := s.db.QueryRowContext(ctx,
|
||||
`SELECT uid, handle, display_name, created_at, avatar, header, bio,
|
||||
(SELECT COUNT(*) FROM entry e WHERE e.uid = a.uid AND e.deleted = 0)
|
||||
FROM account a WHERE handle = $1`, NormalizeHandle(handle),
|
||||
).Scan(&p.UID, &p.Handle, &p.DisplayName, &p.CreatedAt, &p.Avatar, &p.Header, &p.Bio, &p.Entries)
|
||||
if err != nil {
|
||||
return Profile{}, notFoundOr(err, "profil")
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Info liefert das Konto zu uid.
|
||||
func (s *Store) Info(ctx context.Context, uid int64) (Info, error) {
|
||||
i := Info{UID: uid}
|
||||
var lastLogin sql.NullInt64
|
||||
err := s.db.QueryRowContext(ctx,
|
||||
`SELECT created_at, last_login, handle, display_name, avatar FROM account WHERE uid = $1`, uid,
|
||||
).Scan(&i.CreatedAt, &lastLogin, &i.Handle, &i.DisplayName, &i.Avatar)
|
||||
if err != nil {
|
||||
return Info{}, notFoundOr(err, "konto")
|
||||
}
|
||||
i.LastLogin = lastLogin.Int64
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// ErrHandleUnchanged: der neue Handle ist der bisherige.
|
||||
var ErrHandleUnchanged = apperr.Invalid("user.handle_unchanged", "Das ist bereits dein Handle.").At("handle")
|
||||
|
||||
// SetHandle ändert den Handle des Kontos (Eingabe wie vom Nutzer) und liefert
|
||||
// ihn normalisiert zurück. Alles hängt an der uid, daher genügt ein UPDATE;
|
||||
// Links auf das alte /u/<handle> laufen danach ins Leere.
|
||||
func (s *Store) SetHandle(ctx context.Context, uid int64, handle string) (string, error) {
|
||||
handle = NormalizeHandle(handle)
|
||||
if !ValidHandle(handle) {
|
||||
return "", ErrHandleInvalid
|
||||
}
|
||||
res, err := s.db.ExecContext(ctx,
|
||||
`UPDATE account SET handle = $1 WHERE uid = $2 AND handle <> $1`, handle, uid)
|
||||
if err != nil {
|
||||
// Vergeben, auch im Rennen zweier gleichzeitiger Änderungen.
|
||||
if database.IsUniqueViolation(err, "account_handle_key") {
|
||||
return "", ErrHandleTaken.WithCause(err)
|
||||
}
|
||||
return "", fmt.Errorf("handle setzen: %w", err)
|
||||
}
|
||||
if n, _ := res.RowsAffected(); n == 0 {
|
||||
return "", ErrHandleUnchanged
|
||||
}
|
||||
return handle, nil
|
||||
}
|
||||
|
||||
// SetDisplayName setzt den bereinigten Anzeigenamen (CleanDisplayName) und
|
||||
// liefert ihn; leer heißt: Handle anzeigen.
|
||||
func (s *Store) SetDisplayName(ctx context.Context, uid int64, name string) (string, error) {
|
||||
name = CleanDisplayName(name)
|
||||
if _, err := s.db.ExecContext(ctx,
|
||||
`UPDATE account SET display_name = $1 WHERE uid = $2`, name, uid); err != nil {
|
||||
return "", fmt.Errorf("anzeigename setzen: %w", err)
|
||||
}
|
||||
return name, nil
|
||||
}
|
||||
|
||||
// SetBio setzt die Profilbeschreibung: Klartext, getrimmt, auf MaxBioRunes
|
||||
// gekürzt; leer löscht sie. Liefert den gespeicherten Text.
|
||||
func (s *Store) SetBio(ctx context.Context, uid int64, bio string) (string, error) {
|
||||
bio = strings.ReplaceAll(bio, "\r\n", "\n")
|
||||
bio = runes.Truncate(strings.TrimSpace(bio), MaxBioRunes)
|
||||
if _, err := s.db.ExecContext(ctx,
|
||||
`UPDATE account SET bio = $1 WHERE uid = $2`, bio, uid); err != nil {
|
||||
return "", fmt.Errorf("beschreibung setzen: %w", err)
|
||||
}
|
||||
return bio, nil
|
||||
}
|
||||
|
||||
// Image ist eines der Profilbilder: Spalte in account und zugleich Name des
|
||||
// Formularfelds.
|
||||
type Image string
|
||||
|
||||
const (
|
||||
Avatar Image = "avatar"
|
||||
Header Image = "header"
|
||||
)
|
||||
|
||||
// Die Abfragen stehen fest im Code, damit kein Spaltenname in SQL
|
||||
// zusammengesetzt wird. Der Self-Join liefert das bisherige Bild (prev sieht
|
||||
// die Zeile vor dem UPDATE), ohne eigene Abfrage davor.
|
||||
var setImageQuery = map[Image]string{
|
||||
Avatar: `UPDATE account a SET avatar = $1 FROM account prev
|
||||
WHERE a.uid = $2 AND prev.uid = a.uid RETURNING prev.avatar`,
|
||||
Header: `UPDATE account a SET header = $1 FROM account prev
|
||||
WHERE a.uid = $2 AND prev.uid = a.uid RETURNING prev.header`,
|
||||
}
|
||||
|
||||
// SetImage setzt das Profilbild img auf path (leer entfernt es) und liefert den
|
||||
// bisherigen Pfad, damit der Aufrufer die alte Datei löschen kann.
|
||||
func (s *Store) SetImage(ctx context.Context, uid int64, img Image, path string) (string, error) {
|
||||
var old string
|
||||
if err := s.db.QueryRowContext(ctx, setImageQuery[img], path, uid).Scan(&old); err != nil {
|
||||
return "", notFoundOr(err, "profilbild")
|
||||
}
|
||||
return old, nil
|
||||
}
|
||||
|
||||
// Delete löscht das Konto und alles, was nur ihm gehört: Sessions,
|
||||
// Reset-Links, Schlüssel und Direktnachrichten. Was von ihm im Forum steht
|
||||
// (Beiträge, Votes, Erwähnungen, Benachrichtigungen), räumt der Aufrufer in
|
||||
// derselben Transaktion ab -- die Beiträge bleiben als Platzhalter erhalten,
|
||||
// damit fremde Antworten nicht verwaisen.
|
||||
func (s *Store) Delete(ctx context.Context, tx *sql.Tx, uid int64) error {
|
||||
for _, q := range []string{
|
||||
`DELETE FROM session WHERE uid = $1`,
|
||||
`DELETE FROM password_reset WHERE uid = $1`,
|
||||
`DELETE FROM account_key WHERE uid = $1`,
|
||||
`DELETE FROM message WHERE sender = $1 OR recipient = $1`,
|
||||
`DELETE FROM account WHERE uid = $1`,
|
||||
} {
|
||||
if _, err := tx.ExecContext(ctx, q, uid); err != nil {
|
||||
return fmt.Errorf("konto löschen: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -29,9 +29,11 @@ const resetTTL = 72 * time.Hour
|
||||
// Nutzer ist das dasselbe: einen neuen Link holen.
|
||||
var ErrResetInvalid = apperr.NotFound("reset.invalid", "Der Link ist ungültig oder abgelaufen.")
|
||||
|
||||
// hashResetToken: in der DB steht nur der Hash. SHA-256 statt bcrypt genügt,
|
||||
// das Token ist 256 Bit Zufall und nicht zu erraten.
|
||||
func hashResetToken(token string) string {
|
||||
// HashToken: in der DB steht von Reset-Links und Sessions nur der Hash; wer
|
||||
// die DB (oder ein Backup) liest, kann damit weder ein Passwort setzen noch
|
||||
// eine Sitzung übernehmen. SHA-256 statt bcrypt genügt, das Token ist 256 Bit
|
||||
// Zufall (NewToken) und nicht zu erraten.
|
||||
func HashToken(token string) string {
|
||||
sum := sha256.Sum256([]byte(token))
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
@@ -57,7 +59,7 @@ func (s *Store) CreateResetToken(ctx context.Context, handle string) (string, ti
|
||||
}
|
||||
if _, err := tx.ExecContext(ctx,
|
||||
`INSERT INTO password_reset (uid, token_hash, created_at, expires) VALUES ($1, $2, $3, $4)`,
|
||||
uid, hashResetToken(token), now.Unix(), expires.Unix()); err != nil {
|
||||
uid, HashToken(token), now.Unix(), expires.Unix()); err != nil {
|
||||
return fmt.Errorf("reset-link anlegen: %w", err)
|
||||
}
|
||||
return nil
|
||||
@@ -75,7 +77,7 @@ func (s *Store) ResetHandle(ctx context.Context, token string) (string, error) {
|
||||
err := s.db.QueryRowContext(ctx,
|
||||
`SELECT a.handle FROM password_reset p JOIN account a ON a.uid = p.uid
|
||||
WHERE p.token_hash = $1 AND p.expires >= $2`,
|
||||
hashResetToken(token), s.now().Unix(),
|
||||
HashToken(token), s.now().Unix(),
|
||||
).Scan(&handle)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return "", ErrResetInvalid
|
||||
@@ -138,7 +140,7 @@ func (s *Store) consumeReset(ctx context.Context, tx *sql.Tx, token string) (int
|
||||
var uid int64
|
||||
err := tx.QueryRowContext(ctx,
|
||||
`DELETE FROM password_reset WHERE token_hash = $1 AND expires >= $2 RETURNING uid`,
|
||||
hashResetToken(token), s.now().Unix(),
|
||||
HashToken(token), s.now().Unix(),
|
||||
).Scan(&uid)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return 0, ErrResetInvalid
|
||||
|
||||
@@ -7,7 +7,10 @@
|
||||
// und der HTTP-Status ergibt sich allein aus Kind (siehe httpapi).
|
||||
package apperr
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Kind ist die Schwere eines Fehlers. Bewusst kein HTTP-Status: die Zuordnung
|
||||
// passiert erst im Adapter, damit ein CLI- oder App-Client dieselben Fehler
|
||||
@@ -33,7 +36,13 @@ type Error struct {
|
||||
Msg string // deutsche Nutzermeldung
|
||||
Field string // optional: betroffenes Formularfeld
|
||||
Fields map[string]string // optional: mehrere Feldfehler auf einmal
|
||||
cause error // nur fürs Log, nie für den Nutzer
|
||||
// Extra sind Nutzdaten, die der Client neben dem Fehler braucht (etwa
|
||||
// retry_after beim Repost-Cooldown); der Adapter legt sie neben "error".
|
||||
Extra map[string]any
|
||||
// RetryAfter sagt bei KindRateLimited, wann es sich lohnt, es erneut zu
|
||||
// versuchen (HTTP: Header Retry-After). 0 = keine Angabe.
|
||||
RetryAfter time.Duration
|
||||
cause error // nur fürs Log, nie für den Nutzer
|
||||
}
|
||||
|
||||
func (e *Error) Error() string { return e.Code + ": " + e.Msg }
|
||||
@@ -86,6 +95,20 @@ func (e *Error) WithFields(fields map[string]string) *Error {
|
||||
return &c
|
||||
}
|
||||
|
||||
// WithExtra hängt Nutzdaten an, die neben dem Fehler ausgeliefert werden.
|
||||
func (e *Error) WithExtra(extra map[string]any) *Error {
|
||||
c := *e
|
||||
c.Extra = extra
|
||||
return &c
|
||||
}
|
||||
|
||||
// WithRetryAfter vermerkt, wann ein erneuter Versuch Aussicht hat.
|
||||
func (e *Error) WithRetryAfter(d time.Duration) *Error {
|
||||
c := *e
|
||||
c.RetryAfter = d
|
||||
return &c
|
||||
}
|
||||
|
||||
// WithCause hängt eine technische Ursache an einen fachlichen Fehler, etwa
|
||||
// wenn ein DB-Fehler fachlich eindeutig ist, die Ursache aber ins Log soll.
|
||||
func (e *Error) WithCause(cause error) *Error {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestModifiersCopy(t *testing.T) {
|
||||
@@ -17,9 +18,12 @@ func TestModifiersCopy(t *testing.T) {
|
||||
{"At", sentinel.At("feld")},
|
||||
{"WithFields", sentinel.WithFields(map[string]string{"a": "b"})},
|
||||
{"WithCause", sentinel.WithCause(cause)},
|
||||
{"WithExtra", sentinel.WithExtra(map[string]any{"n": 1})},
|
||||
{"WithRetryAfter", sentinel.WithRetryAfter(time.Minute)},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if sentinel.Field != "" || sentinel.Fields != nil || sentinel.Unwrap() != nil {
|
||||
if sentinel.Field != "" || sentinel.Fields != nil || sentinel.Unwrap() != nil ||
|
||||
sentinel.Extra != nil || sentinel.RetryAfter != 0 {
|
||||
t.Fatalf("%s hat das Sentinel verändert: %+v", tt.name, sentinel)
|
||||
}
|
||||
if !errors.Is(fmt.Errorf("verpackt: %w", tt.err), sentinel) {
|
||||
|
||||
@@ -1,38 +1,33 @@
|
||||
-- Schema der App, beim Start idempotent angewendet (siehe database.Open).
|
||||
-- Zeitstempel sind Unix-Sekunden (BIGINT) statt timestamptz: das JSON-Format
|
||||
-- der API liefert sie so aus, und die Bump-Rechnung arbeitet direkt damit.
|
||||
-- "user" ist in Postgres ein reserviertes Wort, daher heißt die Tabelle account.
|
||||
-- Es beschreibt den Ist-Stand: Es gibt genau eine Datenbank (Rolling
|
||||
-- Release), Umbauten werden direkt dort ausgeführt und hier eingetragen; alte
|
||||
-- Migrationsschritte verbleiben nicht. Zeitstempel sind Unix-Sekunden (BIGINT)
|
||||
-- statt timestamptz: das JSON-Format der API liefert sie so aus, und die
|
||||
-- Bump-Rechnung arbeitet direkt damit. "user" ist in Postgres ein
|
||||
-- reserviertes Wort, daher heißt die Tabelle account.
|
||||
|
||||
-- handle: @name, eindeutig, nur a-z0-9_ (account.ValidHandle); display_name:
|
||||
-- freier Anzeigename, '' = Handle anzeigen.
|
||||
-- freier Anzeigename, '' = Handle anzeigen. legacy_name ist der Unicode-
|
||||
-- Nutzername aus der Zeit vor der Trennung (bis 11/2026), NULL bei jüngeren
|
||||
-- Konten; er bleibt, bis alle Betroffenen ihren neuen Handle kennen
|
||||
-- (kver handles).
|
||||
CREATE TABLE IF NOT EXISTS account (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
uid BIGINT NOT NULL UNIQUE,
|
||||
handle TEXT NOT NULL UNIQUE,
|
||||
display_name TEXT NOT NULL DEFAULT '',
|
||||
legacy_name TEXT UNIQUE,
|
||||
password BYTEA NOT NULL,
|
||||
created_at BIGINT NOT NULL,
|
||||
last_login BIGINT,
|
||||
avatar TEXT NOT NULL DEFAULT ''
|
||||
avatar TEXT NOT NULL DEFAULT '',
|
||||
-- Profil: Header-Bild ('' = keins) und Beschreibung (Klartext).
|
||||
header TEXT NOT NULL DEFAULT '',
|
||||
bio TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
-- Bis 11/2026 gab es nur einen Unicode-Nutzernamen (username). Er bleibt als
|
||||
-- legacy_name erhalten, bis alle Betroffenen ihren neuen Handle kennen
|
||||
-- (kver handles); handle und display_name füllt account.MigrateHandles.
|
||||
DO $$ BEGIN
|
||||
IF EXISTS (SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = current_schema() AND table_name = 'account'
|
||||
AND column_name = 'username') THEN
|
||||
ALTER TABLE account RENAME COLUMN username TO legacy_name;
|
||||
ALTER TABLE account ALTER COLUMN legacy_name DROP NOT NULL;
|
||||
END IF;
|
||||
END $$;
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS legacy_name TEXT;
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS handle TEXT UNIQUE;
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS display_name TEXT NOT NULL DEFAULT '';
|
||||
-- Profil: Beschreibung (Klartext) und Header-Bild, '' = keins.
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS bio TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE account ADD COLUMN IF NOT EXISTS header TEXT NOT NULL DEFAULT '';
|
||||
|
||||
-- value ist der SHA-256 des Cookie-Werts (account.HashToken), nie der Wert
|
||||
-- selbst.
|
||||
CREATE TABLE IF NOT EXISTS session (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
uid BIGINT NOT NULL,
|
||||
@@ -42,6 +37,11 @@ CREATE TABLE IF NOT EXISTS session (
|
||||
description TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
-- link_url: kanonische URL des ersten Links im Inhalt (linkpreview.Key), ''
|
||||
-- ohne Link. image_warning/image_cover: Hinweis vor dem Bild (kver
|
||||
-- cover-image). Steht ein Text da, zeigt das Frontend statt des Bilds die
|
||||
-- verpixelte Variante image_cover, bis jemand "Inhalt anzeigen" klickt. Für
|
||||
-- Bilder, die erlaubt sind, aber nicht jedem ungefragt begegnen müssen.
|
||||
CREATE TABLE IF NOT EXISTS entry (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
pid BIGINT NOT NULL UNIQUE,
|
||||
@@ -54,16 +54,11 @@ CREATE TABLE IF NOT EXISTS entry (
|
||||
last_activity BIGINT NOT NULL DEFAULT 0,
|
||||
deleted BIGINT NOT NULL DEFAULT 0,
|
||||
bump_count BIGINT NOT NULL DEFAULT 0,
|
||||
last_bump BIGINT NOT NULL DEFAULT 0
|
||||
last_bump BIGINT NOT NULL DEFAULT 0,
|
||||
link_url TEXT NOT NULL DEFAULT '',
|
||||
image_warning TEXT NOT NULL DEFAULT '',
|
||||
image_cover TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
-- Kanonische URL des ersten Links im Inhalt (previewKey), '' ohne Link.
|
||||
ALTER TABLE entry ADD COLUMN IF NOT EXISTS link_url TEXT NOT NULL DEFAULT '';
|
||||
-- Hinweis vor dem Bild (kver cover-image): Steht hier ein Text, zeigt das
|
||||
-- Frontend statt des Bilds die verpixelte Variante image_cover, bis jemand
|
||||
-- "Inhalt anzeigen" klickt. Für Bilder, die erlaubt sind, aber nicht jedem
|
||||
-- ungefragt begegnen müssen.
|
||||
ALTER TABLE entry ADD COLUMN IF NOT EXISTS image_warning TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE entry ADD COLUMN IF NOT EXISTS image_cover TEXT NOT NULL DEFAULT '';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS vote (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
@@ -122,10 +117,10 @@ CREATE TABLE IF NOT EXISTS link_preview (
|
||||
site TEXT NOT NULL DEFAULT '',
|
||||
thumb TEXT NOT NULL DEFAULT '',
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
fetched_at BIGINT NOT NULL DEFAULT 0
|
||||
fetched_at BIGINT NOT NULL DEFAULT 0,
|
||||
attempts INT NOT NULL DEFAULT 0,
|
||||
retry_at BIGINT NOT NULL DEFAULT 0
|
||||
);
|
||||
ALTER TABLE link_preview ADD COLUMN IF NOT EXISTS attempts INT NOT NULL DEFAULT 0;
|
||||
ALTER TABLE link_preview ADD COLUMN IF NOT EXISTS retry_at BIGINT NOT NULL DEFAULT 0;
|
||||
|
||||
-- OpenPGP-Schlüssel (v6) der Accounts für Ende-zu-Ende-verschlüsselte
|
||||
-- Direktnachrichten, siehe notes/schluessel.md. public_key ist das binäre
|
||||
@@ -202,8 +197,7 @@ CREATE TABLE IF NOT EXISTS mention (
|
||||
CREATE INDEX IF NOT EXISTS idx_mention_uid ON mention(uid);
|
||||
|
||||
-- Hashtags je Beitrag, klein geschrieben, für die Vorschläge beim Tippen
|
||||
-- (häufigste zuerst). Gepflegt beim Anlegen/Bearbeiten/Löschen, bestehende
|
||||
-- Beiträge trägt httpapi.BackfillTags beim Start nach.
|
||||
-- (häufigste zuerst). Gepflegt beim Anlegen/Bearbeiten/Löschen (syncTags).
|
||||
CREATE TABLE IF NOT EXISTS entry_tag (
|
||||
pid BIGINT NOT NULL,
|
||||
tag TEXT NOT NULL,
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/http/cookiejar"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -111,12 +112,35 @@ func TestRegisterLoginSession(t *testing.T) {
|
||||
if got := getStatus(t, c, srv.URL+"/api/auth/sessioninfo"); got != http.StatusOK {
|
||||
t.Fatalf("sessioninfo nach Login: erwartet 200, bekam %d", got)
|
||||
}
|
||||
// In der DB steht nur der Hash des Cookie-Werts.
|
||||
cookie := sessionCookieValue(t, c, srv.URL)
|
||||
var plain, hashed int
|
||||
if err := srv.db.QueryRow(`SELECT COUNT(*) FILTER (WHERE value = $1), COUNT(*) FILTER (WHERE value = $2) FROM session`,
|
||||
cookie, account.HashToken(cookie)).Scan(&plain, &hashed); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if plain != 0 || hashed != 1 {
|
||||
t.Fatalf("session in der DB: %d im Klartext, %d gehasht", plain, hashed)
|
||||
}
|
||||
// Anonymer Client hat keine Session.
|
||||
if got := getStatus(t, newClient(t), srv.URL+"/api/auth/sessioninfo"); got != http.StatusUnauthorized {
|
||||
t.Fatalf("sessioninfo anonym: erwartet 401, bekam %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
// sessionCookieValue liest den Session-Cookie aus dem Jar des Clients.
|
||||
func sessionCookieValue(t *testing.T, c *http.Client, srvURL string) string {
|
||||
t.Helper()
|
||||
u, _ := url.Parse(srvURL)
|
||||
for _, ck := range c.Jar.Cookies(u) {
|
||||
if ck.Name == sessionCookie {
|
||||
return ck.Value
|
||||
}
|
||||
}
|
||||
t.Fatal("kein Session-Cookie")
|
||||
return ""
|
||||
}
|
||||
|
||||
// getStatus macht einen GET und liefert nur den Statuscode.
|
||||
func getStatus(t *testing.T, c *http.Client, urlStr string) int {
|
||||
t.Helper()
|
||||
@@ -224,6 +248,15 @@ func TestVoteRequiresAuthAndValidMode(t *testing.T) {
|
||||
if resp.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("ungültiger Modus: erwartet 400, bekam %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
// Gelöschte Beiträge nehmen keine Stimmen mehr an.
|
||||
resp = postForm(t, alice, fmt.Sprintf("%s/api/entry/%d/delete", srv.URL, pid), url.Values{})
|
||||
resp.Body.Close()
|
||||
resp = postForm(t, alice, voteURL, url.Values{"mode": {"yes"}})
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusNotFound {
|
||||
t.Fatalf("vote auf gelöschten Beitrag: erwartet 404, bekam %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBump(t *testing.T) {
|
||||
@@ -257,12 +290,25 @@ func TestBump(t *testing.T) {
|
||||
}
|
||||
|
||||
// Cooldown gilt pro Beitrag (global): auch ein anderer Nutzer wird sofort
|
||||
// abgewiesen.
|
||||
// abgewiesen -- mit Restzeit im Header und neben dem Fehler im Body.
|
||||
resp = postForm(t, bob, bumpURL, url.Values{})
|
||||
resp.Body.Close()
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusTooManyRequests {
|
||||
t.Fatalf("bump im cooldown: erwartet 429, bekam %d", resp.StatusCode)
|
||||
}
|
||||
var cool struct {
|
||||
Error errorBody `json:"error"`
|
||||
RetryAfter int64 `json:"retry_after"`
|
||||
BumpCount int64 `json:"bump_count"`
|
||||
}
|
||||
json.NewDecoder(resp.Body).Decode(&cool)
|
||||
if cool.Error.Code != "entry.bump_cooldown" || cool.BumpCount != 1 ||
|
||||
cool.RetryAfter <= 0 || cool.RetryAfter > 86400 {
|
||||
t.Fatalf("cooldown-antwort: %+v", cool)
|
||||
}
|
||||
if ra, _ := strconv.ParseInt(resp.Header.Get("Retry-After"), 10, 64); ra != cool.RetryAfter {
|
||||
t.Fatalf("Retry-After %q, body %d", resp.Header.Get("Retry-After"), cool.RetryAfter)
|
||||
}
|
||||
|
||||
// Gelöschter Beitrag lässt sich nicht bumpen.
|
||||
del := createEntry(t, alice, srv, post("weg gleich"))
|
||||
@@ -819,19 +865,13 @@ func TestPasswordResetReplacesSession(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
registerAndLogin(t, srv, "alice")
|
||||
bob := registerAndLogin(t, srv, "bob")
|
||||
var bobSession string
|
||||
u, _ := url.Parse(srv.URL)
|
||||
for _, ck := range bob.Jar.Cookies(u) {
|
||||
if ck.Name == sessionCookie {
|
||||
bobSession = ck.Value
|
||||
}
|
||||
}
|
||||
bobSession := sessionCookieValue(t, bob, srv.URL)
|
||||
form := resetForm(srv.resetToken(t, "alice"), "drittesgeheim")
|
||||
if got := postStatus(t, bob, srv.URL+"/api/auth/reset", form); got != http.StatusOK {
|
||||
t.Fatalf("reset mit fremder Session: erwartet 200, bekam %d", got)
|
||||
}
|
||||
var n int
|
||||
if err := srv.db.QueryRow(`SELECT COUNT(*) FROM session WHERE value = $1`, bobSession).Scan(&n); err != nil {
|
||||
if err := srv.db.QueryRow(`SELECT COUNT(*) FROM session WHERE value = $1`, account.HashToken(bobSession)).Scan(&n); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != 0 {
|
||||
@@ -950,7 +990,7 @@ func TestCrossOriginPostRejected(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
c := registerAndLogin(t, srv, "alice")
|
||||
|
||||
post := func(origin string) int {
|
||||
post := func(origin, fetchSite string) int {
|
||||
req, err := http.NewRequest(http.MethodPost, srv.URL+"/api/entry/create",
|
||||
strings.NewReader(url.Values{"content": {"x"}}.Encode()))
|
||||
if err != nil {
|
||||
@@ -961,6 +1001,9 @@ func TestCrossOriginPostRejected(t *testing.T) {
|
||||
if origin != "" {
|
||||
req.Header.Set("Origin", origin)
|
||||
}
|
||||
if fetchSite != "" {
|
||||
req.Header.Set("Sec-Fetch-Site", fetchSite)
|
||||
}
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -969,17 +1012,24 @@ func TestCrossOriginPostRejected(t *testing.T) {
|
||||
return resp.StatusCode
|
||||
}
|
||||
|
||||
if got := post("https://boese-seite.example"); got != http.StatusForbidden {
|
||||
t.Fatalf("cross-origin POST: erwartet 403, bekam %d", got)
|
||||
}
|
||||
if got := post("null"); got != http.StatusForbidden {
|
||||
t.Fatalf("Origin null: erwartet 403, bekam %d", got)
|
||||
}
|
||||
if got := post(srv.URL); got != http.StatusCreated {
|
||||
t.Fatalf("same-origin POST: erwartet 201, bekam %d", got)
|
||||
}
|
||||
if got := post(""); got != http.StatusCreated {
|
||||
t.Fatalf("POST ohne Origin: erwartet 201, bekam %d", got)
|
||||
for _, tc := range []struct {
|
||||
name, origin, fetchSite string
|
||||
want int
|
||||
}{
|
||||
{"cross-origin", "https://boese-seite.example", "", http.StatusForbidden},
|
||||
{"Origin null", "null", "", http.StatusForbidden},
|
||||
{"Sec-Fetch-Site cross-site", "", "cross-site", http.StatusForbidden},
|
||||
// Andere Subdomain: Origin stimmt nicht, auch wenn Browser "same-site" sagen.
|
||||
{"Sec-Fetch-Site same-site", "", "same-site", http.StatusForbidden},
|
||||
{"passender Origin, aber cross-site", srv.URL, "cross-site", http.StatusForbidden},
|
||||
{"same-origin", srv.URL, "same-origin", http.StatusCreated},
|
||||
{"nur Origin", srv.URL, "", http.StatusCreated},
|
||||
{"Nutzer selbst (none)", "", "none", http.StatusCreated},
|
||||
{"ohne beides (curl)", "", "", http.StatusCreated},
|
||||
} {
|
||||
if got := post(tc.origin, tc.fetchSite); got != tc.want {
|
||||
t.Errorf("%s: erwartet %d, bekam %d", tc.name, tc.want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,15 +50,24 @@ func (s *Server) handleCreateEntry(w http.ResponseWriter, r *http.Request) error
|
||||
return apperr.Internal(err)
|
||||
}
|
||||
s.Previews.Request(r.Context(), in.linkURL)
|
||||
writeJSON(w, http.StatusCreated, map[string]any{
|
||||
"pid": pid,
|
||||
"content": in.content,
|
||||
"filepath": in.filepath,
|
||||
"reply_to": in.replyTo,
|
||||
})
|
||||
writeJSON(w, http.StatusCreated, createdJSON{PID: pid, Content: in.content, Filepath: in.filepath, ReplyTo: in.replyTo})
|
||||
return nil
|
||||
}
|
||||
|
||||
// createdJSON ist die Antwort auf einen angelegten Beitrag.
|
||||
type createdJSON struct {
|
||||
PID int64 `json:"pid"`
|
||||
Content string `json:"content"`
|
||||
Filepath string `json:"filepath"`
|
||||
ReplyTo int64 `json:"reply_to"`
|
||||
}
|
||||
|
||||
// editedJSON ist die Antwort auf einen bearbeiteten Beitrag.
|
||||
type editedJSON struct {
|
||||
PID int64 `json:"pid"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// readNewEntry prüft das Formular und speichert ein angehängtes Bild.
|
||||
func (s *Server) readNewEntry(r *http.Request) (newEntry, error) {
|
||||
in := newEntry{
|
||||
@@ -191,7 +200,7 @@ func (s *Server) handleEditEntry(w http.ResponseWriter, r *http.Request) error {
|
||||
return apperr.Internal(err)
|
||||
}
|
||||
s.Previews.Request(r.Context(), linkURL)
|
||||
writeJSON(w, http.StatusOK, map[string]any{"pid": e.PID, "content": content})
|
||||
writeJSON(w, http.StatusOK, editedJSON{PID: e.PID, Content: content})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -221,22 +230,8 @@ func (s *Server) handleDeleteEntry(w http.ResponseWriter, r *http.Request) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Mit dem Beitrag verschwinden seine Erwähnungen und die Benachrichtigungen,
|
||||
// die ihn zitieren.
|
||||
if err := database.InTx(r.Context(), s.DB, func(tx *sql.Tx) error {
|
||||
if _, err := tx.ExecContext(r.Context(),
|
||||
`UPDATE entry SET deleted = 1, content = '', filepath = '', image_warning = '', image_cover = '', link_url = '', uid = 0 WHERE pid = $1`,
|
||||
e.PID); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.ExecContext(r.Context(), `DELETE FROM mention WHERE pid = $1`, e.PID); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.ExecContext(r.Context(), `DELETE FROM entry_tag WHERE pid = $1`, e.PID); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.ExecContext(r.Context(), `DELETE FROM notification WHERE pid = $1`, e.PID)
|
||||
return err
|
||||
return softDeleteEntries(r.Context(), tx, "pid = $1", e.PID)
|
||||
}); err != nil {
|
||||
return apperr.Internal(err)
|
||||
}
|
||||
@@ -246,6 +241,28 @@ func (s *Server) handleDeleteEntry(w http.ResponseWriter, r *http.Request) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// softDeleteEntries löscht alle Beiträge weich, auf die cond (eine
|
||||
// WHERE-Bedingung über entry mit $1 = arg, fest im Code) zutrifft: Inhalt,
|
||||
// Bild, Link und Autor werden geleert, die Zeile bleibt als
|
||||
// [deleted]-Platzhalter. Mit den Beiträgen verschwinden ihre Erwähnungen,
|
||||
// Hashtags und die Benachrichtigungen, die sie zitieren. Die Dateien
|
||||
// (filepath, image_cover) löscht der Aufrufer.
|
||||
func softDeleteEntries(ctx context.Context, tx *sql.Tx, cond string, arg any) error {
|
||||
pids := `(SELECT pid FROM entry WHERE ` + cond + `)`
|
||||
for _, q := range []string{
|
||||
`DELETE FROM mention WHERE pid IN ` + pids,
|
||||
`DELETE FROM entry_tag WHERE pid IN ` + pids,
|
||||
`DELETE FROM notification WHERE pid IN ` + pids,
|
||||
`UPDATE entry SET deleted = 1, content = '', filepath = '', image_warning = '', image_cover = '',
|
||||
link_url = '', uid = 0 WHERE ` + cond,
|
||||
} {
|
||||
if _, err := tx.ExecContext(ctx, q, arg); err != nil {
|
||||
return fmt.Errorf("beiträge löschen: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleReport meldet einen Beitrag, optional mit Grund. Melden darf jeder;
|
||||
// ohne Session ist der Melder anonym (uid 0). Angemeldete legen für denselben
|
||||
// Beitrag keine zweite Meldung an, solange ihre erste offen ist.
|
||||
|
||||
@@ -19,17 +19,24 @@ func serveApp(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, webDir+"/index.html")
|
||||
}
|
||||
|
||||
// serveAssets liefert die gebauten JS/CSS-Dateien. Ihre Namen enthalten einen
|
||||
// Inhalts-Hash, sie ändern sich also nie -> dauerhaft cachebar. Verzeichnisse
|
||||
// gibt es nicht zu sehen (kein Listing).
|
||||
func serveAssets() http.Handler {
|
||||
files := http.FileServer(http.Dir(webDir))
|
||||
// serveFiles liefert Dateien aus dir mit festem Cache-Control, aber ohne
|
||||
// Verzeichnislisting: http.FileServer zeigt sonst für jeden Pfad mit
|
||||
// Schluss-"/" den Inhalt des Verzeichnisses -- unter static/media wäre das die
|
||||
// Liste aller Uploads.
|
||||
func serveFiles(dir, cacheControl string) http.Handler {
|
||||
files := http.FileServer(http.Dir(dir))
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasSuffix(r.URL.Path, "/") {
|
||||
// Leer: StripPrefix hat "/static/" selbst zu "" gemacht, das wäre das
|
||||
// Wurzelverzeichnis.
|
||||
if r.URL.Path == "" || strings.HasSuffix(r.URL.Path, "/") {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
||||
w.Header().Set("Cache-Control", cacheControl)
|
||||
files.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// immutable ist das Cache-Control für Dateien, deren Name sich mit dem Inhalt
|
||||
// ändert: gehashte Assets und Uploads mit zufälligem Namen.
|
||||
const immutable = "public, max-age=31536000, immutable"
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestServeFilesNoListing: Dateien kommen durch, Verzeichnisse liefern 404
|
||||
// statt einer Liste ihres Inhalts.
|
||||
func TestServeFilesNoListing(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(dir, "media"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "media", "a.jpg"), []byte("x"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h := http.StripPrefix("/static/", serveFiles(dir, immutable))
|
||||
for path, want := range map[string]int{
|
||||
"/static/media/a.jpg": http.StatusOK,
|
||||
"/static/media/": http.StatusNotFound,
|
||||
"/static/": http.StatusNotFound,
|
||||
"/static/fehlt.jpg": http.StatusNotFound,
|
||||
} {
|
||||
rr := httptest.NewRecorder()
|
||||
h.ServeHTTP(rr, httptest.NewRequest(http.MethodGet, path, nil))
|
||||
if rr.Code != want {
|
||||
t.Errorf("GET %s: %d, erwartet %d", path, rr.Code, want)
|
||||
}
|
||||
if rr.Code == http.StatusOK && rr.Header().Get("Cache-Control") != immutable {
|
||||
t.Errorf("GET %s: Cache-Control %q", path, rr.Header().Get("Cache-Control"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,8 +68,8 @@ func syncMentions(ctx context.Context, tx *sql.Tx, pid, author, replyTo int64, c
|
||||
return fmt.Errorf("erwähnungen speichern: %w", err)
|
||||
}
|
||||
if _, err := tx.ExecContext(ctx,
|
||||
`DELETE FROM notification WHERE pid = $1 AND kind = 'mention'
|
||||
AND uid NOT IN (SELECT uid FROM mention WHERE pid = $1)`, pid); err != nil {
|
||||
`DELETE FROM notification WHERE pid = $1 AND kind = $2
|
||||
AND uid NOT IN (SELECT uid FROM mention WHERE pid = $1)`, pid, kindMention); err != nil {
|
||||
return fmt.Errorf("erwähnungen abgleichen: %w", err)
|
||||
}
|
||||
after, err := mentionedUIDs(ctx, tx, pid)
|
||||
@@ -89,8 +89,8 @@ func syncMentions(ctx context.Context, tx *sql.Tx, pid, author, replyTo int64, c
|
||||
}
|
||||
if _, err := tx.ExecContext(ctx,
|
||||
`INSERT INTO notification (uid, kind, actor, excerpt, link, pid, created_at)
|
||||
VALUES ($1, 'mention', $2, $3, $4, $5, $6)`,
|
||||
uid, author, excerpt(content), fmt.Sprintf("/e/%d", pid), pid, now); err != nil {
|
||||
VALUES ($1, $7, $2, $3, $4, $5, $6)`,
|
||||
uid, author, excerpt(content), entryLink(pid), pid, now, kindMention); err != nil {
|
||||
return fmt.Errorf("benachrichtigung anlegen: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,18 +72,25 @@ func secHeaders(next http.Handler) http.Handler {
|
||||
var errBadOrigin = apperr.Forbidden("csrf.bad_origin", "Anfrage von fremder Seite abgelehnt")
|
||||
|
||||
// checkOrigin weist zustandsändernde Cross-Site-Requests ab (CSRF-Schutz,
|
||||
// zusätzlich zu SameSite=Lax für ältere Browser bzw. GET-Navigationen).
|
||||
// Browser setzen bei Cross-Site-Requests immer einen Origin-Header; fehlt er
|
||||
// (Nicht-Browser-Clients wie curl, gleiche Site bei manchen Browsern), lassen
|
||||
// wir durch -- der Cookie-Schutz greift dort ohnehin nicht bzw. schon.
|
||||
// zusätzlich zu SameSite=Lax für ältere Browser bzw. GET-Navigationen). Zwei
|
||||
// Quellen, beide vom Browser gesetzt und von Seiten nicht fälschbar:
|
||||
// Sec-Fetch-Site sagt direkt, ob der Request von derselben Origin kommt
|
||||
// (same-origin) oder vom Nutzer selbst ausgeht (none: Adresszeile,
|
||||
// Lesezeichen); Origin wird gegen den Host verglichen. Fehlen beide
|
||||
// (Nicht-Browser-Clients wie curl), lassen wir durch -- der Cookie-Schutz
|
||||
// greift dort ohnehin nicht.
|
||||
func checkOrigin(r *http.Request) error {
|
||||
o := r.Header.Get("Origin")
|
||||
if r.Method == http.MethodGet || r.Method == http.MethodHead || o == "" {
|
||||
if r.Method == http.MethodGet || r.Method == http.MethodHead {
|
||||
return nil
|
||||
}
|
||||
if u, err := url.Parse(o); err != nil || u.Host != r.Host {
|
||||
if site := r.Header.Get("Sec-Fetch-Site"); site != "" && site != "same-origin" && site != "none" {
|
||||
return errBadOrigin
|
||||
}
|
||||
if o := r.Header.Get("Origin"); o != "" {
|
||||
if u, err := url.Parse(o); err != nil || u.Host != r.Host {
|
||||
return errBadOrigin
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -134,8 +141,9 @@ type ctxKey struct{}
|
||||
|
||||
var errAuthRequired = apperr.Unauth("auth.required", "Nicht angemeldet")
|
||||
|
||||
// requireAuth lehnt Anfragen ohne gültige Session ab und legt die uid in den
|
||||
// Context.
|
||||
// requireAuth lehnt Anfragen ohne gültige Session ab und legt die Session in
|
||||
// den Context -- einmal lesen genügt, die Handler holen sie sich von dort
|
||||
// (currentSession, currentUID).
|
||||
func (s *Server) requireAuth(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
sess, ok := s.session(r)
|
||||
@@ -143,14 +151,18 @@ func (s *Server) requireAuth(next http.Handler) http.Handler {
|
||||
s.writeError(w, r, errAuthRequired)
|
||||
return
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), ctxKey{}, sess.UID)
|
||||
ctx := context.WithValue(r.Context(), ctxKey{}, sess)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
// currentSession ist die Session des angemeldeten Nutzers (nur hinter
|
||||
// requireAuth gesetzt).
|
||||
func currentSession(r *http.Request) session {
|
||||
sess, _ := r.Context().Value(ctxKey{}).(session)
|
||||
return sess
|
||||
}
|
||||
|
||||
// currentUID ist die uid des angemeldeten Nutzers (nur hinter requireAuth
|
||||
// gesetzt).
|
||||
func currentUID(r *http.Request) int64 {
|
||||
id, _ := r.Context().Value(ctxKey{}).(int64)
|
||||
return id
|
||||
}
|
||||
func currentUID(r *http.Request) int64 { return currentSession(r).UID }
|
||||
|
||||
@@ -18,6 +18,13 @@ const (
|
||||
excerptRunes = 50
|
||||
)
|
||||
|
||||
// Arten von Benachrichtigungen (Spalte notification.kind, Feld kind der API).
|
||||
const (
|
||||
kindReply = "reply" // Antwort auf einen eigenen Beitrag
|
||||
kindMention = "mention" // in einem Beitrag erwähnt
|
||||
kindBump = "bump" // eigener Beitrag repostet
|
||||
)
|
||||
|
||||
// notificationJSON ist eine Benachrichtigung in der Liste. Seen meldet den
|
||||
// Stand vor dem Abruf: so sieht die Liste, was neu war, obwohl der Abruf
|
||||
// selbst alles als gesehen markiert.
|
||||
@@ -41,6 +48,10 @@ func excerpt(content string) string {
|
||||
return e
|
||||
}
|
||||
|
||||
// entryLink ist der interne Pfad zu einem Beitrag, wie ihn eine
|
||||
// Benachrichtigung trägt.
|
||||
func entryLink(pid int64) string { return fmt.Sprintf("/e/%d", pid) }
|
||||
|
||||
// notificationMessage ist die Zeile, die sagt, was passiert ist. actor ist
|
||||
// der Handle dessen, der geantwortet hat; leer (Reposts, unbekannt) heißt
|
||||
// "Jemand". Den Auszug liefert die API getrennt.
|
||||
@@ -50,9 +61,9 @@ func notificationMessage(kind, actor string) string {
|
||||
who = "@" + actor
|
||||
}
|
||||
switch kind {
|
||||
case "reply":
|
||||
case kindReply:
|
||||
return who + " hat auf deinen Beitrag geantwortet."
|
||||
case "mention":
|
||||
case kindMention:
|
||||
return who + " hat dich erwähnt."
|
||||
}
|
||||
return who + " hat deinen Beitrag repostet."
|
||||
@@ -64,9 +75,9 @@ func notificationMessage(kind, actor string) string {
|
||||
func notifyReply(ctx context.Context, tx *sql.Tx, in newEntry, pid int64) error {
|
||||
if _, err := tx.ExecContext(ctx,
|
||||
`INSERT INTO notification (uid, kind, actor, excerpt, link, pid, created_at)
|
||||
SELECT uid, 'reply', $1, $2, $3, $4, $5 FROM entry
|
||||
SELECT uid, $7, $1, $2, $3, $4, $5 FROM entry
|
||||
WHERE pid = $6 AND uid <> 0 AND uid <> $1`,
|
||||
in.uid, excerpt(in.content), fmt.Sprintf("/e/%d", pid), pid, in.created, in.replyTo); err != nil {
|
||||
in.uid, excerpt(in.content), entryLink(pid), pid, in.created, in.replyTo, kindReply); err != nil {
|
||||
return fmt.Errorf("benachrichtigung anlegen: %w", err)
|
||||
}
|
||||
return nil
|
||||
@@ -86,8 +97,8 @@ func notifyBump(ctx context.Context, tx *sql.Tx, pid, bumper, now int64) error {
|
||||
}
|
||||
if _, err := tx.ExecContext(ctx,
|
||||
`INSERT INTO notification (uid, kind, excerpt, link, pid, created_at)
|
||||
VALUES ($1, 'bump', $2, $3, $4, $5)`,
|
||||
author, excerpt(content), fmt.Sprintf("/e/%d", pid), pid, now); err != nil {
|
||||
VALUES ($1, $6, $2, $3, $4, $5)`,
|
||||
author, excerpt(content), entryLink(pid), pid, now, kindBump); err != nil {
|
||||
return fmt.Errorf("benachrichtigung anlegen: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"kver/internal/account"
|
||||
)
|
||||
|
||||
type profileJSON struct {
|
||||
@@ -75,7 +77,7 @@ func TestProfileBio(t *testing.T) {
|
||||
t.Fatalf("bio: erwartet 200, bekam %d", got)
|
||||
}
|
||||
p := getProfile(t, srv, "alice")
|
||||
if !strings.HasPrefix(p.Bio, "Zeile 1\nZeile 2 ö") || len([]rune(p.Bio)) != maxBioRunes {
|
||||
if !strings.HasPrefix(p.Bio, "Zeile 1\nZeile 2 ö") || len([]rune(p.Bio)) != account.MaxBioRunes {
|
||||
t.Fatalf("bio falsch gespeichert: %q (%d Runen)", p.Bio, len([]rune(p.Bio)))
|
||||
}
|
||||
if p.Entries != 2 {
|
||||
|
||||
@@ -3,6 +3,8 @@ package httpapi
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"kver/internal/apperr"
|
||||
)
|
||||
@@ -57,6 +59,8 @@ type errorBody struct {
|
||||
Fields map[string]string `json:"fields,omitempty"`
|
||||
}
|
||||
|
||||
// errorResponse ist die Fehlerantwort, wie Clients sie lesen: "error" plus
|
||||
// eventuelle Zusatzfelder (apperr.Error.Extra) daneben.
|
||||
type errorResponse struct {
|
||||
Error errorBody `json:"error"`
|
||||
}
|
||||
@@ -69,9 +73,16 @@ func (s *Server) writeError(w http.ResponseWriter, r *http.Request, err error) {
|
||||
if e.Kind == apperr.KindInternal {
|
||||
s.Log.Error("interner fehler", "method", r.Method, "path", r.URL.Path, "err", e.Unwrap())
|
||||
}
|
||||
writeJSON(w, statusOf(e.Kind), errorResponse{errorBody{
|
||||
Code: e.Code, Message: e.Msg, Field: e.Field, Fields: e.Fields,
|
||||
}})
|
||||
if e.RetryAfter > 0 {
|
||||
w.Header().Set("Retry-After", strconv.FormatInt(int64(e.RetryAfter/time.Second), 10))
|
||||
}
|
||||
body := map[string]any{"error": errorBody{Code: e.Code, Message: e.Msg, Field: e.Field, Fields: e.Fields}}
|
||||
for k, v := range e.Extra {
|
||||
if k != "error" {
|
||||
body[k] = v
|
||||
}
|
||||
}
|
||||
writeJSON(w, statusOf(e.Kind), body)
|
||||
}
|
||||
|
||||
// statusOf bildet Kind auf HTTP ab -- die einzige Stelle, an der das passiert.
|
||||
|
||||
@@ -169,7 +169,8 @@ func (s *Server) pageRoutes(r chi.Router) {
|
||||
r.Get("/stats.html", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/stats", http.StatusMovedPermanently)
|
||||
})
|
||||
r.Handle("/assets/*", serveAssets())
|
||||
// Gebaute JS/CSS-Dateien: Namen mit Inhalts-Hash, dauerhaft cachebar.
|
||||
r.Handle("/assets/*", serveFiles(webDir, immutable))
|
||||
// Alte Adressen der Rechtstexte (bis 2026-10 statische Seiten).
|
||||
for _, name := range []string{"impressum", "datenschutz", "beitragsordnung"} {
|
||||
r.Get("/static/docs/"+name+".html", func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -177,9 +178,11 @@ func (s *Server) pageRoutes(r chi.Router) {
|
||||
})
|
||||
}
|
||||
|
||||
// Hochgeladene Medien + statische Dateien (Schriften, Bilder).
|
||||
// Hochgeladene Medien + statische Dateien (Schriften, Bilder). Uploads
|
||||
// haben zufällige, einmalige Namen (media.Store.create) und sind damit
|
||||
// dauerhaft cachebar; die Assets ändern sich praktisch nie.
|
||||
// nosniff (global via secHeaders) verhindert, dass der Browser eine
|
||||
// durchgereichte (nicht re-kodierte) Datei als HTML/JS interpretiert ->
|
||||
// schließt Polyglot/Stored-XSS über Bild-Uploads.
|
||||
r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
r.Handle("/static/*", http.StripPrefix("/static/", serveFiles("static", immutable)))
|
||||
}
|
||||
|
||||
+19
-10
@@ -22,6 +22,9 @@ const (
|
||||
maxSessionTTL = 365 * 24 * time.Hour
|
||||
)
|
||||
|
||||
// session ist eine Sitzung aus der DB. Value ist der Hash des Cookie-Werts
|
||||
// (account.HashToken) -- so steht sie in der Tabelle, der Klartext nur im
|
||||
// Cookie.
|
||||
type session struct {
|
||||
UID int64
|
||||
CreatedAt int64
|
||||
@@ -45,9 +48,9 @@ func (s *Server) session(r *http.Request) (session, bool) {
|
||||
if err != nil || c.Value == "" {
|
||||
return session{}, false
|
||||
}
|
||||
sess := session{Value: c.Value}
|
||||
sess := session{Value: account.HashToken(c.Value)}
|
||||
err = s.DB.QueryRowContext(r.Context(),
|
||||
`SELECT uid, created_at, expires, description FROM session WHERE value = $1`, c.Value,
|
||||
`SELECT uid, created_at, expires, description FROM session WHERE value = $1`, sess.Value,
|
||||
).Scan(&sess.UID, &sess.CreatedAt, &sess.Expires, &sess.Description)
|
||||
if err != nil {
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
@@ -109,8 +112,9 @@ func sessionTTL(r *http.Request) time.Duration {
|
||||
return time.Duration(min(sec, int64(maxSessionTTL/time.Second))) * time.Second
|
||||
}
|
||||
|
||||
// startSession legt eine Session an und setzt den Cookie. Nebenbei räumt es
|
||||
// abgelaufene Sessions weg und vermerkt den Login.
|
||||
// startSession legt eine Session an und setzt den Cookie; gespeichert wird
|
||||
// nur der Hash des Tokens. Nebenbei räumt es abgelaufene Sessions weg und
|
||||
// vermerkt den Login.
|
||||
func (s *Server) startSession(w http.ResponseWriter, r *http.Request, uid int64) error {
|
||||
ctx := r.Context()
|
||||
now := s.Now()
|
||||
@@ -124,7 +128,7 @@ func (s *Server) startSession(w http.ResponseWriter, r *http.Request, uid int64)
|
||||
}
|
||||
if _, err := s.DB.ExecContext(ctx,
|
||||
`INSERT INTO session (uid, created_at, expires, description, value) VALUES ($1, $2, $3, '', $4)`,
|
||||
uid, now.Unix(), expires.Unix(), token); err != nil {
|
||||
uid, now.Unix(), expires.Unix(), account.HashToken(token)); err != nil {
|
||||
return apperr.Internal(err)
|
||||
}
|
||||
if _, err := s.DB.ExecContext(ctx, `UPDATE account SET last_login = $1 WHERE uid = $2`,
|
||||
@@ -177,15 +181,20 @@ func (s *Server) handleSessionInfo(w http.ResponseWriter, r *http.Request) error
|
||||
if !ok {
|
||||
return apperr.Unauth("auth.no_session", "Keine gültige Sitzung.")
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"uid": sess.UID,
|
||||
"created_at": sess.CreatedAt,
|
||||
"expires": sess.Expires,
|
||||
"description": sess.Description,
|
||||
writeJSON(w, http.StatusOK, sessionJSON{
|
||||
UID: sess.UID, CreatedAt: sess.CreatedAt, Expires: sess.Expires, Description: sess.Description,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// sessionJSON ist die Sitzung im Drahtformat (ohne den Token).
|
||||
type sessionJSON struct {
|
||||
UID int64 `json:"uid"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
Expires int64 `json:"expires"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// handleNewUser sammelt alle Validierungsfehler ein, statt beim ersten
|
||||
// abzubrechen -- der Nutzer soll nicht Feld für Feld durchprobieren müssen.
|
||||
func (s *Server) handleNewUser(w http.ResponseWriter, r *http.Request) error {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"kver/internal/apperr"
|
||||
"kver/internal/database"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -55,54 +54,6 @@ func syncTags(ctx context.Context, tx *sql.Tx, pid int64, content string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// BackfillTags trägt die Hashtags bestehender Beiträge nach, solange die
|
||||
// Liste leer ist, es aber Beiträge mit "#" gibt -- also einmal nach dem
|
||||
// Einführen von entry_tag. Ein erneuter Lauf rechnet nur dasselbe nach.
|
||||
func BackfillTags(ctx context.Context, db *sql.DB) (int, error) {
|
||||
var needed bool
|
||||
if err := db.QueryRowContext(ctx,
|
||||
`SELECT NOT EXISTS (SELECT 1 FROM entry_tag)
|
||||
AND EXISTS (SELECT 1 FROM entry WHERE deleted = 0 AND content LIKE '%#%')`).Scan(&needed); err != nil {
|
||||
return 0, fmt.Errorf("hashtags prüfen: %w", err)
|
||||
}
|
||||
if !needed {
|
||||
return 0, nil
|
||||
}
|
||||
n := 0
|
||||
err := database.InTx(ctx, db, func(tx *sql.Tx) error {
|
||||
rows, err := tx.QueryContext(ctx,
|
||||
`SELECT pid, content FROM entry WHERE deleted = 0 AND content LIKE '%#%'`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("beiträge lesen: %w", err)
|
||||
}
|
||||
type post struct {
|
||||
pid int64
|
||||
content string
|
||||
}
|
||||
var posts []post
|
||||
for rows.Next() {
|
||||
var p post
|
||||
if err := rows.Scan(&p.pid, &p.content); err != nil {
|
||||
rows.Close()
|
||||
return fmt.Errorf("beiträge lesen: %w", err)
|
||||
}
|
||||
posts = append(posts, p)
|
||||
}
|
||||
rows.Close()
|
||||
if err := rows.Err(); err != nil {
|
||||
return fmt.Errorf("beiträge lesen: %w", err)
|
||||
}
|
||||
for _, p := range posts {
|
||||
if err := syncTags(ctx, tx, p.pid, p.content); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
n = len(posts)
|
||||
return nil
|
||||
})
|
||||
return n, err
|
||||
}
|
||||
|
||||
// tagSuggestionJSON ist ein Vorschlag für die Autovervollständigung von #tag.
|
||||
type tagSuggestionJSON struct {
|
||||
Tag string `json:"tag"`
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -69,25 +68,3 @@ func TestTagSuggest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackfillTags(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := newTestServer(t)
|
||||
alice := registerAndLogin(t, srv, "alice")
|
||||
createEntry(t, alice, srv, post("#alt #Alt"))
|
||||
createEntry(t, alice, srv, post("#alt"))
|
||||
ctx := context.Background()
|
||||
// Stand vor entry_tag: Beiträge mit Tags, Liste leer.
|
||||
if _, err := srv.db.ExecContext(ctx, `DELETE FROM entry_tag`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, err := BackfillTags(ctx, srv.db); err != nil || n != 2 {
|
||||
t.Fatalf("BackfillTags: %d, %v", n, err)
|
||||
}
|
||||
if n, err := BackfillTags(ctx, srv.db); err != nil || n != 0 {
|
||||
t.Errorf("zweiter Lauf: %d, %v", n, err)
|
||||
}
|
||||
if got := suggestTags(t, srv, "a"); !slices.Equal(got, []string{"alt:2"}) {
|
||||
t.Errorf("nach backfill: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
+57
-136
@@ -6,103 +6,49 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"kver/internal/account"
|
||||
"kver/internal/apperr"
|
||||
"kver/internal/database"
|
||||
"kver/internal/runes"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// notFoundOr bildet sql.ErrNoRows auf account.ErrUserNotFound ab, alles
|
||||
// andere auf einen internen Fehler.
|
||||
func notFoundOr(err error) error {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return account.ErrUserNotFound
|
||||
}
|
||||
return apperr.Internal(err)
|
||||
}
|
||||
|
||||
// maxBioRunes begrenzt die Profilbeschreibung.
|
||||
const maxBioRunes = 300
|
||||
// Die Kontozugriffe liegen in account.Store; hier wird nur gelesen, was im
|
||||
// Request steht, und geantwortet.
|
||||
|
||||
func (s *Server) handleUserPage(w http.ResponseWriter, r *http.Request) error {
|
||||
var uid, createdAt, entries int64
|
||||
var handle, displayName, avatar, header, bio string
|
||||
if err := s.DB.QueryRowContext(r.Context(),
|
||||
`SELECT uid, handle, display_name, created_at, avatar, header, bio,
|
||||
(SELECT COUNT(*) FROM entry e WHERE e.uid = a.uid AND e.deleted = 0)
|
||||
FROM account a WHERE handle = $1`, account.NormalizeHandle(chi.URLParam(r, "handle")),
|
||||
).Scan(&uid, &handle, &displayName, &createdAt, &avatar, &header, &bio, &entries); err != nil {
|
||||
return notFoundOr(err)
|
||||
p, err := s.accounts.Profile(r.Context(), chi.URLParam(r, "handle"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"uid": uid,
|
||||
"handle": handle,
|
||||
"display_name": displayName,
|
||||
"created_at": createdAt,
|
||||
"avatar": avatar,
|
||||
"header": header,
|
||||
"bio": bio,
|
||||
"entries": entries,
|
||||
})
|
||||
writeJSON(w, http.StatusOK, p)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) handleUserInfo(w http.ResponseWriter, r *http.Request) error {
|
||||
uid := currentUID(r)
|
||||
var createdAt, lastLogin sql.NullInt64
|
||||
var handle, displayName, avatar string
|
||||
if err := s.DB.QueryRowContext(r.Context(),
|
||||
`SELECT created_at, last_login, handle, display_name, avatar FROM account WHERE uid = $1`, uid,
|
||||
).Scan(&createdAt, &lastLogin, &handle, &displayName, &avatar); err != nil {
|
||||
return notFoundOr(err)
|
||||
info, err := s.accounts.Info(r.Context(), currentUID(r))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"uid": uid,
|
||||
"handle": handle,
|
||||
"display_name": displayName,
|
||||
"created_at": createdAt.Int64,
|
||||
"last_login": lastLogin.Int64,
|
||||
"avatar": avatar,
|
||||
})
|
||||
writeJSON(w, http.StatusOK, info)
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleSetHandle ändert den Handle des eingeloggten Accounts. Alles hängt an
|
||||
// der uid, daher genügt ein UPDATE; Links auf das alte /u/<handle> laufen
|
||||
// danach ins Leere.
|
||||
func (s *Server) handleSetHandle(w http.ResponseWriter, r *http.Request) error {
|
||||
handle := account.NormalizeHandle(r.FormValue("handle"))
|
||||
if !account.ValidHandle(handle) {
|
||||
return account.ErrHandleInvalid
|
||||
}
|
||||
res, err := s.DB.ExecContext(r.Context(),
|
||||
`UPDATE account SET handle = $1 WHERE uid = $2 AND handle <> $1`, handle, currentUID(r))
|
||||
handle, err := s.accounts.SetHandle(r.Context(), currentUID(r), r.FormValue("handle"))
|
||||
if err != nil {
|
||||
// Vergeben, auch im Rennen zweier gleichzeitiger Änderungen: 409.
|
||||
if database.IsUniqueViolation(err, "account_handle_key") {
|
||||
return account.ErrHandleTaken
|
||||
}
|
||||
return apperr.Internal(err)
|
||||
}
|
||||
if n, _ := res.RowsAffected(); n == 0 {
|
||||
return apperr.Invalid("user.handle_unchanged", "Das ist bereits dein Handle.").At("handle")
|
||||
return err
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]string{"handle": handle})
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleSetDisplayName setzt den Anzeigenamen; leer heißt: Handle anzeigen.
|
||||
func (s *Server) handleSetDisplayName(w http.ResponseWriter, r *http.Request) error {
|
||||
name := account.CleanDisplayName(r.FormValue("display_name"))
|
||||
if _, err := s.DB.ExecContext(r.Context(),
|
||||
`UPDATE account SET display_name = $1 WHERE uid = $2`, name, currentUID(r)); err != nil {
|
||||
return apperr.Internal(err)
|
||||
name, err := s.accounts.SetDisplayName(r.Context(), currentUID(r), r.FormValue("display_name"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]string{"display_name": name})
|
||||
return nil
|
||||
@@ -118,65 +64,62 @@ func (s *Server) handleUserPassword(w http.ResponseWriter, r *http.Request) erro
|
||||
if len(fields) > 0 {
|
||||
return errInvalidForm.WithFields(fields)
|
||||
}
|
||||
sess, _ := s.session(r)
|
||||
if err := s.accounts.ChangePassword(r.Context(), currentUID(r), r.FormValue("pass"), pass1, sess.Value); err != nil {
|
||||
return err
|
||||
sess := currentSession(r)
|
||||
if err := s.accounts.ChangePassword(r.Context(), sess.UID, r.FormValue("pass"), pass1, sess.Value); err != nil {
|
||||
return wrongPasswordAt(err, "pass")
|
||||
}
|
||||
writeJSON(w, http.StatusOK, status{"ok"})
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleSetBio setzt die Profilbeschreibung des eingeloggten Nutzers; leer
|
||||
// löscht sie. Klartext, Links macht erst das Frontend klickbar.
|
||||
// wrongPasswordAt hängt an ein falsches Passwort das Formularfeld, in dem es
|
||||
// stand; andere Fehler gehen unverändert durch.
|
||||
func wrongPasswordAt(err error, field string) error {
|
||||
if errors.Is(err, account.ErrWrongPassword) {
|
||||
return account.ErrWrongPassword.At(field)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Server) handleSetBio(w http.ResponseWriter, r *http.Request) error {
|
||||
bio := strings.ReplaceAll(r.FormValue("bio"), "\r\n", "\n")
|
||||
bio = runes.Truncate(strings.TrimSpace(bio), maxBioRunes)
|
||||
if _, err := s.DB.ExecContext(r.Context(),
|
||||
`UPDATE account SET bio = $1 WHERE uid = $2`, bio, currentUID(r)); err != nil {
|
||||
return apperr.Internal(err)
|
||||
bio, err := s.accounts.SetBio(r.Context(), currentUID(r), r.FormValue("bio"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]string{"bio": bio})
|
||||
return nil
|
||||
}
|
||||
|
||||
// Profilbilder: Spalte in account, zugleich Name des Formularfelds. Die
|
||||
// Abfragen stehen fest im Code, damit kein Spaltenname in SQL zusammengesetzt
|
||||
// wird. Der Self-Join liefert das bisherige Bild (prev sieht die Zeile vor dem
|
||||
// UPDATE), ohne eigene Abfrage davor.
|
||||
var setImageQuery = map[string]string{
|
||||
"avatar": `UPDATE account a SET avatar = $1 FROM account prev
|
||||
WHERE a.uid = $2 AND prev.uid = a.uid RETURNING prev.avatar`,
|
||||
"header": `UPDATE account a SET header = $1 FROM account prev
|
||||
WHERE a.uid = $2 AND prev.uid = a.uid RETURNING prev.header`,
|
||||
}
|
||||
|
||||
// handleSetAvatar speichert ein hochgeladenes Profilbild des eingeloggten
|
||||
// Nutzers und ersetzt ein eventuell vorhandenes.
|
||||
func (s *Server) handleSetAvatar(w http.ResponseWriter, r *http.Request) error {
|
||||
return s.setImage(w, r, "avatar")
|
||||
return s.setImage(w, r, account.Avatar)
|
||||
}
|
||||
|
||||
// handleSetHeader speichert das Header-Bild des Profils.
|
||||
func (s *Server) handleSetHeader(w http.ResponseWriter, r *http.Request) error {
|
||||
return s.setImage(w, r, "header")
|
||||
return s.setImage(w, r, account.Header)
|
||||
}
|
||||
|
||||
// handleRemoveHeader entfernt das Header-Bild; das Profil zeigt dann den
|
||||
// schwarzen Balken.
|
||||
func (s *Server) handleRemoveHeader(w http.ResponseWriter, r *http.Request) error {
|
||||
old, err := s.replaceImage(r.Context(), "header", "", currentUID(r))
|
||||
old, err := s.accounts.SetImage(r.Context(), currentUID(r), account.Header, "")
|
||||
if err != nil {
|
||||
return notFoundOr(err)
|
||||
return err
|
||||
}
|
||||
s.removeMedia(old)
|
||||
writeJSON(w, http.StatusOK, map[string]string{"header": ""})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) setImage(w http.ResponseWriter, r *http.Request, field string) error {
|
||||
// setImage liest das Bild aus dem gleichnamigen Formularfeld, speichert es
|
||||
// und ersetzt das bisherige.
|
||||
func (s *Server) setImage(w http.ResponseWriter, r *http.Request, img account.Image) error {
|
||||
if err := parseUpload(w, r); err != nil {
|
||||
return err
|
||||
}
|
||||
field := string(img)
|
||||
fh := formFile(r, field)
|
||||
if fh == nil {
|
||||
return apperr.Invalid(field+".missing", "Kein Bild hochgeladen.").At(field)
|
||||
@@ -185,10 +128,10 @@ func (s *Server) setImage(w http.ResponseWriter, r *http.Request, field string)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
old, err := s.replaceImage(r.Context(), field, stored, currentUID(r))
|
||||
old, err := s.accounts.SetImage(r.Context(), currentUID(r), img, stored)
|
||||
if err != nil {
|
||||
s.removeMedia(stored)
|
||||
return notFoundOr(err)
|
||||
return err
|
||||
}
|
||||
if old != stored {
|
||||
s.removeMedia(old)
|
||||
@@ -197,13 +140,6 @@ func (s *Server) setImage(w http.ResponseWriter, r *http.Request, field string)
|
||||
return nil
|
||||
}
|
||||
|
||||
// replaceImage setzt die Bildspalte field und liefert den bisherigen Pfad.
|
||||
func (s *Server) replaceImage(ctx context.Context, field, path string, uid int64) (string, error) {
|
||||
var old string
|
||||
err := s.DB.QueryRowContext(ctx, setImageQuery[field], path, uid).Scan(&old)
|
||||
return old, err
|
||||
}
|
||||
|
||||
// handleUserDelete löscht den eingeloggten Account dauerhaft, nach
|
||||
// Bestätigung durch das Passwort (Formularfeld pass1). Sessions, Reset-Links
|
||||
// und Votes werden in einer Transaktion mitgelöscht; die eigenen Beiträge
|
||||
@@ -211,8 +147,8 @@ func (s *Server) replaceImage(ctx context.Context, field, path string, uid int64
|
||||
// Antworten nicht verwaisen. Mediendateien werden danach best effort entfernt.
|
||||
func (s *Server) handleUserDelete(w http.ResponseWriter, r *http.Request) error {
|
||||
ctx, uid := r.Context(), currentUID(r)
|
||||
if err := s.checkPassword(ctx, uid, r.FormValue("pass1"), "pass1"); err != nil {
|
||||
return err
|
||||
if err := s.accounts.VerifyPassword(ctx, uid, r.FormValue("pass1")); err != nil {
|
||||
return wrongPasswordAt(err, "pass1")
|
||||
}
|
||||
// Mediendateien einsammeln, bevor die Pfade geleert werden.
|
||||
files, err := s.userMedia(ctx, uid)
|
||||
@@ -220,7 +156,10 @@ func (s *Server) handleUserDelete(w http.ResponseWriter, r *http.Request) error
|
||||
return apperr.Internal(err)
|
||||
}
|
||||
if err := database.InTx(ctx, s.DB, func(tx *sql.Tx) error {
|
||||
return deleteAccount(ctx, tx, uid)
|
||||
if err := deleteUserContent(ctx, tx, uid); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.accounts.Delete(ctx, tx, uid)
|
||||
}); err != nil {
|
||||
return apperr.Internal(err)
|
||||
}
|
||||
@@ -232,20 +171,6 @@ func (s *Server) handleUserDelete(w http.ResponseWriter, r *http.Request) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkPassword bestätigt eine heikle Aktion mit dem Passwort des Nutzers;
|
||||
// field ist das Formularfeld für die Fehlermeldung.
|
||||
func (s *Server) checkPassword(ctx context.Context, uid int64, pass, field string) error {
|
||||
var hash []byte
|
||||
if err := s.DB.QueryRowContext(ctx,
|
||||
`SELECT password FROM account WHERE uid = $1`, uid).Scan(&hash); err != nil {
|
||||
return notFoundOr(err)
|
||||
}
|
||||
if bcrypt.CompareHashAndPassword(hash, []byte(pass)) != nil {
|
||||
return apperr.Forbidden("auth.bad_password", "Passwort ist falsch.").At(field)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// userMedia liefert die Mediendateien eines Nutzers: Beitragsbilder samt
|
||||
// verpixelter Varianten, Profil- und Header-Bild.
|
||||
func (s *Server) userMedia(ctx context.Context, uid int64) ([]string, error) {
|
||||
@@ -272,23 +197,19 @@ func (s *Server) userMedia(ctx context.Context, uid int64) ([]string, error) {
|
||||
return files, rows.Err()
|
||||
}
|
||||
|
||||
func deleteAccount(ctx context.Context, tx *sql.Tx, uid int64) error {
|
||||
// deleteUserContent räumt ab, was von uid im Forum steht: Votes,
|
||||
// Benachrichtigungen an und von ihm, Erwähnungen seiner Person; die Beiträge
|
||||
// werden weich gelöscht (softDeleteEntries nimmt deren Erwähnungen, Tags und
|
||||
// Benachrichtigungen mit).
|
||||
func deleteUserContent(ctx context.Context, tx *sql.Tx, uid int64) error {
|
||||
for _, q := range []string{
|
||||
`DELETE FROM session WHERE uid = $1`,
|
||||
`DELETE FROM password_reset WHERE uid = $1`,
|
||||
`DELETE FROM vote WHERE uid = $1`,
|
||||
`DELETE FROM account_key WHERE uid = $1`,
|
||||
`DELETE FROM message WHERE sender = $1 OR recipient = $1`,
|
||||
// Vor dem UPDATE auf entry: danach stehen die Beiträge auf uid 0.
|
||||
`DELETE FROM notification WHERE uid = $1 OR actor = $1 OR pid IN (SELECT pid FROM entry WHERE uid = $1)`,
|
||||
`DELETE FROM mention WHERE uid = $1 OR pid IN (SELECT pid FROM entry WHERE uid = $1)`,
|
||||
`DELETE FROM entry_tag WHERE pid IN (SELECT pid FROM entry WHERE uid = $1)`,
|
||||
`UPDATE entry SET deleted = 1, content = '', filepath = '', image_warning = '', image_cover = '', link_url = '', uid = 0 WHERE uid = $1`,
|
||||
`DELETE FROM account WHERE uid = $1`,
|
||||
`DELETE FROM notification WHERE uid = $1 OR actor = $1`,
|
||||
`DELETE FROM mention WHERE uid = $1`,
|
||||
} {
|
||||
if _, err := tx.ExecContext(ctx, q, uid); err != nil {
|
||||
return fmt.Errorf("account löschen: %w", err)
|
||||
return fmt.Errorf("beiträge löschen: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return softDeleteEntries(ctx, tx, "uid = $1", uid)
|
||||
}
|
||||
|
||||
+51
-44
@@ -3,8 +3,9 @@ package httpapi
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"kver/internal/apperr"
|
||||
@@ -74,10 +75,15 @@ func (s *Server) handleVote(w http.ResponseWriter, r *http.Request) error {
|
||||
if mode != "yes" && mode != "no" {
|
||||
return apperr.Invalid("vote.bad_mode", "Ungültiger Modus (yes oder no)").At("mode")
|
||||
}
|
||||
// Nur auf existierende Beiträge abstimmen, sonst entstehen Waisen-Votes.
|
||||
if _, err := s.entryByPID(r.Context(), pid); err != nil {
|
||||
// Nur auf bestehende, nicht gelöschte Beiträge abstimmen, sonst entstehen
|
||||
// Waisen-Votes.
|
||||
e, err := s.entryByPID(r.Context(), pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if e.Deleted != 0 {
|
||||
return errEntryNotFound
|
||||
}
|
||||
uid := currentUID(r)
|
||||
res, err := s.DB.ExecContext(r.Context(),
|
||||
`DELETE FROM vote WHERE uid = $1 AND pid = $2 AND mode = $3`, uid, pid, mode)
|
||||
@@ -100,6 +106,20 @@ func (s *Server) handleVote(w http.ResponseWriter, r *http.Request) error {
|
||||
// jedem Mal teurer.
|
||||
const bumpStep = int64(24 * time.Hour / time.Second)
|
||||
|
||||
// errBumpCooldown trägt neben dem Fehler retry_after und bump_count, mit
|
||||
// denen das Frontend den Knopf sperrt (WithExtra), und den Header Retry-After.
|
||||
var errBumpCooldown = apperr.RateLimited("entry.bump_cooldown", "Dieser Beitrag wurde erst kürzlich repostet.")
|
||||
|
||||
// bumpJSON ist die Antwort auf einen erfolgreichen Repost.
|
||||
type bumpJSON struct {
|
||||
PID int64 `json:"pid"`
|
||||
BumpCount int64 `json:"bump_count"`
|
||||
LastBump int64 `json:"last_bump"`
|
||||
LastActivity int64 `json:"last_activity"`
|
||||
// RetryAfter: Sekunden bis zum nächsten erlaubten Repost.
|
||||
RetryAfter int64 `json:"retry_after"`
|
||||
}
|
||||
|
||||
// handleBump hebt last_activity eines Beitrags auf jetzt -> er steigt im Feed
|
||||
// bzw. in der Antwortliste eines Threads wieder nach oben. Gegen Spam wächst
|
||||
// der Cooldown linear mit der Zahl bisheriger Bumps; er sitzt am Beitrag
|
||||
@@ -109,58 +129,45 @@ func (s *Server) handleBump(w http.ResponseWriter, r *http.Request) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Beim ersten Bump (bump_count 0) ist die Sperre 0 -> sofort erlaubt. Die
|
||||
// Bedingung sitzt direkt im UPDATE (statt Read-then-Write), damit zwei
|
||||
// gleichzeitige Bumps den Cooldown nicht umgehen können.
|
||||
// Ein Statement liest den Stand und bumpt, wenn der Cooldown vorbei ist
|
||||
// (beim ersten Bump, bump_count 0, ist er 0 -> sofort erlaubt). Die
|
||||
// Bedingung sitzt im UPDATE selbst statt in einem Read-then-Write, damit
|
||||
// zwei gleichzeitige Bumps den Cooldown nicht umgehen können; cur liefert
|
||||
// den Stand davor, auch wenn nicht gebumpt wurde (für die Restzeit).
|
||||
now := s.Now().Unix()
|
||||
var bumpCount, lastBump int64
|
||||
var bumped bool
|
||||
if err := database.InTx(r.Context(), s.DB, func(tx *sql.Tx) error {
|
||||
res, err := tx.ExecContext(r.Context(),
|
||||
`UPDATE entry SET last_activity = $1, bump_count = bump_count + 1, last_bump = $1
|
||||
WHERE pid = $2 AND deleted = 0 AND last_bump + bump_count * $3 <= $1`,
|
||||
now, pid, bumpStep)
|
||||
if err != nil {
|
||||
return err
|
||||
err := tx.QueryRowContext(r.Context(),
|
||||
`WITH cur AS (SELECT pid, bump_count, last_bump FROM entry WHERE pid = $2 AND deleted = 0),
|
||||
upd AS (UPDATE entry e SET last_activity = $1, bump_count = e.bump_count + 1, last_bump = $1
|
||||
FROM cur WHERE e.pid = cur.pid AND cur.last_bump + cur.bump_count * $3 <= $1
|
||||
RETURNING e.pid)
|
||||
SELECT cur.bump_count, cur.last_bump, EXISTS (SELECT 1 FROM upd) FROM cur`,
|
||||
now, pid, bumpStep).Scan(&bumpCount, &lastBump, &bumped)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return errEntryNotFound
|
||||
}
|
||||
if n, _ := res.RowsAffected(); n == 0 {
|
||||
if err != nil {
|
||||
return fmt.Errorf("bump: %w", err)
|
||||
}
|
||||
if !bumped {
|
||||
return nil
|
||||
}
|
||||
bumped = true
|
||||
bumpCount++
|
||||
return notifyBump(r.Context(), tx, pid, currentUID(r), now)
|
||||
}); err != nil {
|
||||
return apperr.Internal(err)
|
||||
}
|
||||
var bumpCount, lastBump, deleted int64
|
||||
if err := s.DB.QueryRowContext(r.Context(),
|
||||
`SELECT bump_count, last_bump, deleted FROM entry WHERE pid = $1`, pid).
|
||||
Scan(&bumpCount, &lastBump, &deleted); err != nil || deleted != 0 {
|
||||
return errEntryNotFound
|
||||
return err // errEntryNotFound oder (über writeError) ein interner Fehler
|
||||
}
|
||||
if !bumped {
|
||||
writeBumpCooldown(w, max(lastBump+bumpCount*bumpStep-now, 0), bumpCount)
|
||||
return nil
|
||||
remaining := max(lastBump+bumpCount*bumpStep-now, 0)
|
||||
return errBumpCooldown.
|
||||
WithRetryAfter(time.Duration(remaining) * time.Second).
|
||||
WithExtra(map[string]any{"retry_after": remaining, "bump_count": bumpCount})
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"pid": pid,
|
||||
"bump_count": bumpCount,
|
||||
"last_bump": now,
|
||||
"last_activity": now,
|
||||
"retry_after": bumpCount * bumpStep, // bis zum nächsten erlaubten Bump
|
||||
writeJSON(w, http.StatusOK, bumpJSON{
|
||||
PID: pid, BumpCount: bumpCount, LastBump: now, LastActivity: now,
|
||||
RetryAfter: bumpCount * bumpStep,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeBumpCooldown ist kein Taxonomie-Fehler: die Antwort trägt neben dem
|
||||
// Fehler Nutzdaten (retry_after, bump_count), mit denen das Frontend den
|
||||
// Button sperrt.
|
||||
func writeBumpCooldown(w http.ResponseWriter, remaining, bumpCount int64) {
|
||||
w.Header().Set("Retry-After", strconv.FormatInt(remaining, 10))
|
||||
writeJSON(w, http.StatusTooManyRequests, map[string]any{
|
||||
"error": errorBody{
|
||||
Code: "entry.bump_cooldown",
|
||||
Message: "Dieser Beitrag wurde erst kürzlich repostet.",
|
||||
},
|
||||
"retry_after": remaining,
|
||||
"bump_count": bumpCount,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,8 +19,13 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
xdraw "golang.org/x/image/draw"
|
||||
_ "golang.org/x/image/webp" // WebP-Decoder für image.Decode
|
||||
)
|
||||
|
||||
// Angenommen werden JPEG, PNG, GIF und WebP; die Decoder registrieren sich
|
||||
// über die Importe oben bei image.Decode. Gespeichert wird nie im
|
||||
// Eingangsformat (außer animierte GIFs, siehe SaveUpload), WebP also als JPEG.
|
||||
|
||||
const (
|
||||
// Dir ist das Medienverzeichnis relativ zu Root.
|
||||
Dir = "static/media"
|
||||
@@ -121,11 +126,6 @@ func (s Store) create(dir, pattern string, write func(io.Writer) error) (string,
|
||||
return dir + "/" + filepath.Base(name), nil
|
||||
}
|
||||
|
||||
// isWebP erkennt den RIFF/WEBP-Header.
|
||||
func isWebP(data []byte) bool {
|
||||
return len(data) >= 12 && string(data[:4]) == "RIFF" && string(data[8:12]) == "WEBP"
|
||||
}
|
||||
|
||||
var errGIFTooLarge = errors.New("animiertes GIF zu groß")
|
||||
|
||||
// gifFrames prüft ein GIF gegen Frame- und Pixelbudget und meldet, ob es
|
||||
|
||||
+4
-19
@@ -4,11 +4,8 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"golang.org/x/image/webp"
|
||||
)
|
||||
|
||||
// ThumbSize ist die Zielkante eines Vorschaubilds (klein, steht neben dem Text).
|
||||
@@ -37,29 +34,17 @@ func (s Store) SaveThumb(data []byte, dest string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// decodeChecked dekodiert data nach der Größenprüfung. WebP wird gezielt
|
||||
// dekodiert statt global registriert -- sonst nähme auch SaveUpload WebP an.
|
||||
// decodeChecked dekodiert data nach der Größenprüfung (alle in media.go
|
||||
// registrierten Formate).
|
||||
func decodeChecked(data []byte) (image.Image, error) {
|
||||
decodeConfig := image.DecodeConfig
|
||||
decode := func(r *bytes.Reader) (image.Image, error) {
|
||||
img, _, err := image.Decode(r)
|
||||
return img, err
|
||||
}
|
||||
if isWebP(data) {
|
||||
decodeConfig = func(r io.Reader) (image.Config, string, error) {
|
||||
c, err := webp.DecodeConfig(r)
|
||||
return c, "webp", err
|
||||
}
|
||||
decode = func(r *bytes.Reader) (image.Image, error) { return webp.Decode(r) }
|
||||
}
|
||||
cfg, _, err := decodeConfig(bytes.NewReader(data))
|
||||
cfg, _, err := image.DecodeConfig(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bildformat: %w", err)
|
||||
}
|
||||
if err := checkSize(cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
img, err := decode(bytes.NewReader(data))
|
||||
img, _, err := image.Decode(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bild dekodieren: %w", err)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
// SaveUpload speichert ein hochgeladenes Bild und liefert seinen Pfad.
|
||||
//
|
||||
// Standbilder (JPEG/PNG/Einzelbild-GIF) werden auf maxImageSize skaliert und
|
||||
// Standbilder (JPEG/PNG/WebP/Einzelbild-GIF) werden auf maxImageSize skaliert und
|
||||
// dabei durch Decode+Re-Encode sanitisiert. Animierte GIFs würden durch das
|
||||
// Re-Encode auf das erste Frame reduziert -> sie werden stattdessen unverändert
|
||||
// durchgereicht. Die Bytes sind dann NICHT sanitisiert; deshalb liefert der
|
||||
|
||||
@@ -0,0 +1,738 @@
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
\restrict sfKzavw6BT7S48XgpklDXrRN4BzPBCBJB1apavBd4jjyastMTwALfb7ctd9PV5I
|
||||
|
||||
-- Dumped from database version 18.6 (Debian 18.6-1.pgdg13+2)
|
||||
-- Dumped by pg_dump version 18.6
|
||||
|
||||
-- Started on 2026-11-22 11:57:31 UTC
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET transaction_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 4 (class 2615 OID 2200)
|
||||
-- Name: public; Type: SCHEMA; Schema: -; Owner: pg_database_owner
|
||||
--
|
||||
|
||||
CREATE SCHEMA public;
|
||||
|
||||
|
||||
ALTER SCHEMA public OWNER TO pg_database_owner;
|
||||
|
||||
--
|
||||
-- TOC entry 3589 (class 0 OID 0)
|
||||
-- Dependencies: 4
|
||||
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: pg_database_owner
|
||||
--
|
||||
|
||||
COMMENT ON SCHEMA public IS 'standard public schema';
|
||||
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- TOC entry 220 (class 1259 OID 52996)
|
||||
-- Name: account; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.account (
|
||||
id bigint NOT NULL,
|
||||
uid bigint NOT NULL,
|
||||
legacy_name text,
|
||||
password bytea NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
last_login bigint,
|
||||
avatar text DEFAULT ''::text NOT NULL,
|
||||
bio text DEFAULT ''::text NOT NULL,
|
||||
header text DEFAULT ''::text NOT NULL,
|
||||
handle text NOT NULL,
|
||||
display_name text DEFAULT ''::text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.account OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 219 (class 1259 OID 52995)
|
||||
-- Name: account_id_seq; Type: SEQUENCE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE public.account ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.account_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 234 (class 1259 OID 77480)
|
||||
-- Name: account_key; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.account_key (
|
||||
id bigint NOT NULL,
|
||||
uid bigint NOT NULL,
|
||||
fingerprint bytea NOT NULL,
|
||||
public_key bytea NOT NULL,
|
||||
secret_key bytea NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
replaced_at bigint DEFAULT 0 NOT NULL,
|
||||
lost_at bigint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.account_key OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 233 (class 1259 OID 77479)
|
||||
-- Name: account_key_id_seq; Type: SEQUENCE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE public.account_key ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.account_key_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 224 (class 1259 OID 53032)
|
||||
-- Name: entry; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.entry (
|
||||
id bigint NOT NULL,
|
||||
pid bigint NOT NULL,
|
||||
uid bigint NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
content text DEFAULT ''::text NOT NULL,
|
||||
filepath text DEFAULT ''::text NOT NULL,
|
||||
reply_to bigint DEFAULT 0 NOT NULL,
|
||||
reply_count bigint DEFAULT 0 NOT NULL,
|
||||
last_activity bigint DEFAULT 0 NOT NULL,
|
||||
deleted bigint DEFAULT 0 NOT NULL,
|
||||
bump_count bigint DEFAULT 0 NOT NULL,
|
||||
last_bump bigint DEFAULT 0 NOT NULL,
|
||||
link_url text DEFAULT ''::text NOT NULL,
|
||||
image_warning text DEFAULT ''::text NOT NULL,
|
||||
image_cover text DEFAULT ''::text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.entry OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 223 (class 1259 OID 53031)
|
||||
-- Name: entry_id_seq; Type: SEQUENCE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE public.entry ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.entry_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 240 (class 1259 OID 123529)
|
||||
-- Name: entry_tag; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.entry_tag (
|
||||
pid bigint NOT NULL,
|
||||
tag text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.entry_tag OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 227 (class 1259 OID 53075)
|
||||
-- Name: impression; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.impression (
|
||||
day text NOT NULL,
|
||||
anon_ip text NOT NULL,
|
||||
path text DEFAULT ''::text NOT NULL,
|
||||
asn text DEFAULT ''::text NOT NULL,
|
||||
hits bigint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.impression OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 232 (class 1259 OID 67157)
|
||||
-- Name: link_preview; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.link_preview (
|
||||
url text NOT NULL,
|
||||
kind text DEFAULT ''::text NOT NULL,
|
||||
title text DEFAULT ''::text NOT NULL,
|
||||
site text DEFAULT ''::text NOT NULL,
|
||||
thumb text DEFAULT ''::text NOT NULL,
|
||||
status text DEFAULT 'pending'::text NOT NULL,
|
||||
fetched_at bigint DEFAULT 0 NOT NULL,
|
||||
attempts integer DEFAULT 0 NOT NULL,
|
||||
retry_at bigint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.link_preview OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 239 (class 1259 OID 123498)
|
||||
-- Name: mention; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.mention (
|
||||
pid bigint NOT NULL,
|
||||
handle text NOT NULL,
|
||||
uid bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.mention OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 236 (class 1259 OID 77502)
|
||||
-- Name: message; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.message (
|
||||
id bigint NOT NULL,
|
||||
sender bigint NOT NULL,
|
||||
recipient bigint NOT NULL,
|
||||
body bytea NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
read_at bigint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.message OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 235 (class 1259 OID 77501)
|
||||
-- Name: message_id_seq; Type: SEQUENCE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE public.message ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.message_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 238 (class 1259 OID 123452)
|
||||
-- Name: notification; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.notification (
|
||||
id bigint NOT NULL,
|
||||
uid bigint NOT NULL,
|
||||
kind text NOT NULL,
|
||||
actor bigint DEFAULT 0 NOT NULL,
|
||||
excerpt text DEFAULT ''::text NOT NULL,
|
||||
link text NOT NULL,
|
||||
pid bigint DEFAULT 0 NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
seen_at bigint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.notification OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 237 (class 1259 OID 123451)
|
||||
-- Name: notification_id_seq; Type: SEQUENCE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE public.notification ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.notification_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 231 (class 1259 OID 60666)
|
||||
-- Name: password_reset; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.password_reset (
|
||||
id bigint NOT NULL,
|
||||
uid bigint NOT NULL,
|
||||
token_hash text NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
expires bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.password_reset OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 230 (class 1259 OID 60665)
|
||||
-- Name: password_reset_id_seq; Type: SEQUENCE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE public.password_reset ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.password_reset_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 229 (class 1259 OID 53091)
|
||||
-- Name: report; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.report (
|
||||
id bigint NOT NULL,
|
||||
pid bigint NOT NULL,
|
||||
uid bigint DEFAULT 0 NOT NULL,
|
||||
reason text DEFAULT ''::text NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
handled bigint DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.report OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 228 (class 1259 OID 53090)
|
||||
-- Name: report_id_seq; Type: SEQUENCE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE public.report ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.report_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 222 (class 1259 OID 53015)
|
||||
-- Name: session; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.session (
|
||||
id bigint NOT NULL,
|
||||
uid bigint NOT NULL,
|
||||
value text NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
expires bigint NOT NULL,
|
||||
description text DEFAULT ''::text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.session OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 221 (class 1259 OID 53014)
|
||||
-- Name: session_id_seq; Type: SEQUENCE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE public.session ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.session_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 226 (class 1259 OID 53062)
|
||||
-- Name: vote; Type: TABLE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE TABLE public.vote (
|
||||
id bigint NOT NULL,
|
||||
uid bigint NOT NULL,
|
||||
pid bigint NOT NULL,
|
||||
mode text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.vote OWNER TO kver;
|
||||
|
||||
--
|
||||
-- TOC entry 225 (class 1259 OID 53061)
|
||||
-- Name: vote_id_seq; Type: SEQUENCE; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE public.vote ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.vote_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3380 (class 2606 OID 114443)
|
||||
-- Name: account account_handle_key; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.account
|
||||
ADD CONSTRAINT account_handle_key UNIQUE (handle);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3417 (class 2606 OID 77498)
|
||||
-- Name: account_key account_key_fingerprint_key; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.account_key
|
||||
ADD CONSTRAINT account_key_fingerprint_key UNIQUE (fingerprint);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3419 (class 2606 OID 77496)
|
||||
-- Name: account_key account_key_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.account_key
|
||||
ADD CONSTRAINT account_key_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3382 (class 2606 OID 53009)
|
||||
-- Name: account account_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.account
|
||||
ADD CONSTRAINT account_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3384 (class 2606 OID 53011)
|
||||
-- Name: account account_uid_key; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.account
|
||||
ADD CONSTRAINT account_uid_key UNIQUE (uid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3386 (class 2606 OID 53013)
|
||||
-- Name: account account_username_key; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.account
|
||||
ADD CONSTRAINT account_username_key UNIQUE (legacy_name);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3393 (class 2606 OID 53060)
|
||||
-- Name: entry entry_pid_key; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.entry
|
||||
ADD CONSTRAINT entry_pid_key UNIQUE (pid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3395 (class 2606 OID 53058)
|
||||
-- Name: entry entry_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.entry
|
||||
ADD CONSTRAINT entry_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3435 (class 2606 OID 123537)
|
||||
-- Name: entry_tag entry_tag_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.entry_tag
|
||||
ADD CONSTRAINT entry_tag_pkey PRIMARY KEY (pid, tag);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3406 (class 2606 OID 53089)
|
||||
-- Name: impression impression_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.impression
|
||||
ADD CONSTRAINT impression_pkey PRIMARY KEY (day, anon_ip, path);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3415 (class 2606 OID 67176)
|
||||
-- Name: link_preview link_preview_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.link_preview
|
||||
ADD CONSTRAINT link_preview_pkey PRIMARY KEY (url);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3433 (class 2606 OID 123507)
|
||||
-- Name: mention mention_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.mention
|
||||
ADD CONSTRAINT mention_pkey PRIMARY KEY (pid, handle);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3426 (class 2606 OID 77515)
|
||||
-- Name: message message_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.message
|
||||
ADD CONSTRAINT message_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3430 (class 2606 OID 123471)
|
||||
-- Name: notification notification_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.notification
|
||||
ADD CONSTRAINT notification_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3411 (class 2606 OID 60677)
|
||||
-- Name: password_reset password_reset_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.password_reset
|
||||
ADD CONSTRAINT password_reset_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3413 (class 2606 OID 60679)
|
||||
-- Name: password_reset password_reset_token_hash_key; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.password_reset
|
||||
ADD CONSTRAINT password_reset_token_hash_key UNIQUE (token_hash);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3409 (class 2606 OID 53106)
|
||||
-- Name: report report_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.report
|
||||
ADD CONSTRAINT report_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3389 (class 2606 OID 53028)
|
||||
-- Name: session session_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.session
|
||||
ADD CONSTRAINT session_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3391 (class 2606 OID 53030)
|
||||
-- Name: session session_value_key; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.session
|
||||
ADD CONSTRAINT session_value_key UNIQUE (value);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3402 (class 2606 OID 53072)
|
||||
-- Name: vote vote_pkey; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.vote
|
||||
ADD CONSTRAINT vote_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3404 (class 2606 OID 53074)
|
||||
-- Name: vote vote_uid_pid_key; Type: CONSTRAINT; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.vote
|
||||
ADD CONSTRAINT vote_uid_pid_key UNIQUE (uid, pid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3420 (class 1259 OID 77499)
|
||||
-- Name: idx_account_key_current; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX idx_account_key_current ON public.account_key USING btree (uid) WHERE (replaced_at = 0);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3421 (class 1259 OID 77500)
|
||||
-- Name: idx_account_key_uid; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_account_key_uid ON public.account_key USING btree (uid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3396 (class 1259 OID 53107)
|
||||
-- Name: idx_entry_last_activity; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_entry_last_activity ON public.entry USING btree (last_activity);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3397 (class 1259 OID 53108)
|
||||
-- Name: idx_entry_reply_to; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_entry_reply_to ON public.entry USING btree (reply_to);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3398 (class 1259 OID 75703)
|
||||
-- Name: idx_entry_siblings; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_entry_siblings ON public.entry USING btree (reply_to, last_activity, pid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3436 (class 1259 OID 123538)
|
||||
-- Name: idx_entry_tag_tag; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_entry_tag_tag ON public.entry_tag USING btree (tag text_pattern_ops);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3399 (class 1259 OID 53109)
|
||||
-- Name: idx_entry_uid; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_entry_uid ON public.entry USING btree (uid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3431 (class 1259 OID 123508)
|
||||
-- Name: idx_mention_uid; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_mention_uid ON public.mention USING btree (uid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3422 (class 1259 OID 77518)
|
||||
-- Name: idx_message_created; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_message_created ON public.message USING btree (created_at);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3423 (class 1259 OID 77516)
|
||||
-- Name: idx_message_pair; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_message_pair ON public.message USING btree (sender, recipient, id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3424 (class 1259 OID 77517)
|
||||
-- Name: idx_message_recipient; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_message_recipient ON public.message USING btree (recipient, id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3427 (class 1259 OID 123473)
|
||||
-- Name: idx_notification_pid; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_notification_pid ON public.notification USING btree (pid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3428 (class 1259 OID 123472)
|
||||
-- Name: idx_notification_uid; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_notification_uid ON public.notification USING btree (uid, id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3407 (class 1259 OID 53112)
|
||||
-- Name: idx_report_open; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_report_open ON public.report USING btree (handled, created_at);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3387 (class 1259 OID 53111)
|
||||
-- Name: idx_session_uid; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_session_uid ON public.session USING btree (uid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3400 (class 1259 OID 53110)
|
||||
-- Name: idx_vote_pid; Type: INDEX; Schema: public; Owner: kver
|
||||
--
|
||||
|
||||
CREATE INDEX idx_vote_pid ON public.vote USING btree (pid);
|
||||
|
||||
|
||||
-- Completed on 2026-11-22 11:57:31 UTC
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
\unrestrict sfKzavw6BT7S48XgpklDXrRN4BzPBCBJB1apavBd4jjyastMTwALfb7ctd9PV5I
|
||||
|
||||
+5
-3
@@ -36,10 +36,12 @@ Form:
|
||||
**Requests** sind `application/x-www-form-urlencoded` bzw. `multipart/form-data`
|
||||
(Uploads). Zeitstempel sind Unix-Sekunden.
|
||||
|
||||
**Auth** läuft über das Cookie `session` (HttpOnly, SameSite=Lax). Geschützte
|
||||
Endpunkte antworten ohne gültige Session mit `401 auth.required`.
|
||||
**Auth** läuft über das Cookie `session` (HttpOnly, SameSite=Lax). Der Server
|
||||
speichert davon nur den SHA-256 (wie bei Reset-Links). Geschützte Endpunkte
|
||||
antworten ohne gültige Session mit `401 auth.required`.
|
||||
|
||||
**CSRF:** Nicht-GET-Requests mit fremdem `Origin`-Header werden mit
|
||||
**CSRF:** Nicht-GET-Requests mit fremdem `Origin`-Header oder mit
|
||||
`Sec-Fetch-Site` ungleich `same-origin`/`none` werden mit
|
||||
`403 csrf.bad_origin` abgewiesen.
|
||||
|
||||
**Rate-Limits** (pro IP): Login, Registrierung und Passwort-Reset 20/min.
|
||||
|
||||
+8
-4
@@ -216,16 +216,20 @@ podman build -t kver .
|
||||
systemctl --user restart kver
|
||||
```
|
||||
|
||||
Einmalig nach dem Update vom 22.11.2026 (Session-Tokens werden seitdem
|
||||
gehasht gespeichert): Die alten Klartext-Zeilen sind nutzlos und würden erst
|
||||
mit ihrem Ablauf (bis zu ein Jahr) verschwinden -- `DELETE FROM session;`
|
||||
räumt sie weg. Alle Nutzer müssen sich danach ohnehin neu anmelden.
|
||||
|
||||
Die App fährt bei SIGTERM sauber herunter (laufende Requests werden zu Ende
|
||||
bedient, dann wird die DB-Verbindung geschlossen).
|
||||
|
||||
## Handles (Umstellung 11/2026)
|
||||
|
||||
Seit der Trennung von Handle (`@name`, a–z 0–9 `_`, Login und Profil-URL)
|
||||
und Anzeigename (frei, Unicode) migriert der Server beim ersten Start
|
||||
bestehende Konten selbst (`account.MigrateHandles`): der alte Nutzername wird
|
||||
Anzeigename und, umgeschrieben (ä→ae, Pinyin, `.`/`-`→`_`, klein), Handle;
|
||||
Kollisionen bekommen eine Zahl angehängt. Der alte Name bleibt in
|
||||
und Anzeigename (frei, Unicode) ist der alte Nutzername Anzeigename und,
|
||||
umgeschrieben (ä→ae, Pinyin, `.`/`-`→`_`, klein, Kollisionen mit Zahl),
|
||||
Handle. Die Umschrift ist gelaufen, ihr Code ist weg; der alte Name bleibt in
|
||||
`account.legacy_name`. Wer sich jetzt mit einem anderen Namen anmelden muss
|
||||
(mehr als nur die Groß-/Kleinschreibung), listet:
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ cd frontend && npm run dev # http://localhost:5173
|
||||
Vite reicht `/api` und `/static` ans Backend durch (`frontend/vite.config.ts`,
|
||||
`changeOrigin: false` ist Pflicht, sonst scheitert jeder POST am Origin-Check).
|
||||
|
||||
Tests: `go test ./...` braucht `KVER_TEST_DSN` (steht in `dev.env`, zeigt
|
||||
auf dieselbe Datenbank wie `KVER_DSN`; jeder Test legt sich ein eigenes
|
||||
Schema an und löscht es wieder). Ohne die Variable werden alle DB-Tests
|
||||
übersprungen und `go test` ist trotzdem grün.
|
||||
|
||||
## Bauen
|
||||
|
||||
`npm run build` in `frontend/` prüft die Typen und schreibt nach `../web/`
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# DEV starten
|
||||
|
||||
## Terminal 1: Backend
|
||||
set -a; . ./dev.env; set +a
|
||||
KVER_ADDR=127.0.0.1:8081 go run ./cmd/kver
|
||||
|
||||
## Terminal 2: Frontend
|
||||
cd frontend && npm run dev # → http://localhost:5173
|
||||
Reference in New Issue
Block a user