Used a more efficient image resizing library

This commit is contained in:
2024-02-29 10:31:26 -07:00
parent d52eec5241
commit 981ec34e8a
4 changed files with 34 additions and 52 deletions

View File

@ -3,25 +3,37 @@ package lib
import (
"context"
"os"
"sync"
"atri.dad/lib/pubsub"
"github.com/zmb3/spotify"
"golang.org/x/oauth2"
)
var spotifyOAuth2Endpoint = oauth2.Endpoint{
TokenURL: "https://accounts.spotify.com/api/token",
AuthURL: "https://accounts.spotify.com/authorize",
var (
spotifyOAuth2Endpoint = oauth2.Endpoint{
TokenURL: "https://accounts.spotify.com/api/token",
AuthURL: "https://accounts.spotify.com/authorize",
}
config *oauth2.Config
once sync.Once
)
func GetOAuth2Config(clientID string, clientSecret string) *oauth2.Config {
once.Do(func() {
config = &oauth2.Config{
ClientID: clientID,
ClientSecret: clientSecret,
Scopes: []string{spotify.ScopeUserReadCurrentlyPlaying},
Endpoint: spotifyOAuth2Endpoint,
}
})
return config
}
func GetCurrentlyPlayingTrack(clientID string, clientSecret string, refreshToken string) (*spotify.CurrentlyPlaying, error) {
// OAuth2 config
config := &oauth2.Config{
ClientID: clientID,
ClientSecret: clientSecret,
Scopes: []string{spotify.ScopeUserReadCurrentlyPlaying},
Endpoint: spotifyOAuth2Endpoint,
}
config := GetOAuth2Config(clientID, clientSecret)
// Token source
tokenSource := config.TokenSource(context.Background(), &oauth2.Token{RefreshToken: refreshToken})