This commit is contained in:
parent
13dc7b8945
commit
aafdcf96ab
28
main.go
28
main.go
@ -15,10 +15,22 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// Logic Jellyfin URL
|
||||
type Logic struct {
|
||||
BaseURL string
|
||||
}
|
||||
|
||||
// PublicInfo Chromecast configuration Payload
|
||||
type PublicInfo struct {
|
||||
ID string
|
||||
LocalAddress string
|
||||
OperatingSystem string
|
||||
ProductName string
|
||||
ServerName string
|
||||
StartupWizardCompleted bool
|
||||
Version string
|
||||
}
|
||||
|
||||
func (l Logic) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
logger := logginghandler.Logger(r)
|
||||
|
||||
@ -50,24 +62,15 @@ func (l Logic) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jd := map[string]string{}
|
||||
var jd PublicInfo
|
||||
if err := json.Unmarshal(body, &jd); err != nil {
|
||||
logger.Error().Msg(err.Error())
|
||||
http.Error(w, "could not unmarshal body", http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Delete LocalAddress from map.
|
||||
_, ok := jd["LocalAddress"]
|
||||
if ok {
|
||||
delete(jd, "LocalAddress")
|
||||
} else {
|
||||
logger.Debug().Msg("nothing to do")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
url := os.Getenv("JELLYFIN_URL")
|
||||
jd.LocalAddress = url
|
||||
nd, err := json.Marshal(jd)
|
||||
if err != nil {
|
||||
logger.Error().Msg(err.Error())
|
||||
@ -91,6 +94,7 @@ func main() {
|
||||
|
||||
l := Logic{BaseURL: os.Args[1]}
|
||||
handler := logginghandler.Handler(l)
|
||||
|
||||
http.Handle("/", handler)
|
||||
log.Info().Msg("starting server...")
|
||||
log.Fatal().Msg(http.ListenAndServe("0.0.0.0:8088", nil).Error())
|
||||
|
2
vendor/github.com/rs/zerolog/go.mod
generated
vendored
2
vendor/github.com/rs/zerolog/go.mod
generated
vendored
@ -1,5 +1,7 @@
|
||||
module github.com/rs/zerolog
|
||||
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
|
||||
github.com/pkg/errors v0.8.1
|
||||
|
Loading…
Reference in New Issue
Block a user