userByName reloads cache if user not found, more things in test

pull/20/head
Harvey Tindall 4 years ago
parent 802f957d22
commit 7d84fdec96
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

1
.gitignore vendored

@ -14,3 +14,4 @@ build/
pkg/
old/
version.go
notes

@ -240,16 +240,25 @@ func (jf *Jellyfin) getUsers(public bool) ([]map[string]interface{}, int, error)
}
func (jf *Jellyfin) userByName(username string, public bool) (map[string]interface{}, int, error) {
users, status, err := jf.getUsers(public)
if err != nil || status != 200 {
var match map[string]interface{}
find := func() (map[string]interface{}, int, error) {
users, status, err := jf.getUsers(public)
if err != nil || status != 200 {
return nil, status, err
}
for _, user := range users {
if user["Name"].(string) == username {
return user, status, err
}
}
return nil, status, err
}
for _, user := range users {
if user["Name"].(string) == username {
return user, status, nil
}
match, status, err := find()
if match == nil {
jf.cacheExpiry = time.Now()
match, status, err = find()
}
return nil, status, err
return match, status, err
}
func (jf *Jellyfin) userById(userId string, public bool) (map[string]interface{}, int, error) {

@ -132,6 +132,13 @@ func test(app *appContext) {
out, err := json.MarshalIndent(users, "", " ")
fmt.Print(string(out), err)
}
fmt.Printf("Enter a user to grab: ")
var username string
fmt.Scanln(&username)
user, status, err := app.jf.userByName(username, false)
fmt.Printf("userByName (%s): code %d err %s", username, status, err)
out, err := json.MarshalIndent(user, "", " ")
fmt.Print(string(out))
}
func start(asDaemon, firstCall bool) {

@ -67,6 +67,12 @@ func pwrMonitor(app *appContext, watcher *fsnotify.Watcher) {
}
app.storage.loadEmails()
var address string
uid := user["Id"]
if uid == nil {
app.err.Printf("Couldn't get user ID for user \"%s\"", pwr.Username)
app.debug.Printf("user maplength: %d", len(user))
return
}
addr, ok := app.storage.emails[user["Id"].(string)]
if !ok || addr == nil {
app.err.Printf("Couldn't find email for user \"%s\". Make sure it's set", pwr.Username)

Loading…
Cancel
Save