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

This commit is contained in:
John O'Keefe 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
}

View File

@ -93,7 +93,7 @@ body:graphql {
body:graphql:vars {
{
"userId": 413504,
"mediaId": 1,
"mediaId": 168345,
"listType": "ANIME"
}
}

View File

@ -53,7 +53,7 @@ body:graphql {
body:graphql:vars {
{
"search": "frieren",
"search": "dungeon people",
"listType": "ANIME"
}
}

View File

@ -5,7 +5,7 @@ meta {
}
get {
url: https://api.simkl.com/anime/862523?extended=full
url: https://api.simkl.com/anime/1579943?extended=full
body: none
auth: none
}

View File

@ -38,7 +38,7 @@ export function MyAnimeListLogin():Promise<void>;
export function MyAnimeListUpdate(arg1:main.MALAnime,arg2:main.MALUploadStatus):Promise<main.MalListStatus>;
export function SimklGetUserWatchlist():Promise<main.SimklWatchList>;
export function SimklGetUserWatchlist():Promise<main.SimklWatchListType>;
export function SimklLogin():Promise<void>;

View File

@ -505,11 +505,11 @@ export namespace main {
this.connections = source["connections"];
}
}
export class SimklWatchList {
export class SimklWatchListType {
anime: anime;
static createFrom(source: any = {}) {
return new SimklWatchList(source);
return new SimklWatchListType(source);
}
constructor(source: any = {}) {