diff options
author | Mark Powers <markppowers0@gmail.com> | 2020-04-13 15:20:01 -0500 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2020-04-13 15:20:01 -0500 |
commit | afc1a847f4e93c9fb0ec718286089d409030c95a (patch) | |
tree | 55e2825d15667cd57156be41d59ea2aa6c1830c3 /src/highscores.js | |
parent | 7e6648902b262484bc0aac824c3784b1ae4b8591 (diff) |
Update documentation and make setScore idempotent
Diffstat (limited to 'src/highscores.js')
-rw-r--r-- | src/highscores.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/highscores.js b/src/highscores.js index e735eee..82db612 100644 --- a/src/highscores.js +++ b/src/highscores.js @@ -1,10 +1,19 @@ function submitScore(game, score, username){ + // Prompt for the username if(username == undefined){ username = prompt("Enter a name to submit score", ""); } + // If the user filled out the prompt, post the score if (!(username == null || username == "")) { - const request = new Request(`/setScore?game=${game}&username=${username}&score=${score}`); - fetch(request); + // Get a uuid to identify this request by (for idempotency) + fetch(new Request(`/uuid`)) + .then(response => response.text() + .then(uuid => { + const request = new Request(`/setScore?game=${game}&username=${username}&score=${score}&uuid=${uuid}`); + fetch(request); + })); + } + // Return the username for later use by the game return username }
\ No newline at end of file |