Staff push notifications, and revalidate embedded assets
Notifications: staff turn them on per device from a new Notifications page, pick each type (bans, gags, mutes and silences added or lifted, server down and back up) and quiet hours. A watcher polls SimpleAdmin's tables, so in-game penalties are sent too. Web Push with VAPID and RFC 8291 encryption in internal/push, standard library only. Tables in sql/push.sql, created at startup; the VAPID key is made on first start and kept in saw_settings. Penalty notifications link to the public list searching for the player (#bans?q=<steamid64>). The Android app delegates notifications (versionCode 3). Caching: pages, scripts and styles are served with Cache-Control: no-cache and an ETag, so a deploy shows up at once instead of after Cloudflare's default 4-hour browser cache.
This commit is contained in:
parent
7900bf5b3e
commit
17232bd5a2
23 changed files with 2135 additions and 12 deletions
|
|
@ -14,6 +14,7 @@ import (
|
|||
"time"
|
||||
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/live"
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/push"
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/rcon"
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/saconfig"
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/store"
|
||||
|
|
@ -35,6 +36,8 @@ type Config struct {
|
|||
// the SHA-256 fingerprints of the keys it's signed with. Empty serves no assetlinks.json.
|
||||
AndroidPackage string
|
||||
AndroidCerts []string
|
||||
// Push sends staff notifications; nil turns them off.
|
||||
Push *push.Sender
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
|
|
@ -81,10 +84,13 @@ func (s *Server) Handler() http.Handler {
|
|||
files := http.FileServerFS(static)
|
||||
|
||||
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFileFS(w, r, static, "public.html")
|
||||
serveAsset(w, r, static, "public.html")
|
||||
})
|
||||
mux.HandleFunc("GET /admin", s.adminPage(static))
|
||||
mux.Handle("GET /static/", http.StripPrefix("/static/", files))
|
||||
mux.Handle("GET /static/", http.StripPrefix("/static/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
revalidate(w, r.URL.Path)
|
||||
files.ServeHTTP(w, r)
|
||||
})))
|
||||
mux.HandleFunc("GET /manifest.webmanifest", s.manifest(false))
|
||||
mux.HandleFunc("GET /admin.webmanifest", s.manifest(true))
|
||||
mux.HandleFunc("GET /sw.js", serviceWorker(static))
|
||||
|
|
@ -133,6 +139,12 @@ func (s *Server) Handler() http.Handler {
|
|||
admin("DELETE /api/admin/verify/overrides/{steamid}", s.removeOverride)
|
||||
admin("POST /api/admin/verify/settings", s.saveVerifySettings)
|
||||
|
||||
admin("GET /api/admin/notifications", s.adminNotifications)
|
||||
admin("PUT /api/admin/notifications/prefs", s.saveNotificationPrefs)
|
||||
admin("POST /api/admin/notifications/subscribe", s.subscribeNotifications)
|
||||
admin("POST /api/admin/notifications/unsubscribe", s.unsubscribeNotifications)
|
||||
admin("POST /api/admin/notifications/test", s.testNotification)
|
||||
|
||||
return s.headers(mux)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue