fixed bug where anilist would display a different users stats if show was not in watchlist

This commit is contained in:
2024-09-16 12:45:57 -04:00
parent 9f8014ff00
commit a24a187c7f
6 changed files with 39 additions and 9 deletions

View File

@ -32,7 +32,7 @@ func AniListQuery(body interface{}, login bool) (json.RawMessage, string) {
returnedBody, err := io.ReadAll(res.Body)
return returnedBody, ""
return returnedBody, res.Status
}
func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime {
@ -138,14 +138,44 @@ func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime {
Variables: neededVariables,
}
returnedBody, _ := AniListQuery(body, login)
returnedBody, status := AniListQuery(body, login)
var post AniListGetSingleAnime
if status == "404 Not Found" && login == false {
return post
}
if status == "404 Not Found" && login {
post = a.GetAniListItem(aniId, false)
}
err := json.Unmarshal(returnedBody, &post)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
if login == false {
post.Data.MediaList.UserID = user.Data.Viewer.ID
post.Data.MediaList.Status = ""
post.Data.MediaList.StartedAt.Year = 0
post.Data.MediaList.StartedAt.Month = 0
post.Data.MediaList.StartedAt.Day = 0
post.Data.MediaList.CompletedAt.Year = 0
post.Data.MediaList.CompletedAt.Month = 0
post.Data.MediaList.CompletedAt.Day = 0
post.Data.MediaList.Notes = ""
post.Data.MediaList.Progress = 0
post.Data.MediaList.Score = 0
post.Data.MediaList.Repeat = 0
post.Data.MediaList.User.ID = user.Data.Viewer.ID
post.Data.MediaList.User.Name = user.Data.Viewer.Name
post.Data.MediaList.User.Avatar.Large = user.Data.Viewer.Avatar.Large
post.Data.MediaList.User.Avatar.Medium = user.Data.Viewer.Avatar.Medium
post.Data.MediaList.User.Statistics.Anime.Count = 0
// This provides an empty array and frees up the memory from the garbage collector
post.Data.MediaList.User.Statistics.Anime.Statuses = nil
}
return post
}