diff --git a/player/Makefile b/player/Makefile new file mode 100644 index 0000000..41510fb --- /dev/null +++ b/player/Makefile @@ -0,0 +1,3 @@ +server: main.go + go build -tags netgo -ldflags '-w -extldflags "-static"' -o server main.go + upx server diff --git a/player/README.md b/player/README.md index 7d710a8..cdb4e14 100644 --- a/player/README.md +++ b/player/README.md @@ -3,5 +3,5 @@ A basic web player with automatic mirror selection and view counting. ``` -go build -tags netgo -ldflags '-w -extldflags "-static"' -o server main.go +make ``` diff --git a/player/main.go b/player/main.go index 4494308..6dccdd1 100644 --- a/player/main.go +++ b/player/main.go @@ -21,6 +21,11 @@ func main() { // Get the remote address var ip = r.RemoteAddr + // If behind a proxy, get the real IP + if fwd := r.Header.Get("X-Forwarded-For"); fwd != "" { + ip = fwd + } + // Update the last active time viewers[ip] = now diff --git a/player/static/player.js b/player/static/player.js index 19b0497..7ddf9d6 100644 --- a/player/static/player.js +++ b/player/static/player.js @@ -94,7 +94,8 @@ timeout: 1000, mode: 'cors', }); - viewCount.innerText = await response.text(); + const count = Number(await response.text()); + viewCount.innerText = count; await sleep(5000); } };