update: focus on only few pages (use POST for fetch)

This commit is contained in:
rick 2021-09-10 18:36:21 +02:00
parent 8edd16e6ab
commit 7dbd82c450
Signed by: Rick
GPG key ID: 2B593F087240EE99
4 changed files with 23 additions and 20 deletions

View file

@ -20,11 +20,7 @@ var MyResp = &RespBandcamp{}
var SpotifyAPI = newTokenUser() var SpotifyAPI = newTokenUser()
//var SpotifyAPI = &TokenUser{} //var SpotifyAPI = &TokenUser{}
var Session = session.New() var Session = session.New()
var Errors string
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)
}
/* /*
check artist and album check artist and album
@ -160,10 +156,6 @@ func formHandler (c *fiber.Ctx) error {
return c.SendStatus(303) return c.SendStatus(303)
} }
func hello(c *fiber.Ctx) error {
return c.SendString("Helo!")
}
func getNew(c *fiber.Ctx) error { func getNew(c *fiber.Ctx) error {
c.JSON(MyResp) c.JSON(MyResp)
MyResp.Albums = nil MyResp.Albums = nil
@ -173,8 +165,11 @@ func getNew(c *fiber.Ctx) error {
} }
func mytoken(c *fiber.Ctx) error { func mytoken(c *fiber.Ctx) error {
//if c.Query("error") err := c.BodyParser(&SpotifyAPI)
return c.BodyParser(&SpotifyAPI) if err != nil {
Errors = err.Error()
}
return c.SendStatus(201)
} }
func spotifyCallback(c *fiber.Ctx) error { func spotifyCallback(c *fiber.Ctx) error {
@ -186,7 +181,16 @@ func spotifyCallback(c *fiber.Ctx) error {
} }
func index(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() { func main() {
@ -195,12 +199,11 @@ func main() {
app.Static("/", "./static") app.Static("/", "./static")
app.Get("/", index) app.Get("/", index)
app.Get("/hello", hello) app.Post("/", mytoken)
app.Get("/refresh", getNew) app.Post("/feudecamp", getNew)
app.Get("/spotify", loginSpotify)
app.Get("/callback", spotifyCallback)
app.Post("/back", formHandler) app.Post("/back", formHandler)
app.Post("/mytoken", mytoken) app.Get("/callback", spotifyCallback)
//app.Post("/mytoken", mytoken)
app.Listen(":8080") app.Listen(":8080")
} }

View file

@ -5,7 +5,7 @@ for (let elem of hash) {
datas[elem[0]] = elem[1]; datas[elem[0]] = elem[1];
} }
fetch('/mytoken', { fetch('/', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'

View file

@ -29,7 +29,7 @@ async function addCell(id, elem) {
} }
async function refreshArray() { 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) { if (data != null) {
document.getElementById("nb-fait").textContent = data.done; document.getElementById("nb-fait").textContent = data.done;
document.getElementById("nb-total").textContent = data.todo; document.getElementById("nb-total").textContent = data.todo;

View file

@ -27,7 +27,7 @@
</form> </form>
</div> </div>
{{else}} {{else}}
<a href="/spotify">SE CONNECTER À SPOTIFY ICI</a> <a href="{{ .url }}">SE CONNECTER À SPOTIFY ICI</a>
{{end}} {{end}}
<hr /> <hr />