cleaned up user anilist functions

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

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"];
}
}
}