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 ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"log" "log"
"net/http" "net/http"
@ -37,12 +36,7 @@ func AniListQuery(body interface{}, login bool) (json.RawMessage, string) {
} }
func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime { func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime {
var user = a.GetAniListLoggedInUserId() var user = a.GetAniListLoggedInUser()
// type Variables struct {
// UserId int `json:"userId"`
// MediaId int `json:"mediaId"`
// ListType string `json:"listType"`
// }
var neededVariables interface{} 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 { func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) AniListCurrentUserWatchList {
var user = a.GetAniListLoggedInUserId() var user = a.GetAniListLoggedInUser()
type Variables struct { type Variables struct {
Page int `json:"page"` Page int `json:"page"`
PerPage int `json:"perPage"` PerPage int `json:"perPage"`
@ -311,8 +305,6 @@ func (a *App) GetAniListUserWatchingList(page int, perPage int, sort string) Ani
returnedBody, _ := AniListQuery(body, true) returnedBody, _ := AniListQuery(body, true)
fmt.Println("ReturnedBody: ", string(returnedBody))
var post AniListCurrentUserWatchList var post AniListCurrentUserWatchList
err := json.Unmarshal(returnedBody, &post) err := json.Unmarshal(returnedBody, &post)
if err != nil { 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); 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) { export function GetAniListItem(arg1, arg2) {
return window['go']['main']['App']['GetAniListItem'](arg1, arg2); return window['go']['main']['App']['GetAniListItem'](arg1, arg2);
} }
export function GetAniListLoggedInUserId() { export function GetAniListLoggedInUser() {
return window['go']['main']['App']['GetAniListLoggedInUserId'](); return window['go']['main']['App']['GetAniListLoggedInUser']();
} }
export function GetAniListUserWatchingList(arg1, arg2, arg3) { export function GetAniListUserWatchingList(arg1, arg2, arg3) {
return window['go']['main']['App']['GetAniListUserWatchingList'](arg1, arg2, arg3); return window['go']['main']['App']['GetAniListUserWatchingList'](arg1, arg2, arg3);
} }
export function GetSimklLoggedInUserId() { export function GetSimklLoggedInUser() {
return window['go']['main']['App']['GetSimklLoggedInUserId'](); return window['go']['main']['App']['GetSimklLoggedInUser']();
} }
export function Greet(arg1) { export function SimklGetUserWatchlist() {
return window['go']['main']['App']['Greet'](arg1); return window['go']['main']['App']['SimklGetUserWatchlist']();
} }
export function SimklLogin() { export function SimklLogin() {

View File

@ -61,7 +61,7 @@ export namespace main {
} }
} }
export class AniListUser { 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; data: any;
static createFrom(source: any = {}) { static createFrom(source: any = {}) {
@ -148,8 +148,9 @@ export namespace main {
} }
} }
export class SimklUser { export class SimklUser {
// Go type: struct { Viewer struct { ID int "json:\"id\""; Name string "json:\"name\"" } "json:\"Viewer\"" } user: user;
data: any; account: account;
connections: connections;
static createFrom(source: any = {}) { static createFrom(source: any = {}) {
return new SimklUser(source); return new SimklUser(source);
@ -157,25 +158,21 @@ export namespace main {
constructor(source: any = {}) { constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source); 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 { constructor(source: any = {}) {
if (!a) { if ('string' === typeof source) source = JSON.parse(source);
return a; this.anime = source["anime"];
}
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;
} }
} }