1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 09:00:10 +00:00

add cache_timeout option

controls how old the Jellyfin user cache can be before refetching. defaults to 30 minutes.
This commit is contained in:
Harvey Tindall 2020-11-02 23:26:46 +00:00
parent d4a92adc65
commit 8e45ecb214
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
5 changed files with 15 additions and 5 deletions

2
api.go
View File

@ -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 := ""

View File

@ -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": {

View File

@ -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
}

View File

@ -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()

View File

@ -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)