Add ability to display notifications other than HTTP errors
This commit is contained in:
@ -88,6 +88,6 @@ func UploadDocx(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
notifyClient(w, "Hochladen erfolgreich!", http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
20
cmd/frontend/notifications.go
Normal file
20
cmd/frontend/notifications.go
Normal file
@ -0,0 +1,20 @@
|
||||
package frontend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func notifyClient(w http.ResponseWriter, message string, status int) {
|
||||
h := w.Header()
|
||||
h.Del("Content-Length")
|
||||
h.Set("Content-Type", "text/html; charset=utf-8")
|
||||
if status >= 400 {
|
||||
h.Set("X-Content-Type-Options", "nosniff")
|
||||
}
|
||||
w.WriteHeader(status)
|
||||
|
||||
safeMsg := template.HTMLEscapeString(message)
|
||||
fmt.Fprintf(w, `<span id="notification-content" hx-swap-oob="true">%s</span>`, safeMsg)
|
||||
}
|
@ -54,6 +54,6 @@ func UploadPDF(c *b.Config, s map[string]*Session) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
notifyClient(w, "Hochladen erfolgreich!", http.StatusOK)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user