Skip to content

Commit e91e4e8

Browse files
authored
Merge pull request #193 from zorchenhimer/ZorchCanBlameMeForThisNameIDK_WHAT_TO_CALL_IT
Handful of updates
2 parents 80576b3 + de25205 commit e91e4e8

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

.github/workflows/main.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- name: test
2626
run: go test ./...
2727

28+
- name: test ui
29+
run: go test ./... -tags=test_ui
30+
2831
build:
2932
runs-on: ubuntu-latest
3033

handlers.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,14 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
127127
return
128128
}
129129

130+
if data.Type == common.CdPing {
131+
continue
132+
}
133+
130134
var joinData common.JoinData
131135
err = json.Unmarshal([]byte(data.Message), &joinData)
132136
if err != nil {
133-
common.LogInfof("[handler] Could not unmarshal join data %#v: %v\n", data.Message, err)
137+
common.LogInfof("[handler] Could not unmarshal websocket %d data %#v: %v\n", data.Type, data.Message, err)
134138
continue
135139
}
136140

@@ -315,14 +319,6 @@ func handleEmoteTemplate(w http.ResponseWriter, r *http.Request) {
315319
}
316320

317321
func handleIndexTemplate(w http.ResponseWriter, r *http.Request) {
318-
if settings.RoomAccess != AccessOpen {
319-
if !checkRoomAccess(w, r) {
320-
common.LogDebugln("Denied access")
321-
return
322-
}
323-
common.LogDebugln("Granted access")
324-
}
325-
326322
type Data struct {
327323
Video, Chat bool
328324
MessageHistoryCount int
@@ -473,3 +469,16 @@ func handleDefault(w http.ResponseWriter, r *http.Request) {
473469
handleIndexTemplate(w, r)
474470
}
475471
}
472+
473+
func wrapAuth(next http.HandlerFunc) http.HandlerFunc {
474+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
475+
if settings.RoomAccess != AccessOpen {
476+
if !checkRoomAccess(w, r) {
477+
common.LogDebugln("Denied access")
478+
return
479+
}
480+
common.LogDebugln("Granted access")
481+
}
482+
next.ServeHTTP(w, r)
483+
})
484+
}

main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,17 @@ func run(args args) {
142142

143143
router := http.NewServeMux()
144144

145-
router.HandleFunc("/ws", wsHandler) // Chat websocket
146145
router.Handle("/static/", http.FileServer(http.FS(staticFsys)))
147146
router.HandleFunc("/emotes/", wsEmotes)
148-
router.HandleFunc("/chat", handleIndexTemplate)
149-
router.HandleFunc("/video", handleIndexTemplate)
150-
router.HandleFunc("/help", handleHelpTemplate)
151-
router.HandleFunc("/emotes", handleEmoteTemplate)
152147

153-
router.HandleFunc("/live", handleLive)
154-
router.HandleFunc("/", handleDefault)
148+
router.HandleFunc("/ws", wrapAuth(wsHandler)) // Chat websocket
149+
router.HandleFunc("/chat", wrapAuth(handleIndexTemplate))
150+
router.HandleFunc("/video", wrapAuth(handleIndexTemplate))
151+
router.HandleFunc("/help", wrapAuth(handleHelpTemplate))
152+
router.HandleFunc("/emotes", wrapAuth(handleEmoteTemplate))
153+
154+
router.HandleFunc("/live", wrapAuth(handleLive))
155+
router.HandleFunc("/", wrapAuth(handleDefault))
155156

156157
httpServer := &http.Server{
157158
Addr: args.Addr,

main_test.go renamed to ui_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build test_ui
2+
13
package main
24

35
import (

0 commit comments

Comments
 (0)