From a24a187c7f630f4e1173215f8b912ac69d5cb42a Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 16 Sep 2024 12:45:57 -0400 Subject: [PATCH] fixed bug where anilist would display a different users stats if show was not in watchlist --- AniListFunctions.go | 36 +++++++++++++++++-- .../AniList/Get Items/AniList Item.bru | 2 +- .../AniList/Get Items/AniList Search.bru | 2 +- .../Simkl/Get Items/Get Anime Full Info.bru | 2 +- frontend/wailsjs/go/main/App.d.ts | 2 +- frontend/wailsjs/go/models.ts | 4 +-- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/AniListFunctions.go b/AniListFunctions.go index db13e51..6c0cb1b 100644 --- a/AniListFunctions.go +++ b/AniListFunctions.go @@ -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 } diff --git a/bruno/AniTrack/AniList/Get Items/AniList Item.bru b/bruno/AniTrack/AniList/Get Items/AniList Item.bru index f1ad7a8..9953d23 100644 --- a/bruno/AniTrack/AniList/Get Items/AniList Item.bru +++ b/bruno/AniTrack/AniList/Get Items/AniList Item.bru @@ -93,7 +93,7 @@ body:graphql { body:graphql:vars { { "userId": 413504, - "mediaId": 1, + "mediaId": 168345, "listType": "ANIME" } } diff --git a/bruno/AniTrack/AniList/Get Items/AniList Search.bru b/bruno/AniTrack/AniList/Get Items/AniList Search.bru index 6fcba48..6a0cfe2 100644 --- a/bruno/AniTrack/AniList/Get Items/AniList Search.bru +++ b/bruno/AniTrack/AniList/Get Items/AniList Search.bru @@ -53,7 +53,7 @@ body:graphql { body:graphql:vars { { - "search": "frieren", + "search": "dungeon people", "listType": "ANIME" } } diff --git a/bruno/AniTrack/Simkl/Get Items/Get Anime Full Info.bru b/bruno/AniTrack/Simkl/Get Items/Get Anime Full Info.bru index 2e28fab..86c1dde 100644 --- a/bruno/AniTrack/Simkl/Get Items/Get Anime Full Info.bru +++ b/bruno/AniTrack/Simkl/Get Items/Get Anime Full Info.bru @@ -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 } diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index e060917..be83217 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -38,7 +38,7 @@ export function MyAnimeListLogin():Promise; export function MyAnimeListUpdate(arg1:main.MALAnime,arg2:main.MALUploadStatus):Promise; -export function SimklGetUserWatchlist():Promise; +export function SimklGetUserWatchlist():Promise; export function SimklLogin():Promise; diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index e333d6e..3ba4eca 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -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 = {}) {