diff --git a/server/scripts/createLocales.js b/server/scripts/createLocales.js index bdce8cd2f..88768e077 100644 --- a/server/scripts/createLocales.js +++ b/server/scripts/createLocales.js @@ -1,6 +1,7 @@ /* eslint-disable no-console */ const fs = require('fs') const path = require('path') +const { api } = require('../src/services/config') const fetchJson = require('../src/services/api/fetchJson') @@ -9,6 +10,8 @@ const finalLocalesFolder = path.resolve(__dirname, '../../public/locales') const missingFolder = path.resolve(__dirname, '../../public/missing-locales') const locales = async () => { + if (!api.pogoApiEndpoints.translations) + console.error('[LOCALES] No translations endpoint') const localTranslations = await fs.promises.readdir(appLocalesFolder) const englishRef = fs.readFileSync( path.resolve(appLocalesFolder, 'en.json'), @@ -22,7 +25,7 @@ const locales = async () => { ) const availableRemote = await fetchJson( - 'https://raw.githubusercontent.com/WatWowMap/pogo-translations/master/index.json', + `${api.pogoApiEndpoints.translations}/index.json`, ) await Promise.all( @@ -41,7 +44,7 @@ const locales = async () => { try { const hasRemote = availableRemote.includes(locale) const remoteFiles = await fetchJson( - `https://raw.githubusercontent.com/WatWowMap/pogo-translations/master/static/locales/${ + `${api.pogoApiEndpoints.translations}/static/locales/${ hasRemote ? baseName : 'en' }.json`, ) diff --git a/server/scripts/generateMasterfile.js b/server/scripts/generateMasterfile.js index 90089e245..9e86819b4 100644 --- a/server/scripts/generateMasterfile.js +++ b/server/scripts/generateMasterfile.js @@ -1,6 +1,6 @@ const fs = require('fs') const { resolve } = require('path') -const { rarity: customRarity } = require('../src/services/config') +const { rarity: customRarity, api } = require('../src/services/config') const fetchJson = require('../src/services/api/fetchJson') const defaultRarity = require('../src/data/defaultRarity.json') @@ -19,9 +19,10 @@ const generate = async ( dbRarity = new Map(), ) => { try { - const masterfile = await fetchJson( - 'https://raw.githubusercontent.com/WatWowMap/Masterfile-Generator/master/master-latest-react-map.json', - ) + if (!api.pogoApiEndpoints.masterfile) + throw new Error('No masterfile endpoint') + + const masterfile = await fetchJson(api.pogoApiEndpoints.masterfile) const newMf = { ...masterfile, diff --git a/server/src/configs/custom-environment-variables.json b/server/src/configs/custom-environment-variables.json index 157c8b357..73b3ce828 100644 --- a/server/src/configs/custom-environment-variables.json +++ b/server/src/configs/custom-environment-variables.json @@ -217,6 +217,11 @@ "fetchTimeoutMs": { "__name": "API_FETCH_TIMEOUT_MS", "__format": "number" + }, + "pogoApiEndpoints": { + "invasions": "API_POGO_API_ENDPOINTS_INVASIONS", + "masterfile": "API_POGO_API_ENDPOINTS_MASTERFILE", + "translations": "API_POGO_API_ENDPOINTS_TRANSLATIONS" } }, "multiDomains": { diff --git a/server/src/configs/default.json b/server/src/configs/default.json index f92f97cc1..c229fa347 100644 --- a/server/src/configs/default.json +++ b/server/src/configs/default.json @@ -82,7 +82,12 @@ "hideOldGyms": false, "stopValidDataLimit": 30, "hideOldPokestops": false, - "fetchTimeoutMs": 3000 + "fetchTimeoutMs": 3000, + "pogoApiEndpoints": { + "invasions": "https://raw.githubusercontent.com/ccev/pogoinfo/v2/active/grunts.json", + "masterfile": "https://raw.githubusercontent.com/WatWowMap/Masterfile-Generator/master/master-latest-react-map.json", + "translations": "https://raw.githubusercontent.com/WatWowMap/pogo-translations/master" + } }, "multiDomains": [], "map": { diff --git a/server/src/index.js b/server/src/index.js index f6d9850b5..c42a986e6 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -205,7 +205,7 @@ Db.determineType().then(async () => { await Promise.all([ Event.getUicons(config.icons.styles), Event.getMasterfile(Db.historical, Db.rarity), - Event.getInvasions(), + Event.getInvasions(config.api.pogoApiEndpoints.invasions), Event.getWebhooks(config), ]).then(() => { Event.addAvailable() diff --git a/server/src/services/EventManager.js b/server/src/services/EventManager.js index 56bbe4be3..125ac31bb 100644 --- a/server/src/services/EventManager.js +++ b/server/src/services/EventManager.js @@ -50,15 +50,19 @@ module.exports = class EventManager { setInterval(async () => { await this.getUicons(config.icons.styles) }, 1000 * 60 * 60 * (config.icons.cacheHrs || 3)) - setInterval(async () => { - await this.getInvasions() - }, 1000 * 60 * 60 * (config.map.invasionCacheHrs || 1)) + if (config.api.pogoApiEndpoints.invasions) { + setInterval(async () => { + await this.getInvasions(config.api.pogoApiEndpoints.invasions) + }, 1000 * 60 * 60 * (config.map.invasionCacheHrs || 1)) + } setInterval(async () => { await Db.historicalRarity() }, 1000 * 60 * 60 * (config.api.queryUpdateHours.historicalRarity || 6)) - setInterval(async () => { - await this.getMasterfile(Db.historical, Db.rarity) - }, 1000 * 60 * 60 * (config.map.masterfileCacheHrs || 6)) + if (config.api.pogoApiEndpoints.masterfile) { + setInterval(async () => { + await this.getMasterfile(Db.historical, Db.rarity) + }, 1000 * 60 * 60 * (config.map.masterfileCacheHrs || 6)) + } if (Pvp) { setInterval(async () => { console.log('[EVENT] Fetching Latest PVP Masterfile') @@ -120,40 +124,40 @@ module.exports = class EventManager { this.uicons = this.uicons.filter(Boolean) } - async getInvasions() { - console.log('[EVENT] Fetching Latest Invasions') - try { - this.invasions = await fetchJson( - 'https://raw.githubusercontent.com/ccev/pogoinfo/v2/active/grunts.json', - ).then((response) => - response - ? Object.fromEntries( - Object.entries(this.invasions).map(([type, info]) => { - const latest = response[type] - const newInvasion = this.invasions[type] - if (info.encounters) { - Object.keys(info.encounters).forEach((position, i) => { - if (latest?.active) { - newInvasion.encounters[position] = latest.lineup.team[ - i - ].map((pkmn, j) => - pkmn.template === 'UNSET' && - info.encounters[position][j] - ? info.encounters[position][j] - : { id: pkmn.id, form: pkmn.form }, - ) - newInvasion.second_reward = - latest.lineup.rewards.length > 1 - } - }) - } - return [type, newInvasion] - }), - ) - : this.invasions, - ) - } catch (e) { - console.warn('[WARN] Unable to generate latest invasions:\n', e.message) + async getInvasions(endpoint) { + if (endpoint) { + console.log('[EVENT] Fetching Latest Invasions') + try { + this.invasions = await fetchJson(endpoint).then((response) => + response + ? Object.fromEntries( + Object.entries(this.invasions).map(([type, info]) => { + const latest = response[type] + const newInvasion = this.invasions[type] + if (info.encounters) { + Object.keys(info.encounters).forEach((position, i) => { + if (latest?.active) { + newInvasion.encounters[position] = latest.lineup.team[ + i + ].map((pkmn, j) => + pkmn.template === 'UNSET' && + info.encounters[position][j] + ? info.encounters[position][j] + : { id: pkmn.id, form: pkmn.form }, + ) + newInvasion.second_reward = + latest.lineup.rewards.length > 1 + } + }) + } + return [type, newInvasion] + }), + ) + : this.invasions, + ) + } catch (e) { + console.warn('[WARN] Unable to generate latest invasions:\n', e.message) + } } } diff --git a/server/src/services/config.js b/server/src/services/config.js index 077f51351..c230767cd 100644 --- a/server/src/services/config.js +++ b/server/src/services/config.js @@ -53,7 +53,7 @@ if (!fs.existsSync(resolve(`${__dirname}/../configs/local.json`))) { ], }) } else { - throw new Error( + console.error( 'Missing scanner database config! \nCheck to make sure you have SCANNER_DB_HOST,SCANNER_DB_PORT, SCANNER_DB_NAME, SCANNER_DB_USERNAME, and SCANNER_DB_PASSWORD', ) } @@ -73,7 +73,7 @@ if (!fs.existsSync(resolve(`${__dirname}/../configs/local.json`))) { useFor: ['session', 'user', 'nest', 'portal'], }) } else { - throw new Error( + console.error( 'Missing manual database config! \nCheck to make sure you have MANUAL_DB_HOST,MANUAL_DB_PORT, MANUAL_DB_NAME, MANUAL_DB_USERNAME, and MANUAL_DB_PASSWORD', ) }