-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This aligns with the map layer from the main website.
- Loading branch information
Showing
6 changed files
with
11,471 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// copied from https://github.com/digital-land/digital-land.info/blob/main/assets/javascripts/osApiToken.js | ||
|
||
const API_ACCESS_TOKEN_URL = '/api/os/get-access-token' | ||
let apiToken = { | ||
access_token: '', | ||
expires_in: 0, | ||
issued_at: 0 | ||
} | ||
|
||
let makingRequest = false | ||
|
||
export const getApiToken = () => { | ||
const tokenCheckBuffer = 30 * 1000 | ||
const tokenExpires = parseInt(apiToken.expires_in) * 1000 + parseInt(apiToken.issued_at) | ||
if (Date.now() > tokenExpires - tokenCheckBuffer && !makingRequest) { | ||
getFreshApiToken() | ||
} | ||
return apiToken.access_token | ||
} | ||
|
||
export const getFreshApiToken = () => { | ||
return new Promise((resolve, reject) => { | ||
makingRequest = true | ||
fetch(API_ACCESS_TOKEN_URL) | ||
.then(res => res.json()) | ||
Check failure on line 25 in src/assets/js/os-api-token.js GitHub Actions / run-tests / testUnhandled error
Check failure on line 25 in src/assets/js/os-api-token.js GitHub Actions / testUnhandled error
|
||
.then(res => { | ||
apiToken = res | ||
makingRequest = false | ||
resolve(apiToken.access_token) | ||
} | ||
) | ||
}) | ||
} |
Oops, something went wrong.