Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions server/scripts/createLocales.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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'),
Expand All @@ -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(
Expand 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`,
)
Expand Down
9 changes: 5 additions & 4 deletions server/scripts/generateMasterfile.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions server/src/configs/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 6 additions & 1 deletion server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
84 changes: 44 additions & 40 deletions server/src/services/EventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)
}
Expand All @@ -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',
)
}
Expand Down