added ability to change simkl rating

This commit is contained in:
John O'Keefe 2024-08-11 18:32:44 -04:00
parent b11395a617
commit a6b26171d4
5 changed files with 81 additions and 7 deletions

View File

@ -113,3 +113,50 @@ func (a *App) SimklSyncEpisodes(anime Anime, progress int) interface{} {
return success return success
} }
func (a *App) SimklSyncRating(anime Anime, rating int) interface{} {
var url string
var showWithRating = ShowWithRating{
Title: anime.Show.Title,
Ids: Ids{
Simkl: anime.Show.Ids.Simkl,
Mal: anime.Show.Ids.Mal,
Anilist: anime.Show.Ids.AniList,
},
Rating: rating,
}
var showWithoutRating = ShowWithoutRating{
Title: anime.Show.Title,
Ids: Ids{
Simkl: anime.Show.Ids.Simkl,
Mal: anime.Show.Ids.Mal,
Anilist: anime.Show.Ids.AniList,
},
}
var shows []interface{}
if rating > 0 {
shows = append(shows, showWithRating)
url = "https://api.simkl.com/sync/ratings"
} else {
shows = append(shows, showWithoutRating)
url = "https://api.simkl.com/sync/ratings/remove"
}
simklSync := struct {
Shows []interface{} `json:"shows" ts_type:"shows"`
}{shows}
respBody := SimklPostHelper(url, simklSync)
var success interface{}
err := json.Unmarshal(respBody, &success)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
return success
}

View File

@ -88,3 +88,14 @@ type Ids struct {
Mal string `json:"mal" ts_type:"mal"` Mal string `json:"mal" ts_type:"mal"`
Anilist string `json:"anilist" ts_type:"anilist"` Anilist string `json:"anilist" ts_type:"anilist"`
} }
type ShowWithRating struct {
Title string `json:"title" ts_type:"title"`
Ids `json:"ids" ts_type:"ids"`
Rating int `json:"rating" ts_type:"rating"`
}
type ShowWithoutRating struct {
Title string `json:"title" ts_type:"title"`
Ids `json:"ids" ts_type:"ids"`
}

View File

@ -14,7 +14,7 @@
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import type {SimklAnime} from "./simkl/types/simklTypes"; import type {SimklAnime} from "./simkl/types/simklTypes";
import { get } from 'svelte/store'; import { get } from 'svelte/store';
import {AniListUpdateEntry, SimklSyncEpisodes} from "../wailsjs/go/main/App"; import {AniListUpdateEntry, SimklSyncEpisodes, SimklSyncRating} from "../wailsjs/go/main/App";
const simklWatch = get(simklWatchList); const simklWatch = get(simklWatchList);
let isAniListLoggedIn: boolean let isAniListLoggedIn: boolean
@ -211,12 +211,22 @@
console.log(value) console.log(value)
}) })
if (simklLoggedIn && simklAnime.watched_episodes_count !== values.progress) { if (simklLoggedIn) {
await SimklSyncEpisodes(simklAnime, values.progress).then(value => { if (simklAnime.watched_episodes_count !== values.progress) {
console.log(value) await SimklSyncEpisodes(simklAnime, values.progress).then(value => {
simklAnime.watched_episodes_count = values.progress console.log(value)
simklWatch.anime[simklAnimeIndex].watched_episodes_count = values.progress simklAnime.watched_episodes_count = values.progress
}) simklWatch.anime[simklAnimeIndex].watched_episodes_count = values.progress
})
}
if (simklAnime.user_rating !== values.score) {
await SimklSyncRating(simklAnime, values.score).then(value => {
console.log(value)
simklAnime.user_rating = values.score
simklWatch.anime[simklAnimeIndex].user_rating = values.score
})
}
} }
} }
</script> </script>

View File

@ -25,3 +25,5 @@ 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 SimklSyncEpisodes(arg1:main.Anime,arg2:number):Promise<any>;
export function SimklSyncRating(arg1:main.Anime,arg2:number):Promise<any>;

View File

@ -49,3 +49,7 @@ export function SimklLogin() {
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);
} }
export function SimklSyncRating(arg1, arg2) {
return window['go']['main']['App']['SimklSyncRating'](arg1, arg2);
}