diff --git a/README.md b/README.md index 74104ac..6f40021 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ Site pour pouvoir vérifier si un artiste présent sur Spotify possède un compte bandcamp. + +Pour configurer le fichier `config.go`: +* ClientID: l’id de votre application +* RedirectURI: lien de redirection après l’authentification diff --git a/config.go.example b/config.go.example index e1867e4..78982ab 100644 --- a/config.go.example +++ b/config.go.example @@ -1,3 +1,5 @@ package main -var SpotifyAPI = "test" +var SpotifyAPI = "" +var ClientID = "" +var RedirectURI = "" diff --git a/server.go b/server.go index 27da230..d5b4699 100644 --- a/server.go +++ b/server.go @@ -15,6 +15,17 @@ import ( var MyClient = &http.Client{} var MyResp = &RespBandcamp{} +func loginSpotify(w http.ResponseWriter, r *http.Request) { + if err := r.ParseForm(); err != nil { + fmt.Fprintf(w, "ParseForm() err: %v", err) + return + } + + w.Header().Set("Location", "https://accounts.spotify.com/authorize?client_id="+ClientID+"&response_type=token&redirect_uri="+RedirectURI) + w.WriteHeader(http.StatusSeeOther) + go getListPlaylist(r.FormValue("id")) +} + /* check artist and album items[x].track.album.name et items[x].track.album.artists[0].name @@ -216,12 +227,18 @@ func getNew(w http.ResponseWriter, r *http.Request) { MyResp.Notfound = nil } +func mytest(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, r.RequestURI) +} + func main() { fileServer := http.FileServer(http.Dir("./static")) http.Handle("/", fileServer) http.HandleFunc("/hello", hello) http.HandleFunc("/back", formHandler) http.HandleFunc("/refresh", getNew) + http.HandleFunc("/spotify", loginSpotify) + http.HandleFunc("/mytest", mytest) fmt.Printf("Starting the server…\n") if err := http.ListenAndServe(":8080", nil); err != nil { diff --git a/static/index.html b/static/index.html index fa26cc9..0737c0f 100644 --- a/static/index.html +++ b/static/index.html @@ -8,6 +8,8 @@
Recherche dans une playlist les artistes se trouvant aussi sur Bandcamp !