fixed a bug in simkl where nothing loads if it does not have an anilist id

This commit is contained in:
John O'Keefe 2024-09-14 23:58:09 -04:00
parent be6c3439ca
commit 4c329d6b9d
3 changed files with 23 additions and 7 deletions

View File

@ -230,7 +230,7 @@ func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime {
return anime
}
func (a *App) SimklSearch(aniId int) SimklAnime {
func (a *App) SimklSearch(aniListAnime MediaList) SimklAnime {
var result SimklAnime
if reflect.DeepEqual(WatchList, SimklWatchList{}) {
@ -243,23 +243,39 @@ func (a *App) SimklSearch(aniId int) SimklAnime {
if err != nil {
fmt.Println("AniList ID does not exist on " + anime.Show.Title)
}
if id == aniId {
if id == aniListAnime.Media.ID {
result = anime
}
}
if reflect.DeepEqual(result, SimklAnime{}) {
var anime SimklSearchType
url := "https://api.simkl.com/search/id?anilist=" + strconv.Itoa(aniId)
url := "https://api.simkl.com/search/id?anilist=" + strconv.Itoa(aniListAnime.Media.ID)
respBody := SimklHelper("GET", url, nil)
err := json.Unmarshal(respBody, &anime)
if len(anime) == 0 {
fmt.Println("reached search by mal")
url = "https://api.simkl.com/search/id?mal=" + strconv.Itoa(aniListAnime.Media.IDMal)
respBody = SimklHelper("GET", url, nil)
fmt.Println(string(respBody))
err = json.Unmarshal(respBody, &anime)
}
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
if len(anime) > 0 {
for _, watchListAnime := range WatchList.Anime {
id := watchListAnime.Show.Ids.Simkl
if id == anime[0].Ids.Simkl {
result = watchListAnime
}
}
if reflect.DeepEqual(result, SimklSearchType{}) && len(anime) > 0 {
result.Show.Title = anime[0].Title
result.Show.Poster = anime[0].Poster
result.Show.Ids.Simkl = anime[0].Ids.Simkl

View File

@ -63,7 +63,7 @@
const completedAtDate = convertAniListDateToString(currentAniListAnime.data.MediaList.completedAt)
if (isAniListLoggedIn) AddAnimeServiceToTable({
id: currentAniListAnime.data.MediaList.id,
id: currentAniListAnime.data.MediaList.mediaId,
title,
service: "AniList",
progress: currentAniListAnime.data.MediaList.progress,
@ -168,7 +168,7 @@
return newValue
})
AddAnimeServiceToTable({
id: currentAniListAnime.data.MediaList.id,
id: currentAniListAnime.data.MediaList.mediaId,
title,
service: "AniList",
progress: currentAniListAnime.data.MediaList.progress,

View File

@ -42,7 +42,7 @@ export function SimklGetUserWatchlist():Promise<main.SimklWatchList>;
export function SimklLogin():Promise<void>;
export function SimklSearch(arg1:number):Promise<main.SimklAnime>;
export function SimklSearch(arg1:main.MediaList):Promise<main.SimklAnime>;
export function SimklSyncEpisodes(arg1:main.SimklAnime,arg2:number):Promise<main.SimklAnime>;