diff --git a/server.go b/server.go index a98189c..4e876bd 100644 --- a/server.go +++ b/server.go @@ -20,11 +20,7 @@ var MyResp = &RespBandcamp{} var SpotifyAPI = newTokenUser() //var SpotifyAPI = &TokenUser{} var Session = session.New() - -func loginSpotify(c *fiber.Ctx) error { - c.Set("Location", "https://accounts.spotify.com/authorize?client_id="+ClientID+"&response_type=token&redirect_uri="+RedirectURI) - return c.SendStatus(303) -} +var Errors string /* check artist and album @@ -160,10 +156,6 @@ func formHandler (c *fiber.Ctx) error { return c.SendStatus(303) } -func hello(c *fiber.Ctx) error { - return c.SendString("Helo!") -} - func getNew(c *fiber.Ctx) error { c.JSON(MyResp) MyResp.Albums = nil @@ -173,8 +165,11 @@ func getNew(c *fiber.Ctx) error { } func mytoken(c *fiber.Ctx) error { - //if c.Query("error") - return c.BodyParser(&SpotifyAPI) + err := c.BodyParser(&SpotifyAPI) + if err != nil { + Errors = err.Error() + } + return c.SendStatus(201) } func spotifyCallback(c *fiber.Ctx) error { @@ -186,7 +181,16 @@ func spotifyCallback(c *fiber.Ctx) error { } func index(c *fiber.Ctx) error { - return c.Render("index", fiber.Map{"connected": !SpotifyAPI.CheckEmpty(),}) + if Errors == "" { + return c.Render("index", fiber.Map{"connected": !SpotifyAPI.CheckEmpty(), + "url": SpotifyURL}) + } else { + tmp := Errors + Errors = "" + return c.Render("index", fiber.Map{"connected": !SpotifyAPI.CheckEmpty(), + "error": tmp, + "url": SpotifyURL}) + } } func main() { @@ -195,12 +199,11 @@ func main() { app.Static("/", "./static") app.Get("/", index) - app.Get("/hello", hello) - app.Get("/refresh", getNew) - app.Get("/spotify", loginSpotify) - app.Get("/callback", spotifyCallback) + app.Post("/", mytoken) + app.Post("/feudecamp", getNew) app.Post("/back", formHandler) - app.Post("/mytoken", mytoken) + app.Get("/callback", spotifyCallback) + //app.Post("/mytoken", mytoken) app.Listen(":8080") } diff --git a/static/gethash.js b/static/gethash.js index 99e5685..2f1c5f0 100644 --- a/static/gethash.js +++ b/static/gethash.js @@ -5,7 +5,7 @@ for (let elem of hash) { datas[elem[0]] = elem[1]; } -fetch('/mytoken', { +fetch('/', { method: 'POST', headers: { 'Content-Type': 'application/json' diff --git a/static/script.js b/static/script.js index dbe6cad..b56ca76 100644 --- a/static/script.js +++ b/static/script.js @@ -29,7 +29,7 @@ async function addCell(id, elem) { } async function refreshArray() { - const data = await fetch('/refresh').then(response => response.json()); + const data = await fetch('/feudecamp', {method: 'POST'}).then(response => response.json()); if (data != null) { document.getElementById("nb-fait").textContent = data.done; document.getElementById("nb-total").textContent = data.todo; diff --git a/views/index.html b/views/index.html index 3e4c444..7c43436 100644 --- a/views/index.html +++ b/views/index.html @@ -27,7 +27,7 @@ {{else}} - SE CONNECTER À SPOTIFY ICI + SE CONNECTER À SPOTIFY ICI {{end}}