diff --git a/api.go b/api.go index 7d00f2e..c619d4a 100644 --- a/api.go +++ b/api.go @@ -209,7 +209,7 @@ func (app *appContext) getOmbiUser(jfID string) (map[string]interface{}, int, er username := jfUser["Name"].(string) email := "" if e, ok := app.storage.emails[jfID]; ok { - email := e.(string) + email = e.(string) } for _, ombiUser := range ombiUsers { ombiAddr := "" diff --git a/config/config-base.json b/config/config-base.json index c2341fd..4ee8d44 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -42,6 +42,14 @@ "type": "text", "value": "jfa-go", "description": "The name of the client that will show up in the Jellyfin dashboard." + }, + "cache_timeout": { + "name": "User cache timeout (minutes)", + "required": false, + "requires_restart": true, + "type": "number", + "value": 30, + "description": "Timeout of user cache in minutes. Set to 0 to disable." } }, "ui": { diff --git a/jfapi/jfapi.go b/jfapi/jfapi.go index 5e160a0..27c5586 100644 --- a/jfapi/jfapi.go +++ b/jfapi/jfapi.go @@ -48,7 +48,7 @@ type Jellyfin struct { } // NewJellyfin returns a new Jellyfin object. -func NewJellyfin(server, client, version, device, deviceID string, timeoutHandler common.TimeoutHandler) (*Jellyfin, error) { +func NewJellyfin(server, client, version, device, deviceID string, timeoutHandler common.TimeoutHandler, cacheTimeout int) (*Jellyfin, error) { jf := &Jellyfin{} jf.Server = server jf.client = client @@ -78,7 +78,7 @@ func NewJellyfin(server, client, version, device, deviceID string, timeoutHandle data, _ := ioutil.ReadAll(resp.Body) json.Unmarshal(data, &jf.ServerInfo) } - jf.cacheLength = 30 + jf.cacheLength = cacheTimeout jf.CacheExpiry = time.Now() return jf, nil } diff --git a/main.go b/main.go index 508a6cb..91758d1 100644 --- a/main.go +++ b/main.go @@ -435,6 +435,7 @@ func start(asDaemon, firstCall bool) { } server := app.config.Section("jellyfin").Key("server").String() + cacheTimeout := int(app.config.Section("jellyfin").Key("cache_timeout").MustUint(30)) app.jf, _ = jfapi.NewJellyfin( server, app.config.Section("jellyfin").Key("client").String(), @@ -442,6 +443,7 @@ func start(asDaemon, firstCall bool) { app.config.Section("jellyfin").Key("device").String(), app.config.Section("jellyfin").Key("device_id").String(), common.NewTimeoutHandler("Jellyfin", server, true), + cacheTimeout, ) var status int _, status, err = app.jf.Authenticate(app.config.Section("jellyfin").Key("username").String(), app.config.Section("jellyfin").Key("password").String()) @@ -449,7 +451,7 @@ func start(asDaemon, firstCall bool) { app.err.Fatalf("Failed to authenticate with Jellyfin @ %s: Code %d", server, status) } app.info.Printf("Authenticated with %s", server) - app.authJf, _ = jfapi.NewJellyfin(server, "jfa-go", app.version, "auth", "auth", common.NewTimeoutHandler("Jellyfin", server, true)) + app.authJf, _ = jfapi.NewJellyfin(server, "jfa-go", app.version, "auth", "auth", common.NewTimeoutHandler("Jellyfin", server, true), cacheTimeout) app.loadStrftime() diff --git a/setup.go b/setup.go index 2822882..b6f4502 100644 --- a/setup.go +++ b/setup.go @@ -15,7 +15,7 @@ type testReq struct { func (app *appContext) TestJF(gc *gin.Context) { var req testReq gc.BindJSON(&req) - tempjf, _ := jfapi.NewJellyfin(req.Host, "jfa-go-setup", app.version, "auth", "auth", common.NewTimeoutHandler("authJF", req.Host, true)) + tempjf, _ := jfapi.NewJellyfin(req.Host, "jfa-go-setup", app.version, "auth", "auth", common.NewTimeoutHandler("authJF", req.Host, true), 30) _, status, err := tempjf.Authenticate(req.Username, req.Password) if !(status == 200 || status == 204) || err != nil { app.info.Printf("Auth failed with code %d (%s)", status, err)