From 53b7368dafc9d4d11e8b1c0d88b32c97ba17d235 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Tue, 30 Jul 2024 20:41:18 -0400 Subject: [PATCH] cleaned up user anilist functions --- AniListFunctions.go | 12 ++-------- frontend/wailsjs/go/main/App.js | 20 ++++++++++++----- frontend/wailsjs/go/models.ts | 39 +++++++++++++++------------------ 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/AniListFunctions.go b/AniListFunctions.go index 94be911..2b145fe 100644 --- a/AniListFunctions.go +++ b/AniListFunctions.go @@ -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 { diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index 7fd68be..06ac105 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -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() { diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index 5688c83..938aac5 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -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"]; + } } }