diff --git a/.gitignore b/.gitignore index 3828ba8..44b7bdb 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ frontend/dist package.json.md5 package-lock.json .idea -.env \ No newline at end of file +.env +environment.go \ No newline at end of file diff --git a/AniListUserFunctions.go b/AniListUserFunctions.go index 71c4129..045923c 100644 --- a/AniListUserFunctions.go +++ b/AniListUserFunctions.go @@ -8,7 +8,6 @@ import ( "log" "net/http" "net/url" - "os" "strconv" "strings" "sync" @@ -52,7 +51,7 @@ func (a *App) AniListLogin() { accessToken, err := aniRing.Get("anilistAccessToken") refreshToken, err := aniRing.Get("anilistRefreshToken") 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" + getAniListCodeUrl := "https://anilist.co/api/v2/oauth/authorize?client_id=" + Environment.ANILIST_APP_ID + "&redirect_uri=" + Environment.ANILIST_CALLBACK_URI + "&response_type=code" runtime.BrowserOpenURL(a.ctx, getAniListCodeUrl) serverDone := &sync.WaitGroup{} @@ -133,9 +132,9 @@ func getAniListAuthorizationToken(content string) AniListJWT { resource := "/api/v2/oauth/token" data := url.Values{} data.Set("grant_type", "authorization_code") - data.Set("client_id", os.Getenv("ANILIST_APP_ID")) - data.Set("client_secret", os.Getenv("ANILIST_SECRET_TOKEN")) - data.Set("redirect_uri", os.Getenv("ANILIST_CALLBACK_URI")) + data.Set("client_id", Environment.ANILIST_APP_ID) + data.Set("client_secret", Environment.ANILIST_SECRET_TOKEN) + data.Set("redirect_uri", Environment.ANILIST_CALLBACK_URI) data.Set("code", content) u, _ := url.ParseRequestURI(apiUrl) @@ -211,6 +210,7 @@ func (a *App) LogoutAniList() string { if err != nil { fmt.Println("AniList Logout Failed", err) } + aniListJwt = AniListJWT{} } return "AniList Logged Out Successfully" diff --git a/MALUserFunctions.go b/MALUserFunctions.go index 062598a..1efb883 100644 --- a/MALUserFunctions.go +++ b/MALUserFunctions.go @@ -11,7 +11,6 @@ import ( "math/rand" "net/http" "net/url" - "os" "strconv" "strings" "sync" @@ -97,7 +96,7 @@ func (a *App) MyAnimeListLogin() { refreshToken, err := myAnimeListRing.Get("MyAnimeListRefreshToken") if err != nil || len(accessToken.Data) == 0 { verifier, _ := verifier() - getMyAnimeListCodeUrl := "https://myanimelist.net/v1/oauth2/authorize?response_type=code&client_id=" + os.Getenv("MAL_CLIENT_ID") + "&redirect_uri=" + os.Getenv("MAL_CALLBACK_URI") + "&code_challenge=" + verifier.Value + "&code_challenge_method=plain" + getMyAnimeListCodeUrl := "https://myanimelist.net/v1/oauth2/authorize?response_type=code&client_id=" + Environment.MAL_CLIENT_ID + "&redirect_uri=" + Environment.MAL_CALLBACK_URI + "&code_challenge=" + verifier.Value + "&code_challenge_method=plain" runtime.BrowserOpenURL(a.ctx, getMyAnimeListCodeUrl) serverDone := &sync.WaitGroup{} serverDone.Add(1) @@ -185,9 +184,9 @@ func getMyAnimeListAuthorizationToken(content string, verifier *CodeVerifier) My CodeVerifier *CodeVerifier `json:"code_verifier"` }{ GrantType: "authorization_code", - ClientID: os.Getenv("MAL_CLIENT_ID"), - ClientSecret: os.Getenv("MAL_CLIENT_SECRET"), - RedirectURI: os.Getenv("MAL_CALLBACK_URI"), + ClientID: Environment.MAL_CLIENT_ID, + ClientSecret: Environment.MAL_CLIENT_SECRET, + RedirectURI: Environment.MAL_CALLBACK_URI, Code: content, CodeVerifier: verifier, } @@ -234,7 +233,7 @@ func (a *App) GetMyAnimeListLoggedInUser() MyAnimeListUser { req.Header.Add("Content-Type", "application/json") req.Header.Add("Authorization", "Bearer "+myAnimeListJwt.AccessToken) - req.Header.Add("myAnimeList-api-key", os.Getenv("MAL_CLIENT_ID")) + req.Header.Add("myAnimeList-api-key", Environment.MAL_CLIENT_ID) response, err := client.Do(req) @@ -267,6 +266,7 @@ func (a *App) LogoutMyAnimeList() string { if err != nil { fmt.Println("MAL Logout Failed", err) } + myAnimeListJwt = MyAnimeListJWT{} } return "MAL Logged Out Successfully" diff --git a/SimklFunctions.go b/SimklFunctions.go index b43721b..633f38f 100644 --- a/SimklFunctions.go +++ b/SimklFunctions.go @@ -7,7 +7,6 @@ import ( "io" "log" "net/http" - "os" ) func (a *App) SimklGetUserWatchlist() SimklWatchList { @@ -17,7 +16,7 @@ func (a *App) SimklGetUserWatchlist() SimklWatchList { 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")) + req.Header.Add("simkl-api-key", Environment.SIMKL_CLIENT_ID) resp, err := client.Do(req) @@ -48,7 +47,7 @@ func SimklPostHelper(url string, body interface{}) json.RawMessage { 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")) + req.Header.Add("simkl-api-key", Environment.SIMKL_CLIENT_ID) resp, err := client.Do(req) diff --git a/SimklUserFunctions.go b/SimklUserFunctions.go index 7f89143..f551687 100644 --- a/SimklUserFunctions.go +++ b/SimklUserFunctions.go @@ -8,7 +8,6 @@ import ( "io" "log" "net/http" - "os" "sync" "github.com/99designs/keyring" @@ -47,7 +46,7 @@ func (a *App) SimklLogin() { accessToken, err := simklRing.Get("SimklAccessToken") scope, err := simklRing.Get("SimklScope") if err != nil || len(accessToken.Data) == 0 { - getSimklCodeUrl := "https://simkl.com/oauth/authorize?response_type=code&client_id=" + os.Getenv("SIMKL_CLIENT_ID") + "&redirect_uri=" + os.Getenv("SIMKL_CALLBACK_URI") + getSimklCodeUrl := "https://simkl.com/oauth/authorize?response_type=code&client_id=" + Environment.SIMKL_CLIENT_ID + "&redirect_uri=" + Environment.SIMKL_CALLBACK_URI runtime.BrowserOpenURL(a.ctx, getSimklCodeUrl) serverDone := &sync.WaitGroup{} @@ -127,9 +126,9 @@ func getSimklAuthorizationToken(content string) SimklJWT { Code string `json:"code"` }{ GrantType: "authorization_code", - ClientID: os.Getenv("SIMKL_CLIENT_ID"), - ClientSecret: os.Getenv("SIMKL_CLIENT_SECRET"), - RedirectURI: os.Getenv("SIMKL_CALLBACK_URI"), + ClientID: Environment.SIMKL_CLIENT_ID, + ClientSecret: Environment.SIMKL_CLIENT_SECRET, + RedirectURI: Environment.SIMKL_CALLBACK_URI, Code: content, } jsonData, err := json.Marshal(data) @@ -171,7 +170,7 @@ func (a *App) GetSimklLoggedInUser() SimklUser { 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")) + req.Header.Add("simkl-api-key", Environment.SIMKL_CLIENT_ID) response, err := client.Do(req) @@ -203,6 +202,7 @@ func (a *App) LogoutSimkl() string { if err != nil { fmt.Println("Simkl Logout Failed", err) } + simklJwt = SimklJWT{} } return "Simkl Logged Out Successfully" diff --git a/environmentType.go b/environmentType.go new file mode 100644 index 0000000..80a447a --- /dev/null +++ b/environmentType.go @@ -0,0 +1,16 @@ +package main + +type EnvironmentStruct struct { + ANILIST_SECRET_TOKEN string + ANILIST_APP_ID string + ANILIST_APP_NAME string + ANILIST_CALLBACK_URI string + SIMKL_CLIENT_ID string + SIMKL_CLIENT_SECRET string + SIMKL_CALLBACK_URI string + MAL_CLIENT_ID string + MAL_CLIENT_SECRET string + MAL_CALLBACK_URI string +} + +// created a separate environment.go file and add var Environment EnvironmentStruct = {} diff --git a/go.mod b/go.mod index 7c5251c..d253a38 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ toolchain go1.21.11 require ( github.com/99designs/keyring v1.2.2 - github.com/joho/godotenv v1.5.1 github.com/wailsapp/wails/v2 v2.9.1 ) diff --git a/go.sum b/go.sum index dae5f3c..881ff88 100644 --- a/go.sum +++ b/go.sum @@ -23,8 +23,6 @@ github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8 github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck= github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs= -github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= -github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= diff --git a/main.go b/main.go index f31e607..772b1e6 100644 --- a/main.go +++ b/main.go @@ -2,20 +2,11 @@ package main import ( "embed" - "github.com/joho/godotenv" "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" "github.com/wailsapp/wails/v2/pkg/options/assetserver" - "log" ) -func init() { - err := godotenv.Load() - if err != nil { - log.Fatal("Error loading .env file") - } -} - //go:embed all:frontend/dist var assets embed.FS