Skip to content

Commit

Permalink
Properly recover image if litterbox was dead before
Browse files Browse the repository at this point in the history
  • Loading branch information
Arno500 committed Jun 10, 2024
1 parent 9a7e125 commit d7b437a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions discord/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var client = &http.Client{
Timeout: 5 * time.Second,
}

const EMPTY_THUMB_STRING = "plex"

// InitDiscordClient prepares Discord's RPC API to allow Rich Presence
func InitDiscordClient() {
if (discord == nil || !discord.Logged) {
Expand All @@ -44,7 +46,7 @@ func LogoutDiscordClient() {

func getThumbnailLink(thumbKey string, plexInstance *plex.Plex) string {
if currentPlayState.Thumb.PlexThumbUrl == thumbKey {
if currentPlayState.Thumb.ImgLink != "" {
if currentPlayState.Thumb.ImgLink != EMPTY_THUMB_STRING {
return currentPlayState.Thumb.ImgLink
}
}
Expand All @@ -54,22 +56,22 @@ func getThumbnailLink(thumbKey string, plexInstance *plex.Plex) string {
thumbResp, err := client.Get(plexThumbLink)
if err != nil {
log.Printf("Couldn't get thumbnail from Plex (%s)", err)
currentPlayState.Thumb.ImgLink = "plex"
return "plex"
currentPlayState.Thumb.ImgLink = EMPTY_THUMB_STRING
return EMPTY_THUMB_STRING
}
defer thumbResp.Body.Close()
b, err := io.ReadAll(thumbResp.Body)
if err != nil {
log.Printf("Couldn't read thumbnail from Plex (%s)", err)
currentPlayState.Thumb.ImgLink = "plex"
return "plex"
currentPlayState.Thumb.ImgLink = EMPTY_THUMB_STRING
return EMPTY_THUMB_STRING
}

imgUrl, err := UploadImage(b, thumbKey)
if err != nil {
log.Println("Error uploading image to litterbox: ", err)
currentPlayState.Thumb.ImgLink = "plex"
return "plex"
currentPlayState.Thumb.ImgLink = EMPTY_THUMB_STRING
return EMPTY_THUMB_STRING
}
currentPlayState.Thumb.ImgLink = imgUrl
return imgUrl
Expand Down

0 comments on commit d7b437a

Please sign in to comment.