diff options
author | 0neGal <mail@0negal.com> | 2024-01-24 12:03:25 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2024-01-24 12:03:25 +0100 |
commit | 5b3e218d446ac805685e43c8c95ca524755b6601 (patch) | |
tree | df90ee0ebbb2f96582b1817f35535d87eb35b70b /src/app/js/browser.js | |
parent | e61e640dafdaf5472dee487cc9141f5ae70f0a2e (diff) | |
download | Viper-5b3e218d446ac805685e43c8c95ca524755b6601.tar.gz Viper-5b3e218d446ac805685e43c8c95ca524755b6601.zip |
entirely refactor src/modules/requests.js
Its now been split into 2, requests.js and releases.js, the latter
simply gets relevant info from GitHub release pages. The prior however
gives simple functions for doing `GET` requests, and caching the result,
and then transparently it'll use that cache when you request it next
time. On top of this, some requests made by the renderer will now also
use this, and this in turn ends up making loading the mod browser much
faster. As instead of having to request the list of packages from
Thunderstore, we can simply load the result of an old request.
The current lifetime of the cache is 5 minutes, however this can also
easily be adjusted.
This also moves the cached requests away from
<cache_folder>/viper-requests.json, and over to
<cache_folder>/Viper/cached-requests.json
Diffstat (limited to 'src/app/js/browser.js')
-rw-r--r-- | src/app/js/browser.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/app/js/browser.js b/src/app/js/browser.js index c1da9b5..07572d9 100644 --- a/src/app/js/browser.js +++ b/src/app/js/browser.js @@ -166,7 +166,21 @@ var Browser = { packagecount = 0; if (packages.length < 1) { - packages = await (await fetch("https://northstar.thunderstore.io/api/v1/package/")).json(); + let host = "northstar.thunderstore.io"; + let path = "/api/v1/package/"; + + packages = []; + + // attempt to get the list of packages from Thunderstore, if + // this has been done recently, it'll simply return a cached + // version of the request + try { + packages = JSON.parse( + await request(host, path, "thunderstore-packages") + ) + }catch(err) { + console.error(err) + } Browser.add_pkg_properties(); |