Fixed Simkl Bugs

This commit is contained in:
John O'Keefe 2024-08-18 17:23:09 -04:00
parent 6ebf5ac48e
commit 4d9012b43c
13 changed files with 280 additions and 157 deletions

View File

@ -7,43 +7,23 @@ import (
"io" "io"
"log" "log"
"net/http" "net/http"
"reflect"
"strconv"
) )
func (a *App) SimklGetUserWatchlist() SimklWatchList { var WatchList SimklWatchList
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.simkl.com/sync/all-items/anime/watching", nil) func SimklHelper(method string, url string, body interface{}) json.RawMessage {
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer "+simklJwt.AccessToken)
req.Header.Add("simkl-api-key", Environment.SIMKL_CLIENT_ID)
resp, err := client.Do(req)
if err != nil {
fmt.Println("Errored when sending request to the server")
return SimklWatchList{}
}
defer resp.Body.Close()
respBody, _ := io.ReadAll(resp.Body)
var watchlist SimklWatchList
err = json.Unmarshal(respBody, &watchlist)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
return watchlist
}
func SimklPostHelper(url string, body interface{}) json.RawMessage {
reader, _ := json.Marshal(body) reader, _ := json.Marshal(body)
var req *http.Request
client := &http.Client{} client := &http.Client{}
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(reader)) if body != nil {
req, _ = http.NewRequest(method, url, bytes.NewBuffer(reader))
} else {
req, _ = http.NewRequest(method, url, nil)
}
req.Header.Add("Content-Type", "application/json") req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer "+simklJwt.AccessToken) req.Header.Add("Authorization", "Bearer "+simklJwt.AccessToken)
@ -54,7 +34,7 @@ func SimklPostHelper(url string, body interface{}) json.RawMessage {
if err != nil { if err != nil {
fmt.Println("Errored when sending request to the server") fmt.Println("Errored when sending request to the server")
message, _ := json.Marshal(struct { message, _ := json.Marshal(struct {
Message string `json:"message" ts_type:"message"` Message string `json:"message"`
}{ }{
Message: "Errored when sending request to the server" + err.Error(), Message: "Errored when sending request to the server" + err.Error(),
}) })
@ -69,7 +49,41 @@ func SimklPostHelper(url string, body interface{}) json.RawMessage {
} }
func (a *App) SimklSyncEpisodes(anime Anime, progress int) interface{} { func (a *App) SimklGetUserWatchlist() SimklWatchList {
method := "GET"
url := "https://api.simkl.com/sync/all-items/anime/watching"
respBody := SimklHelper(method, url, nil)
var errCheck struct {
Error string `json:"error"`
Message string `json:"message"`
}
err := json.Unmarshal(respBody, &errCheck)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
if errCheck.Error != "" {
a.LogoutSimkl()
return SimklWatchList{}
}
var watchlist SimklWatchList
err = json.Unmarshal(respBody, &watchlist)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
WatchList = watchlist
return watchlist
}
func (a *App) SimklSyncEpisodes(anime SimklAnime, progress int) interface{} {
var episodes []Episode var episodes []Episode
var url string var url string
@ -101,7 +115,7 @@ func (a *App) SimklSyncEpisodes(anime Anime, progress int) interface{} {
simklSync := SimklSyncHistoryType{shows} simklSync := SimklSyncHistoryType{shows}
respBody := SimklPostHelper(url, simklSync) respBody := SimklHelper("POST", url, simklSync)
var success interface{} var success interface{}
@ -113,7 +127,7 @@ func (a *App) SimklSyncEpisodes(anime Anime, progress int) interface{} {
return success return success
} }
func (a *App) SimklSyncRating(anime Anime, rating int) interface{} { func (a *App) SimklSyncRating(anime SimklAnime, rating int) interface{} {
var url string var url string
var showWithRating = ShowWithRating{ var showWithRating = ShowWithRating{
Title: anime.Show.Title, Title: anime.Show.Title,
@ -148,7 +162,7 @@ func (a *App) SimklSyncRating(anime Anime, rating int) interface{} {
Shows []interface{} `json:"shows" ts_type:"shows"` Shows []interface{} `json:"shows" ts_type:"shows"`
}{shows} }{shows}
respBody := SimklPostHelper(url, simklSync) respBody := SimklHelper("POST", url, simklSync)
var success interface{} var success interface{}
@ -160,7 +174,7 @@ func (a *App) SimklSyncRating(anime Anime, rating int) interface{} {
return success return success
} }
func (a *App) SimklSyncStatus(anime Anime, status string) interface{} { func (a *App) SimklSyncStatus(anime SimklAnime, status string) interface{} {
url := "https://api.simkl.com/sync/add-to-list" url := "https://api.simkl.com/sync/add-to-list"
var show = SimklShowStatus{ var show = SimklShowStatus{
Title: anime.Show.Title, Title: anime.Show.Title,
@ -180,7 +194,7 @@ func (a *App) SimklSyncStatus(anime Anime, status string) interface{} {
Shows []SimklShowStatus `json:"shows" ts_type:"shows"` Shows []SimklShowStatus `json:"shows" ts_type:"shows"`
}{shows} }{shows}
respBody := SimklPostHelper(url, simklSync) respBody := SimklHelper("POST", url, simklSync)
var success interface{} var success interface{}
@ -191,3 +205,44 @@ func (a *App) SimklSyncStatus(anime Anime, status string) interface{} {
return success return success
} }
func (a *App) SimklSearch(aniId int) SimklAnime {
fmt.Println(aniId)
var result SimklAnime
if reflect.DeepEqual(WatchList, SimklWatchList{}) {
fmt.Println("Watchlist empty. Calling...")
WatchList = a.SimklGetUserWatchlist()
}
for _, anime := range WatchList.Anime {
id, err := strconv.Atoi(anime.Show.Ids.AniList)
if err != nil {
fmt.Println("AniList ID does not exist on " + anime.Show.Title)
}
if id == aniId {
result = anime
}
}
if reflect.DeepEqual(result, SimklAnime{}) {
var anime SimklSearchType
url := "https://api.simkl.com/search/id?anilist=" + strconv.Itoa(aniId)
respBody := SimklHelper("GET", url, nil)
err := json.Unmarshal(respBody, &anime)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
if len(anime) > 0 {
result.Show.Title = anime[0].Title
result.Show.Poster = anime[0].Poster
result.Show.Ids.Simkl = anime[0].Ids.Simkl
result.Show.Ids.Slug = anime[0].Ids.Slug
}
}
return result
}

View File

@ -27,10 +27,10 @@ type SimklUser struct {
} }
type SimklWatchList struct { type SimklWatchList struct {
Anime []Anime `json:"anime" ts_type:"anime"` Anime []SimklAnime `json:"anime" ts_type:"anime"`
} }
type Anime struct { type SimklAnime struct {
LastWatchedAt string `json:"last_watched_at" ts_type:"last_watched_at"` LastWatchedAt string `json:"last_watched_at" ts_type:"last_watched_at"`
Status string `json:"status" ts_type:"status"` Status string `json:"status" ts_type:"status"`
UserRating float64 `json:"user_rating" ts_type:"user_rating"` UserRating float64 `json:"user_rating" ts_type:"user_rating"`
@ -105,3 +105,17 @@ type SimklShowStatus struct {
Ids `json:"ids" ts_type:"ids"` Ids `json:"ids" ts_type:"ids"`
To string `json:"to" ts_type:"to"` To string `json:"to" ts_type:"to"`
} }
type SimklSearchType []struct {
Type string `json:"type"`
Title string `json:"title"`
Poster string `json:"poster"`
Year int `json:"year"`
Status string `json:"status"`
Ids struct {
Simkl int `json:"simkl"`
Slug string `json:"slug"`
} `json:"ids"`
TotalEpisodes int `json:"total_episodes"`
AnimeType string `json:"anime_type"`
}

View File

@ -181,10 +181,26 @@ func (a *App) GetSimklLoggedInUser() SimklUser {
defer response.Body.Close() defer response.Body.Close()
var user SimklUser
respBody, _ := io.ReadAll(response.Body) respBody, _ := io.ReadAll(response.Body)
var errCheck struct {
Error string `json:"error"`
Message string `json:"message"`
}
err = json.Unmarshal(respBody, &errCheck)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
if errCheck.Error != "" {
a.LogoutSimkl()
return SimklUser{}
}
var user SimklUser
err = json.Unmarshal(respBody, &user) err = json.Unmarshal(respBody, &user)
if err != nil { if err != nil {
log.Printf("Failed at unmarshal, %s\n", err) log.Printf("Failed at unmarshal, %s\n", err)

View File

@ -5,7 +5,7 @@ meta {
} }
get { get {
url: https://api.myanimelist.net/v2/anime/52991?fields=id,title,main_picture,alternative_titles,start_date,end_date,synopsis,mean,rank,popularity,num_list_users,num_scoring_users,nsfw,genres,created_at,updated_at,media_type,status,my_list_status,num_episodes,start_season,broadcast,source,average_episode_duration,rating,pictures,background,related_anime,recommendations,studios,statistics url: https://api.myanimelist.net/v2/anime/53580?fields=id,title,main_picture,alternative_titles,start_date,end_date,synopsis,mean,rank,popularity,num_list_users,num_scoring_users,nsfw,genres,created_at,updated_at,media_type,status,my_list_status,num_episodes,start_season,broadcast,source,average_episode_duration,rating,pictures,background,related_anime,recommendations,studios,statistics
body: none body: none
auth: bearer auth: bearer
} }

View File

@ -1,16 +0,0 @@
meta {
name: Search By MalID
type: http
seq: 1
}
get {
url: https://api.simkl.com/search/id?client_id={{SIMKL_CLIENT_ID}}&simkl=2307708
body: none
auth: none
}
params:query {
client_id: {{SIMKL_CLIENT_ID}}
simkl: 2307708
}

View File

@ -4,28 +4,30 @@
anilistModal, anilistModal,
aniListPrimary, aniListPrimary,
aniListUser, aniListUser,
malUser,
malLoggedIn,
aniListWatchlist, aniListWatchlist,
animePerPage,
GetAniListSingleItemAndOpenModal, GetAniListSingleItemAndOpenModal,
malLoggedIn,
malPrimary,
malUser,
malWatchList,
simklLoggedIn, simklLoggedIn,
simklUser, simklUser,
simklWatchList, simklWatchList,
title, title,
watchListPage, watchListPage,
animePerPage, simklPrimary,
malWatchList,
malPrimary
} from "./GlobalVariablesAndHelperFunctions.svelte"; } from "./GlobalVariablesAndHelperFunctions.svelte";
import { import {
CheckIfAniListLoggedIn, CheckIfAniListLoggedIn,
CheckIfSimklLoggedIn,
CheckIfMyAnimeListLoggedIn, CheckIfMyAnimeListLoggedIn,
CheckIfSimklLoggedIn,
GetAniListLoggedInUser, GetAniListLoggedInUser,
GetAniListUserWatchingList, GetAniListUserWatchingList,
GetMyAnimeList,
GetMyAnimeListLoggedInUser,
GetSimklLoggedInUser, GetSimklLoggedInUser,
SimklGetUserWatchlist, SimklGetUserWatchlist,
GetMyAnimeListLoggedInUser, GetMyAnimeList,
} from "../wailsjs/go/main/App"; } from "../wailsjs/go/main/App";
import {MediaListSort} from "./anilist/types/AniListTypes"; import {MediaListSort} from "./anilist/types/AniListTypes";
import type {AniListCurrentUserWatchList} from "./anilist/types/AniListCurrentUserWatchListType" import type {AniListCurrentUserWatchList} from "./anilist/types/AniListCurrentUserWatchListType"
@ -40,12 +42,14 @@
let isAniListLoggedIn: boolean let isAniListLoggedIn: boolean
let isAniListPrimary: boolean let isAniListPrimary: boolean
let isMalPrimary: boolean let isMalPrimary: boolean
let isSimklPrimary: boolean
let aniListWatchListLoaded: AniListCurrentUserWatchList let aniListWatchListLoaded: AniListCurrentUserWatchList
aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value) aniListLoggedIn.subscribe((value) => isAniListLoggedIn = value)
aniListPrimary.subscribe((value) => isAniListPrimary = value) aniListPrimary.subscribe((value) => isAniListPrimary = value)
aniListWatchlist.subscribe((value) => aniListWatchListLoaded = value) aniListWatchlist.subscribe((value) => aniListWatchListLoaded = value)
malPrimary.subscribe((value) => isMalPrimary = value) malPrimary.subscribe((value) => isMalPrimary = value)
simklPrimary.subscribe(value => isSimklPrimary = value)
let page: number let page: number
@ -90,11 +94,19 @@
await CheckIfSimklLoggedIn().then(loggedIn => { await CheckIfSimklLoggedIn().then(loggedIn => {
if (loggedIn) { if (loggedIn) {
GetSimklLoggedInUser().then(user => { GetSimklLoggedInUser().then(user => {
if (Object.keys(user).length === 0) {
simklLoggedIn.set(false)
} else {
simklUser.set(user) simklUser.set(user)
if(isSimklPrimary) {
SimklGetUserWatchlist().then(result => { SimklGetUserWatchlist().then(result => {
simklWatchList.set(result) simklWatchList.set(result)
simklLoggedIn.set(loggedIn) simklLoggedIn.set(loggedIn)
}) })
} else {
simklLoggedIn.set(loggedIn)
}
}
}) })
} }
}) })
@ -107,9 +119,13 @@
{#if isAniListLoggedIn} {#if isAniListLoggedIn}
<div class="mx-auto max-w-2xl p-4 sm:p-6 lg:max-w-7xl lg:px-8 relative items-center"> <div class="mx-auto max-w-2xl p-4 sm:p-6 lg:max-w-7xl lg:px-8 relative items-center">
<div id="spinner" role="status" class="fixed hidden -translate-x-1/2 -translate-y-1/2 top-2/4 left-1/2"> <div id="spinner" role="status" class="fixed hidden -translate-x-1/2 -translate-y-1/2 top-2/4 left-1/2">
<svg aria-hidden="true" class="inline w-16 h-16 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg aria-hidden="true"
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/> class="inline w-16 h-16 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/> viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"/>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"/>
</svg> </svg>
<span class="sr-only">Loading...</span> <span class="sr-only">Loading...</span>
</div> </div>

View File

@ -5,7 +5,8 @@
aniListLoggedIn, aniListLoggedIn,
simklLoggedIn, simklLoggedIn,
malLoggedIn, malLoggedIn,
malAnime malAnime,
simklAnime,
} from "./GlobalVariablesAndHelperFunctions.svelte"; } from "./GlobalVariablesAndHelperFunctions.svelte";
import {aniListAnime} from "./GlobalVariablesAndHelperFunctions.svelte"; import {aniListAnime} from "./GlobalVariablesAndHelperFunctions.svelte";
import {Button} from "flowbite-svelte"; import {Button} from "flowbite-svelte";
@ -14,8 +15,7 @@
import moment from 'moment' import moment from 'moment'
import { Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell } from 'flowbite-svelte'; import { Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell } from 'flowbite-svelte';
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import type {SimklAnime} from "./simkl/types/simklTypes"; import type {SimklAnime, SimklWatchList} from "./simkl/types/simklTypes";
import { get } from 'svelte/store';
import { import {
AniListUpdateEntry, MyAnimeListUpdate, AniListUpdateEntry, MyAnimeListUpdate,
SimklSyncEpisodes, SimklSyncEpisodes,
@ -25,13 +25,12 @@
import type {MALAnime, MALUploadStatus, MyListStatus} from "./mal/types/MALTypes"; import type {MALAnime, MALUploadStatus, MyListStatus} from "./mal/types/MALTypes";
import type {AniListUpdateVariables} from "./anilist/types/AniListTypes"; import type {AniListUpdateVariables} from "./anilist/types/AniListTypes";
const simklWatch = get(simklWatchList); let simklWatch: SimklWatchList
let isAniListLoggedIn: boolean let isAniListLoggedIn: boolean
let isMalLoggedIn: boolean let isMalLoggedIn: boolean
let isSimklLoggedIn: boolean let isSimklLoggedIn: boolean
let simklAnimeIndex: number
let currentMalAnime: MALAnime let currentMalAnime: MALAnime
let simklAnime: SimklAnime | undefined = undefined let currentSimklAnime: SimklAnime
let submitting = writable(false) let submitting = writable(false)
let isSubmitting: boolean let isSubmitting: boolean
@ -40,13 +39,8 @@
simklLoggedIn.subscribe((value) => isSimklLoggedIn = value) simklLoggedIn.subscribe((value) => isSimklLoggedIn = value)
malAnime.subscribe((value) => currentMalAnime = value) malAnime.subscribe((value) => currentMalAnime = value)
submitting.subscribe((value) => isSubmitting = value) submitting.subscribe((value) => isSubmitting = value)
simklWatchList.subscribe((value) => simklWatch = value)
for (let i = 0; i < simklWatch.anime.length; i++) { simklAnime.subscribe((value) => currentSimklAnime = value)
if (Number(simklWatch.anime[i].show.ids.mal) === aniListAnime.data.MediaList.media.idMal) {
simklAnimeIndex = i
simklAnime = simklWatch.anime[i]
}
}
type statusOption = { type statusOption = {
id: number, id: number,
@ -108,15 +102,15 @@
}) })
} }
if(isSimklLoggedIn && simklAnime !== undefined) { if(isSimklLoggedIn && Object.keys(currentSimklAnime).length > 0) {
items.push({ items.push({
id: simklAnime.show.ids.simkl, id: currentSimklAnime.show.ids.simkl,
service: "Simkl", service: "Simkl",
progress: simklAnime.watched_episodes_count, progress: currentSimklAnime.watched_episodes_count,
status: simklAnime.status, status: currentSimklAnime.status,
startedAt: "", startedAt: "",
completedAt: "", completedAt: "",
score: simklAnime.user_rating, score: currentSimklAnime.user_rating,
repeat: 0, repeat: 0,
notes: "" notes: ""
}) })
@ -299,24 +293,24 @@
} }
if (simklLoggedIn) { if (simklLoggedIn) {
if (simklAnime.watched_episodes_count !== values.progress) { if (currentSimklAnime.watched_episodes_count !== values.progress) {
await SimklSyncEpisodes(simklAnime, values.progress).then(() => { await SimklSyncEpisodes(currentSimklAnime, values.progress).then(() => {
simklAnime.watched_episodes_count = values.progress currentSimklAnime.watched_episodes_count = values.progress
simklWatch.anime[simklAnimeIndex].watched_episodes_count = values.progress simklWatch.anime[simklWatch.currentIndex].watched_episodes_count = values.progress
}) })
} }
if (simklAnime.user_rating !== values.score) { if (currentSimklAnime.user_rating !== values.score) {
await SimklSyncRating(simklAnime, values.score).then(() => { await SimklSyncRating(currentSimklAnime, values.score).then(() => {
simklAnime.user_rating = values.score currentSimklAnime.user_rating = values.score
simklWatch.anime[simklAnimeIndex].user_rating = values.score simklWatch.anime[simklWatch.currentIndex].user_rating = values.score
}) })
} }
if (simklAnime.status !== values.status.simkl) { if (currentSimklAnime.status !== values.status.simkl) {
await SimklSyncStatus(simklAnime, values.status.simkl).then(() => { await SimklSyncStatus(currentSimklAnime, values.status.simkl).then(() => {
simklAnime.status = values.status.simkl currentSimklAnime.status = values.status.simkl
simklWatch.anime[simklAnimeIndex].status = values.status.simkl simklWatch.anime[simklWatch.currentIndex].status = values.status.simkl
}) })
} }
} }

View File

@ -1,15 +1,23 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
import { import {
GetAniListItem, GetAniListItem,
GetAniListLoggedInUser, GetAniListUserWatchingList, GetMyAnimeListAnime, GetMyAnimeListLoggedInUser, GetAniListLoggedInUser,
GetSimklLoggedInUser, LogoutAniList, LogoutMyAnimeList, LogoutSimkl GetAniListUserWatchingList,
GetMyAnimeListAnime,
GetMyAnimeListLoggedInUser,
GetSimklLoggedInUser,
LogoutAniList,
LogoutMyAnimeList,
LogoutSimkl,
SimklGetUserWatchlist,
SimklSearch
} from "../wailsjs/go/main/App"; } from "../wailsjs/go/main/App";
import type { import type {
AniListCurrentUserWatchList, AniListCurrentUserWatchList,
AniListGetSingleAnime AniListGetSingleAnime
} from "./anilist/types/AniListCurrentUserWatchListType.js"; } from "./anilist/types/AniListCurrentUserWatchListType.js";
import {writable} from 'svelte/store' import {writable} from 'svelte/store'
import type {SimklUser, SimklWatchList} from "./simkl/types/simklTypes"; import type {SimklAnime, SimklUser, SimklWatchList} from "./simkl/types/simklTypes";
import {type AniListUser, MediaListSort} from "./anilist/types/AniListTypes"; import {type AniListUser, MediaListSort} from "./anilist/types/AniListTypes";
import type {MALAnime, MALWatchlist, MyAnimeListUser} from "./mal/types/MALTypes"; import type {MALAnime, MALWatchlist, MyAnimeListUser} from "./mal/types/MALTypes";
@ -21,6 +29,7 @@
export let malLoggedIn = writable(false) export let malLoggedIn = writable(false)
export let simklWatchList = writable({} as SimklWatchList) export let simklWatchList = writable({} as SimklWatchList)
export let aniListPrimary = writable(true) export let aniListPrimary = writable(true)
export let simklPrimary = writable(false)
export let malPrimary = writable(false) export let malPrimary = writable(false)
export let simklUser = writable({} as SimklUser) export let simklUser = writable({} as SimklUser)
export let aniListUser = writable({} as AniListUser) export let aniListUser = writable({} as AniListUser)
@ -28,6 +37,7 @@
export let aniListWatchlist = writable({} as AniListCurrentUserWatchList) export let aniListWatchlist = writable({} as AniListCurrentUserWatchList)
export let malWatchList = writable({} as MALWatchlist) export let malWatchList = writable({} as MALWatchlist)
export let malAnime = writable({} as MALAnime) export let malAnime = writable({} as MALAnime)
export let simklAnime = writable({} as SimklAnime)
export let watchListPage = writable(1) export let watchListPage = writable(1)
export let animePerPage = writable(20) export let animePerPage = writable(20)
@ -36,14 +46,20 @@
let page: number let page: number
let perPage: number let perPage: number
let aniWatchlist: AniListCurrentUserWatchList let aniWatchlist: AniListCurrentUserWatchList
let simklWatch: SimklWatchList
let currentSimklAnime: SimklAnime
let isMalLoggedIn: boolean let isMalLoggedIn: boolean
let isSimklLoggedIn: boolean
aniListPrimary.subscribe(value => isAniListPrimary = value) aniListPrimary.subscribe(value => isAniListPrimary = value)
watchListPage.subscribe(value => page = value) watchListPage.subscribe(value => page = value)
animePerPage.subscribe(value => perPage = value) animePerPage.subscribe(value => perPage = value)
aniListWatchlist.subscribe(value => aniWatchlist = value) aniListWatchlist.subscribe(value => aniWatchlist = value)
malLoggedIn.subscribe(value => isMalLoggedIn = value) malLoggedIn.subscribe(value => isMalLoggedIn = value)
simklLoggedIn.subscribe(value => isSimklLoggedIn = value)
simklWatchList.subscribe(value => simklWatch = value)
simklAnime.subscribe(value => currentSimklAnime = value)
export async function GetAniListSingleItemAndOpenModal(aniId: number, login: boolean): Promise<""> { export async function GetAniListSingleItemAndOpenModal(aniId: number, login: boolean): Promise<""> {
@ -52,26 +68,34 @@
title.set(aniListAnime.data.MediaList.media.title.english === "" ? title.set(aniListAnime.data.MediaList.media.title.english === "" ?
aniListAnime.data.MediaList.media.title.romaji : aniListAnime.data.MediaList.media.title.romaji :
aniListAnime.data.MediaList.media.title.english) aniListAnime.data.MediaList.media.title.english)
})
if (isMalLoggedIn) { if (isMalLoggedIn) {
GetMyAnimeListAnime(aniListAnime.data.MediaList.media.idMal).then(malResult => { await GetMyAnimeListAnime(aniListAnime.data.MediaList.media.idMal).then(malResult => {
malAnime.set(malResult) malAnime.set(malResult)
anilistModal.set(true)
return ""
}) })
} else {
anilistModal.set(true)
return ""
} }
if (isSimklLoggedIn) {
await SimklSearch(aniListAnime.data.MediaList.media.id).then((value: SimklAnime) => {
simklAnime.set(value)
}) })
}
anilistModal.set(true)
return "" return ""
} }
export function loginToSimkl(): void { export function loginToSimkl(): void {
GetSimklLoggedInUser().then(result => { GetSimklLoggedInUser().then(user => {
simklUser.set(result) if (Object.keys(user).length === 0) {
simklLoggedIn.set(false)
} else {
simklUser.set(user)
SimklGetUserWatchlist().then(result => {
simklWatchList.set(result)
simklLoggedIn.set(true) simklLoggedIn.set(true)
}) })
} }
})
}
export function loginToAniList(): void { export function loginToAniList(): void {
GetAniListLoggedInUser().then(result => { GetAniListLoggedInUser().then(result => {

View File

@ -10,7 +10,6 @@
function runAniListSearch(): void { function runAniListSearch(): void {
AniListSearch(aniSearch).then(result => { AniListSearch(aniSearch).then(result => {
console.log(result.data.Page.media[5])
aniListSearch = result aniListSearch = result
aniListSearchActive = true aniListSearchActive = true
}) })

View File

@ -20,6 +20,7 @@ export type SimklUser = {
export type SimklWatchList = { export type SimklWatchList = {
anime: [SimklAnime] anime: [SimklAnime]
currentIndex: number
} }
export type SimklAnime = { export type SimklAnime = {
@ -59,3 +60,17 @@ export type SimklAnime = {
}, },
anime_type: string anime_type: string
} }
export type SimklSearchType = [{
type: string;
title: string;
poster: string;
year: number;
status: string;
ids: {
simkl: number;
slug: string;
};
totalEpisodes: number;
animeType: string;
}]

View File

@ -42,8 +42,10 @@ export function SimklGetUserWatchlist():Promise<main.SimklWatchList>;
export function SimklLogin():Promise<void>; export function SimklLogin():Promise<void>;
export function SimklSyncEpisodes(arg1:main.Anime,arg2:number):Promise<any>; export function SimklSearch(arg1:number):Promise<main.SimklAnime>;
export function SimklSyncRating(arg1:main.Anime,arg2:number):Promise<any>; export function SimklSyncEpisodes(arg1:main.SimklAnime,arg2:number):Promise<any>;
export function SimklSyncStatus(arg1:main.Anime,arg2:string):Promise<any>; export function SimklSyncRating(arg1:main.SimklAnime,arg2:number):Promise<any>;
export function SimklSyncStatus(arg1:main.SimklAnime,arg2:string):Promise<any>;

View File

@ -82,6 +82,10 @@ export function SimklLogin() {
return window['go']['main']['App']['SimklLogin'](); return window['go']['main']['App']['SimklLogin']();
} }
export function SimklSearch(arg1) {
return window['go']['main']['App']['SimklSearch'](arg1);
}
export function SimklSyncEpisodes(arg1, arg2) { export function SimklSyncEpisodes(arg1, arg2) {
return window['go']['main']['App']['SimklSyncEpisodes'](arg1, arg2); return window['go']['main']['App']['SimklSyncEpisodes'](arg1, arg2);
} }

View File

@ -167,36 +167,6 @@ export namespace main {
return a; return a;
} }
} }
export class Anime {
last_watched_at: last_watched_at;
status: status;
user_rating: user_rating;
last_watched: last_watched;
next_to_watch: next_to_watch;
watched_episodes_count: watched_episodes_count;
total_episodes_count: total_episodes_count;
not_aired_episodes_count: not_aired_episodes_count;
show: show;
anime_type: anime_type;
static createFrom(source: any = {}) {
return new Anime(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.last_watched_at = source["last_watched_at"];
this.status = source["status"];
this.user_rating = source["user_rating"];
this.last_watched = source["last_watched"];
this.next_to_watch = source["next_to_watch"];
this.watched_episodes_count = source["watched_episodes_count"];
this.total_episodes_count = source["total_episodes_count"];
this.not_aired_episodes_count = source["not_aired_episodes_count"];
this.show = source["show"];
this.anime_type = source["anime_type"];
}
}
export class MALAnime { export class MALAnime {
id: id; id: id;
@ -489,6 +459,36 @@ export namespace main {
this.updated_at = source["updated_at"]; this.updated_at = source["updated_at"];
} }
} }
export class SimklAnime {
last_watched_at: last_watched_at;
status: status;
user_rating: user_rating;
last_watched: last_watched;
next_to_watch: next_to_watch;
watched_episodes_count: watched_episodes_count;
total_episodes_count: total_episodes_count;
not_aired_episodes_count: not_aired_episodes_count;
show: show;
anime_type: anime_type;
static createFrom(source: any = {}) {
return new SimklAnime(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.last_watched_at = source["last_watched_at"];
this.status = source["status"];
this.user_rating = source["user_rating"];
this.last_watched = source["last_watched"];
this.next_to_watch = source["next_to_watch"];
this.watched_episodes_count = source["watched_episodes_count"];
this.total_episodes_count = source["total_episodes_count"];
this.not_aired_episodes_count = source["not_aired_episodes_count"];
this.show = source["show"];
this.anime_type = source["anime_type"];
}
}
export class SimklUser { export class SimklUser {
user: user; user: user;
account: account; account: account;