allSites.js 1.3 KB

123456789101112131415161718192021222324252627
  1. var allSites = getAllSites();
  2. function getAllSites() {
  3. return got.get( 'https://help.gamepedia.com/api.php?action=allsites&formatversion=2&do=getSiteStats&filter=wikis|md5_key,wiki_domain,wiki_display_name,wiki_image,wiki_description,wiki_managers,official_wiki,wiki_crossover,created&format=json', {
  4. responseType: 'json'
  5. } ).then( response => {
  6. var body = response.body;
  7. if ( response.statusCode !== 200 || !body || body.status !== 'okay' || !body.data || !body.data.wikis ) {
  8. console.log( '- ' + shardId + ': ' + response.statusCode + ': Error while gettings all sites: ' + ( body && body.error && body.error.info ) );
  9. return [];
  10. }
  11. else {
  12. console.log( '- ' + shardId + ': Sites successfully loaded.' );
  13. var sites = JSON.parse(JSON.stringify(body.data.wikis.filter( site => /^[a-z\d-]{1,50}\.gamepedia\.com$/.test(site.wiki_domain) )));
  14. sites.filter( site => site.wiki_crossover ).forEach( site => site.wiki_crossover = site.wiki_crossover.replace( /^(?:https?:)?\/\/(([a-z\d-]{1,50})\.(?:fandom\.com|wikia\.org)(?:(?!\/wiki\/)\/([a-z-]{1,8}))?).*/, '$1' ) );
  15. return sites;
  16. }
  17. }, error => {
  18. console.log( '- ' + shardId + ': Error while gettings all sites: ' + error );
  19. return [];
  20. } );
  21. }
  22. module.exports = {
  23. get: getAllSites,
  24. then: (callback) => allSites.then(callback)
  25. };