added ability to change simkl rating
This commit is contained in:
parent
b11395a617
commit
a6b26171d4
@ -113,3 +113,50 @@ func (a *App) SimklSyncEpisodes(anime Anime, progress int) interface{} {
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -88,3 +88,14 @@ type Ids struct {
|
||||
Mal string `json:"mal" ts_type:"mal"`
|
||||
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"`
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import type {SimklAnime} from "./simkl/types/simklTypes";
|
||||
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);
|
||||
let isAniListLoggedIn: boolean
|
||||
@ -211,12 +211,22 @@
|
||||
console.log(value)
|
||||
})
|
||||
|
||||
if (simklLoggedIn && simklAnime.watched_episodes_count !== values.progress) {
|
||||
await SimklSyncEpisodes(simklAnime, values.progress).then(value => {
|
||||
console.log(value)
|
||||
simklAnime.watched_episodes_count = values.progress
|
||||
simklWatch.anime[simklAnimeIndex].watched_episodes_count = values.progress
|
||||
})
|
||||
if (simklLoggedIn) {
|
||||
if (simklAnime.watched_episodes_count !== values.progress) {
|
||||
await SimklSyncEpisodes(simklAnime, values.progress).then(value => {
|
||||
console.log(value)
|
||||
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>
|
||||
|
2
frontend/wailsjs/go/main/App.d.ts
vendored
2
frontend/wailsjs/go/main/App.d.ts
vendored
@ -25,3 +25,5 @@ export function SimklGetUserWatchlist():Promise<main.SimklWatchList>;
|
||||
export function SimklLogin():Promise<void>;
|
||||
|
||||
export function SimklSyncEpisodes(arg1:main.Anime,arg2:number):Promise<any>;
|
||||
|
||||
export function SimklSyncRating(arg1:main.Anime,arg2:number):Promise<any>;
|
||||
|
@ -49,3 +49,7 @@ export function SimklLogin() {
|
||||
export function SimklSyncEpisodes(arg1, arg2) {
|
||||
return window['go']['main']['App']['SimklSyncEpisodes'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function SimklSyncRating(arg1, arg2) {
|
||||
return window['go']['main']['App']['SimklSyncRating'](arg1, arg2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user