renamed and created anilist and simkl user functions

renamed anilist userid to user function. Created simkl user functions
This commit is contained in:
John O'Keefe 2024-07-30 20:38:55 -04:00
parent 7af14ad7f3
commit d2ef265807
3 changed files with 64 additions and 23 deletions

View File

@ -27,14 +27,27 @@ var aniCtxShutdown, aniCancel = context.WithCancel(context.Background())
func (a *App) CheckIfAniListLoggedIn() bool {
if (AniListJWT{} == aniListJwt) {
return false
tokenType, err := aniRing.Get("anilistTokenType")
expiresIn, err := aniRing.Get("anilistTokenExpiresIn")
accessToken, err := aniRing.Get("anilistAccessToken")
refreshToken, err := aniRing.Get("anilistRefreshToken")
if err != nil {
return false
} else {
aniListJwt.TokenType = string(tokenType.Data)
aniListJwt.AccessToken = string(accessToken.Data)
aniListJwt.RefreshToken = string(refreshToken.Data)
expiresInString := string(expiresIn.Data)
aniListJwt.ExpiresIn, _ = strconv.Atoi(expiresInString)
return true
}
} else {
return true
}
}
func (a *App) AniListLogin() {
if a.CheckIfSimklLoggedIn() == false {
if (AniListJWT{} == aniListJwt) {
tokenType, err := aniRing.Get("anilistTokenType")
expiresIn, err := aniRing.Get("anilistTokenExpiresIn")
accessToken, err := aniRing.Get("anilistAccessToken")
@ -150,7 +163,7 @@ func getAniListAuthorizationToken(content string) AniListJWT {
return post
}
func (a *App) GetAniListLoggedInUserId() AniListUser {
func (a *App) GetAniListLoggedInUser() AniListUser {
a.AniListLogin()
body := struct {
Query string `json:"query"`
@ -160,6 +173,12 @@ func (a *App) GetAniListLoggedInUserId() AniListUser {
Viewer {
id
name
avatar {
large
medium
}
bannerImage
siteUrl
}
}
`,

View File

@ -25,7 +25,17 @@ var simklCtxShutdown, simklCancel = context.WithCancel(context.Background())
func (a *App) CheckIfSimklLoggedIn() bool {
if (SimklJWT{} == simklJwt) {
return false
tokenType, err := simklRing.Get("SimklTokenType")
accessToken, err := simklRing.Get("SimklAccessToken")
scope, err := simklRing.Get("SimklScope")
if err != nil {
return false
} else {
simklJwt.TokenType = string(tokenType.Data)
simklJwt.AccessToken = string(accessToken.Data)
simklJwt.Scope = string(scope.Data)
return true
}
} else {
return true
}
@ -144,28 +154,36 @@ func getSimklAuthorizationToken(content string) SimklJWT {
return post
}
func (a *App) GetSimklLoggedInUserId() SimklUser {
func (a *App) GetSimklLoggedInUser() SimklUser {
a.SimklLogin()
body := struct {
Query string `json:"query"`
}{
Query: `
query {
Viewer {
id
name
}
}
`,
fmt.Println("Token: ", simklJwt.AccessToken)
client := &http.Client{}
req, _ := http.NewRequest("POST", "https://api.simkl.com/users/settings", nil)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer "+simklJwt.AccessToken)
req.Header.Add("simkl-api-key", os.Getenv("SIMKL_CLIENT_ID"))
response, err := client.Do(req)
if err != nil {
log.Printf("Failed at request, %s\n", err)
return SimklUser{}
}
user, _ := SimklQuery(body, true)
defer response.Body.Close()
var post SimklUser
err := json.Unmarshal(user, &post)
var user SimklUser
respBody, _ := io.ReadAll(response.Body)
err = json.Unmarshal(respBody, &user)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
return post
return user
}

View File

@ -8,14 +8,18 @@ export function AniListSearch(arg1:string):Promise<any>;
export function AniListUpdateEntry(arg1:number,arg2:string,arg3:string,arg4:number,arg5:number,arg6:string,arg7:number,arg8:number,arg9:number,arg10:number,arg11:number,arg12:number):Promise<any>;
export function CheckIfAniListLoggedIn():Promise<boolean>;
export function CheckIfSimklLoggedIn():Promise<boolean>;
export function GetAniListItem(arg1:number,arg2:boolean):Promise<main.AniListGetSingleAnime>;
export function GetAniListLoggedInUserId():Promise<main.AniListUser>;
export function GetAniListLoggedInUser():Promise<main.AniListUser>;
export function GetAniListUserWatchingList(arg1:number,arg2:number,arg3:string):Promise<main.AniListCurrentUserWatchList>;
export function GetSimklLoggedInUserId():Promise<main.SimklUser>;
export function GetSimklLoggedInUser():Promise<main.SimklUser>;
export function Greet(arg1:string):Promise<string>;
export function SimklGetUserWatchlist():Promise<main.SimklWatchList>;
export function SimklLogin():Promise<void>;