mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-10 00:00:53 +00:00
can't believe i didn't already have this smdh
This commit is contained in:
parent
8ba87e1a27
commit
a6508d32ab
2 changed files with 27 additions and 2 deletions
|
@ -297,7 +297,7 @@ func GetCommandsOfType(match PushCommandCacheInfo) []Command {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func HBackendDumpCache(w http.ResponseWriter, r *http.Request) {
|
func HBackendDumpBacklog(w http.ResponseWriter, r *http.Request) {
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
formData, err := UnsealRequest(r.Form)
|
formData, err := UnsealRequest(r.Form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"html/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MAX_PACKET_SIZE = 1024
|
const MAX_PACKET_SIZE = 1024
|
||||||
|
@ -125,11 +126,35 @@ func SetupServerAndHandle(config *Config, tlsConfig *tls.Config, serveMux *http.
|
||||||
if serveMux == nil {
|
if serveMux == nil {
|
||||||
serveMux = http.DefaultServeMux
|
serveMux = http.DefaultServeMux
|
||||||
}
|
}
|
||||||
serveMux.HandleFunc("/", sockServer.ServeHTTP)
|
serveMux.HandleFunc("/", ServeWebsocketOrCatbag(sockServer.ServeHTTP))
|
||||||
serveMux.HandleFunc("/pub_msg", HBackendPublishRequest)
|
serveMux.HandleFunc("/pub_msg", HBackendPublishRequest)
|
||||||
|
serveMux.HandleFunc("/dump_backlog", HBackendDumpBacklog)
|
||||||
serveMux.HandleFunc("/update_and_pub", HBackendUpdateAndPublish)
|
serveMux.HandleFunc("/update_and_pub", HBackendUpdateAndPublish)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Catbag = template.Must(template.New(`
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>CatBag</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`).Parse("html"))
|
||||||
|
|
||||||
|
func ServeWebsocketOrCatbag(sockfunc func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Header.Get("Connection") == "Upgrade" {
|
||||||
|
sockfunc(w, r)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Catbag.Execute(w, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle a new websocket connection from a FFZ client.
|
// Handle a new websocket connection from a FFZ client.
|
||||||
// This runs in a goroutine started by net/http.
|
// This runs in a goroutine started by net/http.
|
||||||
func HandleSocketConnection(conn *websocket.Conn) {
|
func HandleSocketConnection(conn *websocket.Conn) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue