1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-23 01:20:11 +00:00

daemon: ensure correct error before wiping user data

ensure the error is specifically "User not found", rather than a
connection error or such. For #303.
This commit is contained in:
Harvey Tindall 2023-10-19 15:04:31 +01:00
parent 3d0f756264
commit c39a9e80e7
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2

View File

@ -1,6 +1,10 @@
package main package main
import "time" import (
"time"
"github.com/hrfee/mediabrowser"
)
// clearEmails removes stored emails for users which no longer exist. // clearEmails removes stored emails for users which no longer exist.
// meant to be called with other such housekeeping functions, so assumes // meant to be called with other such housekeeping functions, so assumes
@ -9,11 +13,14 @@ func (app *appContext) clearEmails() {
app.debug.Println("Housekeeping: removing unused email addresses") app.debug.Println("Housekeeping: removing unused email addresses")
emails := app.storage.GetEmails() emails := app.storage.GetEmails()
for _, email := range emails { for _, email := range emails {
_, status, err := app.jf.UserByID(email.JellyfinID, false) _, _, err := app.jf.UserByID(email.JellyfinID, false)
if status == 200 && err == nil { // Make sure the user doesn't exist, and no other error has occured
switch err.(type) {
case mediabrowser.ErrUserNotFound:
app.storage.DeleteEmailsKey(email.JellyfinID)
default:
continue continue
} }
app.storage.DeleteEmailsKey(email.JellyfinID)
} }
} }
@ -22,11 +29,14 @@ func (app *appContext) clearDiscord() {
app.debug.Println("Housekeeping: removing unused Discord IDs") app.debug.Println("Housekeeping: removing unused Discord IDs")
discordUsers := app.storage.GetDiscord() discordUsers := app.storage.GetDiscord()
for _, discordUser := range discordUsers { for _, discordUser := range discordUsers {
_, status, err := app.jf.UserByID(discordUser.JellyfinID, false) _, _, err := app.jf.UserByID(discordUser.JellyfinID, false)
if status == 200 && err == nil { // Make sure the user doesn't exist, and no other error has occured
switch err.(type) {
case mediabrowser.ErrUserNotFound:
app.storage.DeleteDiscordKey(discordUser.JellyfinID)
default:
continue continue
} }
app.storage.DeleteDiscordKey(discordUser.JellyfinID)
} }
} }
@ -35,11 +45,14 @@ func (app *appContext) clearMatrix() {
app.debug.Println("Housekeeping: removing unused Matrix IDs") app.debug.Println("Housekeeping: removing unused Matrix IDs")
matrixUsers := app.storage.GetMatrix() matrixUsers := app.storage.GetMatrix()
for _, matrixUser := range matrixUsers { for _, matrixUser := range matrixUsers {
_, status, err := app.jf.UserByID(matrixUser.JellyfinID, false) _, _, err := app.jf.UserByID(matrixUser.JellyfinID, false)
if status == 200 && err == nil { // Make sure the user doesn't exist, and no other error has occured
switch err.(type) {
case mediabrowser.ErrUserNotFound:
app.storage.DeleteMatrixKey(matrixUser.JellyfinID)
default:
continue continue
} }
app.storage.DeleteMatrixKey(matrixUser.JellyfinID)
} }
} }
@ -48,11 +61,14 @@ func (app *appContext) clearTelegram() {
app.debug.Println("Housekeeping: removing unused Telegram IDs") app.debug.Println("Housekeeping: removing unused Telegram IDs")
telegramUsers := app.storage.GetTelegram() telegramUsers := app.storage.GetTelegram()
for _, telegramUser := range telegramUsers { for _, telegramUser := range telegramUsers {
_, status, err := app.jf.UserByID(telegramUser.JellyfinID, false) _, _, err := app.jf.UserByID(telegramUser.JellyfinID, false)
if status == 200 && err == nil { // Make sure the user doesn't exist, and no other error has occured
switch err.(type) {
case mediabrowser.ErrUserNotFound:
app.storage.DeleteTelegramKey(telegramUser.JellyfinID)
default:
continue continue
} }
app.storage.DeleteTelegramKey(telegramUser.JellyfinID)
} }
} }