Compare commits

...

4 Commits

Author SHA1 Message Date
2a708c8d1a cosmetic changes
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-06 10:19:39 +02:00
88d550f947 removes LocalAddress if its not defined from response
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-05-06 10:16:12 +02:00
af068f70e8 more debugging
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2021-04-09 14:02:13 +02:00
b83f2df025 fixes docker-compose example
All checks were successful
continuous-integration/drone/push Build is passing
2020-12-09 09:35:29 +01:00
2 changed files with 29 additions and 17 deletions

View File

@ -4,7 +4,7 @@ a little container to fix [this bug](https://github.com/jellyfin/jellyfin/issues
## Usage
it can take a config file as first argument.
it can take a config file as first argument. if `external_url` is not defined, the JSON response wont include it at all!
## config example
@ -41,8 +41,8 @@ it can take a config file as first argument.
networks:
- nginx_backend
environment:
JELLYFIXER_INTERNAL_URL: http://jellycontainer:8096
JELLYFIXER_EXTERNAL_URL: https://jellyfin.foo.tld
- JELLYFIXER_INTERNAL_URL=http://jellycontainer:8096
- JELLYFIXER_EXTERNAL_URL=https://jellyfin.foo.tld
labels:
- "traefik.enable=true"
- "traefik.http.routers.jellyfixer-secured.rule=Host(`jellyfin.foo.tld`) && Path(`/System/Info/Public`)"

40
main.go
View File

@ -24,15 +24,16 @@ type Logic struct {
// PublicInfo Chromecast configuration Payload.
type PublicInfo struct {
ID string
LocalAddress string
OperatingSystem string
ProductName string
ServerName string
StartupWizardCompleted bool
Version string
LocalAddress string `json:"LocalAddress,omitempty"`
ServerName string `json:"ServerName"`
Version string `json:"Version"`
ProductName string `json:"ProductName"`
OperatingSystem string `json:"OperatingSystem"`
ID string `json:"Id"`
StartupWizardCompleted bool `json:"StartupWizardCompleted"`
}
// nolint:funlen
func (l Logic) ServeHTTP(w http.ResponseWriter, r *http.Request) {
logger := logginghandler.Logger(r)
@ -64,7 +65,10 @@ func (l Logic) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
logger.Debug().Str("body", string(body)).Msg("read body")
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)
@ -72,9 +76,21 @@ func (l Logic) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
jd.LocalAddress = l.ExternalURL
var nd PublicInfo
nd, err := json.Marshal(jd)
nd.ServerName = jd.ServerName
nd.Version = jd.Version
nd.ProductName = jd.ProductName
nd.OperatingSystem = jd.OperatingSystem
nd.ID = jd.ID
nd.StartupWizardCompleted = jd.StartupWizardCompleted
// When there is no external url defined, it wont include it in the response.
if l.ExternalURL != "" {
nd.LocalAddress = l.ExternalURL
}
bd, err := json.Marshal(nd)
if err != nil {
logger.Error().Msg(err.Error())
http.Error(w, "could not marshal body", http.StatusInternalServerError)
@ -82,7 +98,7 @@ func (l Logic) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
if _, err := w.Write(nd); err != nil {
if _, err := w.Write(bd); err != nil {
logger.Error().Msg(err.Error())
}
}
@ -111,10 +127,6 @@ func main() {
log.Fatal().Msg("needs key 'internal_url'")
}
if viper.GetString("external_url") == "" {
log.Fatal().Msg("needs key 'external_url'")
}
l := Logic{
InternalURL: viper.GetString("internal_url"),
ExternalURL: viper.GetString("external_url"),