cleaned up user anilist functions

This commit is contained in:
John O'Keefe 2024-07-30 20:41:18 -04:00
parent c95b658131
commit 53b7368daf
3 changed files with 34 additions and 37 deletions

View File

@ -3,7 +3,6 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
@ -37,12 +36,7 @@ func AniListQuery(body interface{}, login bool) (json.RawMessage, string) {
}
func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime {
var user = a.GetAniListLoggedInUserId()
// type Variables struct {
// UserId int `json:"userId"`
// MediaId int `json:"mediaId"`
// ListType string `json:"listType"`
// }
var user = a.GetAniListLoggedInUser()
var neededVariables interface{}
@ -207,7 +201,7 @@ func (a *App) AniListSearch(query string) any {
}
func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) AniListCurrentUserWatchList {
var user = a.GetAniListLoggedInUserId()
var user = a.GetAniListLoggedInUser()
type Variables struct {
Page int `json:"page"`
PerPage int `json:"perPage"`
@ -311,8 +305,6 @@ func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) Ani
returnedBody, _ := AniListQuery(body, true)
fmt.Println("ReturnedBody: ", string(returnedBody))
var post AniListCurrentUserWatchList
err := json.Unmarshal(returnedBody, &post)
if err != nil {

View File

@ -14,24 +14,32 @@ export function AniListUpdateEntry(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg
return window['go']['main']['App']['AniListUpdateEntry'](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
}
export function CheckIfAniListLoggedIn() {
return window['go']['main']['App']['CheckIfAniListLoggedIn']();
}
export function CheckIfSimklLoggedIn() {
return window['go']['main']['App']['CheckIfSimklLoggedIn']();
}
export function GetAniListItem(arg1, arg2) {
return window['go']['main']['App']['GetAniListItem'](arg1, arg2);
}
export function GetAniListLoggedInUserId() {
return window['go']['main']['App']['GetAniListLoggedInUserId']();
export function GetAniListLoggedInUser() {
return window['go']['main']['App']['GetAniListLoggedInUser']();
}
export function GetAniListUserWatchingList(arg1, arg2, arg3) {
return window['go']['main']['App']['GetAniListUserWatchingList'](arg1, arg2, arg3);
}
export function GetSimklLoggedInUserId() {
return window['go']['main']['App']['GetSimklLoggedInUserId']();
export function GetSimklLoggedInUser() {
return window['go']['main']['App']['GetSimklLoggedInUser']();
}
export function Greet(arg1) {
return window['go']['main']['App']['Greet'](arg1);
export function SimklGetUserWatchlist() {
return window['go']['main']['App']['SimklGetUserWatchlist']();
}
export function SimklLogin() {

View File

@ -61,7 +61,7 @@ export namespace main {
}
}
export class AniListUser {
// Go type: struct { Viewer struct { ID int "json:\"id\""; Name string "json:\"name\"" } "json:\"Viewer\"" }
// Go type: struct { Viewer struct { ID int "json:\"id\""; Name string "json:\"name\""; Avatar struct { Large string "json:\"large\""; Medium string "json:\"medium\"" } "json:\"avatar\""; BannerImage string "json:\"bannerImage\""; SiteUrl string "json:\"siteUrl\"" } "json:\"Viewer\"" }
data: any;
static createFrom(source: any = {}) {
@ -148,8 +148,9 @@ export namespace main {
}
}
export class SimklUser {
// Go type: struct { Viewer struct { ID int "json:\"id\""; Name string "json:\"name\"" } "json:\"Viewer\"" }
data: any;
user: user;
account: account;
connections: connections;
static createFrom(source: any = {}) {
return new SimklUser(source);
@ -157,26 +158,22 @@ export namespace main {
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.data = this.convertValues(source["data"], Object);
this.user = source["user"];
this.account = source["account"];
this.connections = source["connections"];
}
}
export class SimklWatchList {
anime: anime;
static createFrom(source: any = {}) {
return new SimklWatchList(source);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.anime = source["anime"];
}
}
}