added pw pusher

This commit is contained in:
nahakubuilde
2025-07-17 21:52:52 +01:00
parent 4e4e4f735e
commit 5c5b9b9149
8 changed files with 2851 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
package pwpusher
import (
"net/http"
"strings"
)
// RegisterRoutes registers all PWPusher routes with the given ServeMux
func (p *PWPusher) RegisterRoutes(mux *http.ServeMux) {
// Main PWPusher page
mux.HandleFunc("/pwpush", p.IndexHandler)
// API endpoint for checking link status
mux.HandleFunc("/pwpush/api/status/", p.StatusHandler)
// PWPusher sub-routes (push viewing)
mux.HandleFunc("/pwpush/", func(w http.ResponseWriter, r *http.Request) {
// Extract push ID from URL path like /pwpush/abc123
id := strings.TrimPrefix(r.URL.Path, "/pwpush/")
if id != "" {
// Redirect to view handler with proper ID
r.URL.Path = "/pwview/" + id
p.ViewHandler(w, r)
} else {
http.NotFound(w, r)
}
})
// Direct view handler for clean URLs
mux.HandleFunc("/pwview/", p.ViewHandler)
}
// RegisterRoutesWithDefault registers all PWPusher routes with the default ServeMux
func (p *PWPusher) RegisterRoutesWithDefault() {
p.RegisterRoutes(http.DefaultServeMux)
}