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

add extra logging

This commit is contained in:
Harvey Tindall 2021-04-06 18:02:15 +01:00
parent 78049d4a33
commit e6e5231f63
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
3 changed files with 16 additions and 13 deletions

8
api.go
View File

@ -1032,6 +1032,9 @@ func (app *appContext) GetUsers(gc *gin.Context) {
return
}
i := 0
app.storage.usersLock.Lock()
defer app.storage.usersLock.Unlock()
fmt.Printf("GETUSERS user.json:\n%+v\n", app.storage.users)
for _, jfUser := range users {
user := respUser{
ID: jfUser.ID,
@ -1046,8 +1049,11 @@ func (app *appContext) GetUsers(gc *gin.Context) {
if email, ok := app.storage.emails[jfUser.ID]; ok {
user.Email = email.(string)
}
if expiry, ok := app.storage.users[jfUser.ID]; ok {
expiry, ok := app.storage.users[jfUser.ID]
fmt.Printf("CHECKING User: %s, ID: %s, Match: %t\n", user.Name, user.ID, ok)
if ok {
user.Expiry = app.formatDatetime(expiry)
fmt.Printf("EXPIRY FOR User %s, ID: %s, Expiry: %+v, Formatted: %s\n", user.Name, user.ID, expiry, user.Expiry)
}
resp.UserList[i] = user

View File

@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"fmt"
"io/fs"
"log"
"os"
@ -480,11 +481,11 @@ func (st *Storage) storeInvites() error {
}
func (st *Storage) loadUsers() error {
st.usersLock.Lock()
defer st.usersLock.Unlock()
if st.users == nil {
st.users = map[string]time.Time{}
}
st.usersLock.Lock()
defer st.usersLock.Unlock()
temp := map[string]time.Time{}
err := loadJSON(st.users_path, &temp)
if err != nil {
@ -495,6 +496,7 @@ func (st *Storage) loadUsers() error {
st.users[id] = t1
}
}
fmt.Printf("CURRENT USERS:\n%+v\n", st.users)
return nil
}

View File

@ -35,7 +35,6 @@ func (rt *userDaemon) run() {
break
}
started := time.Now()
rt.app.storage.loadInvites()
rt.app.checkUsers()
finished := time.Now()
duration := finished.Sub(started)
@ -76,12 +75,8 @@ func (app *appContext) checkUsers() {
}
for id, expiry := range app.storage.users {
if _, ok := userExists[id]; !ok {
app.debug.Printf("Deleting expiry for non-existent user \"%s\"", id)
app.info.Printf("Deleting expiry for non-existent user \"%s\"", id)
delete(app.storage.users, id)
err = app.storage.storeUsers()
if err != nil {
app.err.Printf("Failed to store user duration: %s", err)
}
} else if time.Now().After(expiry) {
found := false
var user mediabrowser.User
@ -111,10 +106,6 @@ func (app *appContext) checkUsers() {
continue
}
delete(app.storage.users, id)
err = app.storage.storeUsers()
if err != nil {
app.err.Printf("Failed to store user duration: %s", err)
}
if email {
address, ok := app.storage.emails[id]
if !ok {
@ -131,4 +122,8 @@ func (app *appContext) checkUsers() {
}
}
}
err = app.storage.storeUsers()
if err != nil {
app.err.Printf("Failed to store user expiries: %s", err)
}
}