From 05a6154744e76700c8017fa2902880ecbe991a93 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 23 Aug 2022 23:01:51 +0100 Subject: [PATCH] Replace GitHub.js and tomlify-j0.4 dependencies With the official GitHub JS client and @ltd/j-toml respectively. As part of this, turn the JS files into modules and load the dependencies from inside the modules. --- README.md | 2 +- convert-settings.html | 4 +--- credits.html | 3 +-- js/convert.js | 17 ++++++----------- js/credits.js | 33 ++++++++++++++++++++++++--------- js/search.js | 31 ++++++++++++++++++++++++------- search.html | 4 +--- 7 files changed, 58 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 656c7fb..85cd0e4 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ loot.github.io This repository acts as the main LOOT team repository, and holds all the issues that aren't specific to the code or any one game. In addition to that, it also holds LOOT's static website. -The static website is a [Jekyll](https://jekyllrb.com/) site that uses [Material Design Lite](https://www.getmdl.io/) components and the [js-yaml](https://github.com/nodeca/js-yaml) and [Github.js](https://github.com/michael/github) libraries, which are provided by Google, Cloudflare and unpkg CDNs respectively. +The static website is a [Jekyll](https://jekyllrb.com/) site that uses [Material Design Lite](https://www.getmdl.io/) components and the [js-yaml](https://github.com/nodeca/js-yaml), [Octokit.js](https://github.com/octokit/rest.js) and [j-toml](https://github.com/LongTengDao/j-toml) libraries, which are provided by Google, Cloudflare and Skypack CDNs. The easiest way to build this site locally is using Docker: diff --git a/convert-settings.html b/convert-settings.html index 73c8bf7..dd76300 100644 --- a/convert-settings.html +++ b/convert-settings.html @@ -18,6 +18,4 @@ permalink: /convert-settings/

Note that the download link that appears above after converting YAML does not work in Internet Explorer or Edge. Users of those browsers will need to copy the content of the TOML text box into a settings.toml file they create themselves, or use a different browser.

- - - + diff --git a/credits.html b/credits.html index 18a2af3..cb87d86 100644 --- a/credits.html +++ b/credits.html @@ -9,5 +9,4 @@ permalink: /credits/
- - + diff --git a/js/convert.js b/js/convert.js index 1b05085..4b0f2d8 100644 --- a/js/convert.js +++ b/js/convert.js @@ -1,4 +1,6 @@ 'use strict'; +import { load } from 'https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.mjs'; +import TOML from 'https://cdn.skypack.dev/-/@ltd/j-toml@v1.33.3-g895G5Q2ba82bha6HlB9/dist=es2019,mode=imports/optimized/@ltd/j-toml.js'; function upgradeOldYaml(yaml) { if (yaml['Debug Verbosity'] && !yaml.enableDebugLogging) { @@ -37,20 +39,13 @@ function upgradeOldYaml(yaml) { function yamlToToml(evt) { try { - const settings = upgradeOldYaml(jsyaml.load(evt.target.value)); + const settings = upgradeOldYaml(load(evt.target.value)); const options = { - space: 2, - replace: function(key, value) { - if (typeof value === 'number') { - /* Settings only use integers, no floats. */ - return Math.round(value).toString(); - } - - return false; - } + indent: 2, + newline: '\n' } - const toml = tomlify.toToml(settings, options); + const toml = TOML.stringify(settings, options); document.getElementById('output').value = toml; diff --git a/js/credits.js b/js/credits.js index 2ec398e..f8b6d27 100644 --- a/js/credits.js +++ b/js/credits.js @@ -1,4 +1,6 @@ 'use strict'; +import { Octokit } from "https://cdn.skypack.dev/pin/@octokit/rest@v19.0.4-xPNRCbtf1MpCCpqHe5lx/mode=imports,min/optimized/@octokit/rest.js"; +import { throttling } from "https://cdn.skypack.dev/pin/@octokit/plugin-throttling@v4.2.0-q2ZrzGw3H4mnkheWbYZl/mode=imports,min/optimized/@octokit/plugin-throttling.js"; function addToList(listElement, person) { const a = document.createElement('a'); @@ -45,12 +47,12 @@ function sortContributors(a,b) { } function getStats(contributor) { - const isAnon = contributor.author.type === 'Anonymous'; + const isAnon = contributor.type === 'Anonymous'; return { - contributions: contributor.total, - name: isAnon ? contributor.author.name : contributor.author.login, - avatar_url: isAnon ? undefined : contributor.author.avatar_url, - html_url: isAnon ? 'mailto:' + contributor.author.email : contributor.author.html_url + contributions: contributor.contributions, + name: isAnon ? contributor.name : contributor.login, + avatar_url: isAnon ? undefined : contributor.avatar_url, + html_url: isAnon ? 'mailto:' + contributor.email : contributor.html_url }; } @@ -81,13 +83,26 @@ function getContributorsStats(contributors) { } async function getContributors() { - const github = new GitHub(); + const ThrottledOctokit = Octokit.plugin(throttling); - const reposResponse = await github.getOrganization('loot').getRepos(); + const octokit = new ThrottledOctokit({ + throttle: { + onAbuseLimit: () => true, + onRateLimit: () => true + } + }); - const promises = reposResponse.data + const repos = await octokit.paginate(octokit.rest.repos.listForOrg, { + org: 'loot' + }); + + const promises = repos .filter(repo => !repo.fork) - .map(repo => github.getRepo('loot', repo.name).getContributors()); + .map(repo => octokit.paginate(octokit.rest.repos.listContributors, { + owner: 'loot', + repo: repo.name, + anon: true + })); return Promise.all(promises).then(results => results.flat()); } diff --git a/js/search.js b/js/search.js index abac7ee..52d1233 100644 --- a/js/search.js +++ b/js/search.js @@ -1,4 +1,7 @@ 'use strict'; +import { Octokit } from 'https://cdn.skypack.dev/pin/@octokit/rest@v19.0.4-xPNRCbtf1MpCCpqHe5lx/mode=imports,min/optimized/@octokit/rest.js'; +import { throttling } from 'https://cdn.skypack.dev/pin/@octokit/plugin-throttling@v4.2.0-q2ZrzGw3H4mnkheWbYZl/mode=imports,min/optimized/@octokit/plugin-throttling.js'; +import { dump, load } from 'https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.mjs'; // Globals /////////////////// @@ -76,13 +79,27 @@ function onSearchInit(evt) { console.log("Loading masterlist..."); progress.classList.remove('hidden'); - var repo = (new GitHub()) - .getRepo('loot', gameButton.getAttribute('data-selected')) - .getContents(undefined, 'masterlist.yaml', true) - .then(readMasterlist) - .catch(function() { - document.getElementById('progress').classList.add('hidden'); - }); + const ThrottledOctokit = Octokit.plugin(throttling); + + const octokit = new ThrottledOctokit({ + throttle: { + onAbuseLimit: () => true, + onRateLimit: () => true + } + }); + + octokit.rest.repos.getContent({ + owner: 'loot', + repo: gameButton.getAttribute('data-selected'), + path: 'masterlist.yaml', + mediaType: { + format: 'raw' + } + }) + .then(readMasterlist) + .catch(function() { + document.getElementById('progress').classList.add('hidden'); + }); } function onGameSelect(evt) { diff --git a/search.html b/search.html index c104484..8ed9afa 100644 --- a/search.html +++ b/search.html @@ -24,6 +24,4 @@ permalink: /search/
- - - +