added MAL Login

This commit is contained in:
2024-08-13 18:54:27 -04:00
parent 43a054ac92
commit fa3304db92
14 changed files with 459 additions and 22 deletions

View File

@ -31,14 +31,13 @@ func (a *App) CheckIfAniListLoggedIn() bool {
expiresIn, err := aniRing.Get("anilistTokenExpiresIn")
accessToken, err := aniRing.Get("anilistAccessToken")
refreshToken, err := aniRing.Get("anilistRefreshToken")
if err != nil {
if err != nil || len(accessToken.Data) == 0 {
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)
aniListJwt.ExpiresIn, _ = strconv.Atoi(string(expiresIn.Data))
return true
}
} else {
@ -52,7 +51,7 @@ func (a *App) AniListLogin() {
expiresIn, err := aniRing.Get("anilistTokenExpiresIn")
accessToken, err := aniRing.Get("anilistAccessToken")
refreshToken, err := aniRing.Get("anilistRefreshToken")
if err != nil {
if err != nil || len(accessToken.Data) == 0 {
getAniListCodeUrl := "https://anilist.co/api/v2/oauth/authorize?client_id=" + os.Getenv("ANILIST_APP_ID") + "&redirect_uri=" + os.Getenv("ANILIST_CALLBACK_URI") + "&response_type=code"
runtime.BrowserOpenURL(a.ctx, getAniListCodeUrl)
@ -64,8 +63,7 @@ func (a *App) AniListLogin() {
aniListJwt.TokenType = string(tokenType.Data)
aniListJwt.AccessToken = string(accessToken.Data)
aniListJwt.RefreshToken = string(refreshToken.Data)
expiresInString := string(expiresIn.Data)
aniListJwt.ExpiresIn, _ = strconv.Atoi(expiresInString)
aniListJwt.ExpiresIn, _ = strconv.Atoi(string(expiresIn.Data))
}
}
}
@ -89,7 +87,7 @@ func handleAniListCallback(wg *sync.WaitGroup) {
})
_ = aniRing.Set(keyring.Item{
Key: "anilistTokenExpiresIn",
Data: []byte(string(aniListJwt.ExpiresIn)),
Data: []byte(strconv.Itoa(aniListJwt.ExpiresIn)),
})
_ = aniRing.Set(keyring.Item{
Key: "anilistAccessToken",