Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Dev & Main #510

Merged
merged 27 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f6e7a6a
Configurable Polling
TurtIeSocks May 18, 2022
ca14633
Synced docker env vars with latest config
TurtIeSocks May 18, 2022
cfd19aa
Fixed despawn time verificated checkmark for mad spawns
Ninjasoturi May 18, 2022
3d61dea
Merge pull request #497 from Ninjasoturi/mad_spawn_verified_fix
TurtIeSocks May 18, 2022
a02e635
available api
TurtIeSocks May 18, 2022
3161596
Merge pull request #496 from WatWowMap/configurable-polling
TurtIeSocks May 19, 2022
ac8e51e
Update available.js
TurtIeSocks May 19, 2022
f6554a1
Merge pull request #498 from WatWowMap/available-api
TurtIeSocks May 20, 2022
98237a1
Cleanup gym filtering logic
TurtIeSocks May 20, 2022
da0e16d
Update Gym.js
TurtIeSocks May 22, 2022
ab8188e
Added user id to array of chat id's to check in TG auth
Ninjasoturi May 22, 2022
ca30e30
Merge pull request #500 from Ninjasoturi/tg_auth_allow_userid
TurtIeSocks May 23, 2022
9ea97e3
Add Ultra Beast Support
TurtIeSocks May 27, 2022
7f6c992
Merge pull request #502 from WatWowMap/ultra-beast
TurtIeSocks May 27, 2022
d99d238
Improved areas.example.json
Ninjasoturi May 27, 2022
f81b1e3
Merge pull request #503 from Ninjasoturi/improved_areas_example
TurtIeSocks May 27, 2022
254c96a
Add nginx image example
TurtIeSocks May 28, 2022
1155353
Edited poracleToGeoJSON.js to check for coordinate format
Ninjasoturi May 29, 2022
94a5fa5
Fix Scanner Perms
TurtIeSocks May 29, 2022
a1435e9
Add no minified option to .env
TurtIeSocks May 29, 2022
63ac3bd
Merge pull request #504 from Ninjasoturi/poracleToGeoJSON_improvement
TurtIeSocks May 31, 2022
cf093cd
quest form fallback when null
TurtIeSocks Jun 2, 2022
d81baed
Bump protobufjs from 6.11.2 to 6.11.3
dependabot[bot] Jun 2, 2022
14e6a99
Merge pull request #507 from WatWowMap/dependabot/npm_and_yarn/protob…
TurtIeSocks Jun 3, 2022
4a34af4
Update fetchJson.js
TurtIeSocks Jun 6, 2022
47e6ccb
Version bump
TurtIeSocks Jun 7, 2022
132605b
Update workflows
TurtIeSocks Jun 7, 2022
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
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: Synced docker env vars with latest config
Docker:
if: ${{ always() }}
needs: Sync
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Lint
on: [push, pull_request]
on: [push]

jobs:
Lint:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ server/src/strategies/*
server/src/routes/api/v1/*
!server/src/routes/api/v1/users.js
!server/src/routes/api/v1/sessions.js
!server/src/routes/api/v1/available.js

# custom model
server/src/models/Custom.js
Expand Down
14 changes: 12 additions & 2 deletions docker-compose.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ services:
- ./server/src/configs/local.json:/home/node/server/src/configs/local.json
- ./server/src/configs/geofence.json/:/home/node/server/src/configs/geofence.json
- ./example.env:/home/node/.env
security_opt:
- no-new-privileges:true #https://nodramadevops.com/2019/06/running-docker-application-containers-more-securely/
security_opt:
- no-new-privileges:true #https://nodramadevops.com/2019/06/running-docker-application-containers-more-securely/
ports:
- "9090:8080"
# nginx:
# image: nginx
# container_name: nginx
# depends_on:
# - reactmap
# ports:
# - "80:80"
# - "443:443"
# volumes:
# - ./server/src/configs/nginx.conf:/etc/nginx/conf.d/default.conf
4 changes: 3 additions & 1 deletion esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ const esbuild = {
publicPath: '/',
entryNames: isDevelopment ? undefined : '[name].[hash]',
metafile: true,
minify: isRelease || !isDevelopment,
minify: env.parsed.NO_MINIFIED
? false
: isRelease || !isDevelopment,
logLevel: isDevelopment ? 'info' : 'error',
target: ['safari11.1', 'chrome64', 'firefox66', 'edge88'],
watch: isDevelopment
Expand Down
3 changes: 2 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GOOGLE_ANALYTICS_ID=
GOOGLE_ANALYTICS_ID=""
TITLE="Map"
SENTRY_DSN=""
SENTRY_AUTH_TOKEN=""
Expand All @@ -7,3 +7,4 @@ SENTRY_PROJECT=""
SENTRY_TRACES_SAMPLE_RATE=0.1
SENTRY_DEBUG=
DEV_PORT=""
NO_MINIFIED=""
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactmap",
"version": "1.2.6",
"version": "1.2.7",
"description": "React based frontend map.",
"main": "ReactMap.mjs",
"author": "TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com>",
Expand All @@ -26,8 +26,8 @@
"release": "node server/scripts/newRelease.js"
},
"engines": {
"node": ">=16",
"yarn": "1.22.x"
"node": "^16",
"yarn": "^1.22.x"
},
"devDependencies": {
"@craftamap/esbuild-plugin-html": "^0.4.0",
Expand Down
1 change: 1 addition & 0 deletions public/base-locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
"event": "Event",
"legendary": "Legendary",
"mythical": "Mythical",
"ultra_beast": "Ultra Beast",
"alt_forms": "Alt Forms",
"alola": "Alola",
"galarian": "Galarian",
Expand Down
1 change: 1 addition & 0 deletions server/scripts/generateMasterfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const getRarityLevel = (id, pkmn) => {
}
if (pkmn.legendary) pkmnRarity = 'legendary'
if (pkmn.mythical) pkmnRarity = 'mythical'
if (pkmn.ultraBeast) pkmnRarity = 'ultraBeast'
return pkmnRarity
}

Expand Down
4 changes: 4 additions & 0 deletions server/scripts/poracleToGeoJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ if (fs.existsSync(geofencesFile)) {
const coord = inGeofence.path[j]
inGeofence.path[j] = [coord[1], coord[0]]
}
const lastCoords = inGeofence.path.slice(-1)
if (inGeofence.path[0][0] !== lastCoords[0][0] || inGeofence.path[0][1] !== lastCoords[0][1]) {
inGeofence.path.push(inGeofence.path[0])
}
outGeofence.geometry.coordinates[0] = inGeofence.path
outGeoJSON.features.push(outGeofence)
}
Expand Down
16 changes: 14 additions & 2 deletions server/src/configs/areas.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@
"coordinates": [
[
[
-100,
4
lon1,
lat1
],
[
lon2,
lat2
],
[
lon3,
lat3
],
[
lon1,
lat1
]
]
]
Expand Down
42 changes: 42 additions & 0 deletions server/src/configs/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,48 @@
"__format": "number"
}
},
"polling": {
"devices": {
"__name": "API_POLLING_DEVICES",
"__format": "number"
},
"gyms": {
"__name": "API_POLLING_GYMS",
"__format": "number"
},
"nests": {
"__name": "API_POLLING_NESTS",
"__format": "number"
},
"pokemon": {
"__name": "API_POLLING_POKEMON",
"__format": "number"
},
"pokestops": {
"__name": "API_POLLING_POKESTOPS",
"__format": "number"
},
"portals": {
"__name": "API_POLLING_PORTALS",
"__format": "number"
},
"scanAreas": {
"__name": "API_POLLING_SCAN_AREAS",
"__format": "number"
},
"scanCells": {
"__name": "API_POLLING_SCAN_CELLS",
"__format": "number"
},
"submissionCells": {
"__name": "API_POLLING_SUBMISSION_CELLS",
"__format": "number"
},
"weather": {
"__name": "API_POLLING_WEATHER",
"__format": "number"
}
},
"queryUpdateHours": {
"pokemon": {
"__name": "API_QUERY_UPDATE_HOURS_POKEMON",
Expand Down
12 changes: 12 additions & 0 deletions server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
"time": 60,
"requests": 1000
},
"polling": {
"devices": 10,
"gyms": 10,
"nests": 300,
"pokemon": 20,
"pokestops": 300,
"portals": 300,
"scanAreas": 10000,
"scanCells": 10,
"submissionCells": 500,
"weather": 30
},
"queryUpdateHours": {
"pokemon": 0.5,
"quests": 1,
Expand Down
8 changes: 5 additions & 3 deletions server/src/models/Gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ module.exports = class Gym extends Model {
raidFields.forEach(field => newGym[field] = gym[field])
newGym.hasRaid = true
}
if (newGym.hasRaid || newGym.badge
|| finalTeams.includes(gym.team_id)
|| finalSlots[gym.team_id]?.includes(gym.available_slots)) {
if ((onlyAllGyms || onlyExEligible || onlyArEligible || onlyInBattle) && (finalTeams.includes(gym.team_id)
|| finalSlots[gym.team_id]?.includes(gym.available_slots))) {
newGym.hasGym = true
}
if (newGym.hasRaid || newGym.badge || newGym.hasGym) {
filteredResults.push(newGym)
}
})
Expand Down
2 changes: 1 addition & 1 deletion server/src/models/Pokemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getMadSql = q => (
'pokemon_display.pokemon AS display_pokemon_id',
'pokemon_display.form AS ditto_form',
'weather_boosted_condition AS weather',
raw('IF(calc_endminsec, 1, NULL)')
raw('IF(calc_endminsec IS NOT NULL, 1, NULL)')
.as('expire_timestamp_verified'),
raw('Unix_timestamp(disappear_time)')
.as('expire_timestamp'),
Expand Down
3 changes: 2 additions & 1 deletion server/src/models/Pokestop.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ module.exports = class Pokestop extends Model {
newQuest.key = `c${quest.candy_pokemon_id}`
fields.push('candy_pokemon_id', 'candy_amount'); break
case 7:
quest.quest_form_id = quest.quest_form_id ?? 0
newQuest.key = `${quest.quest_pokemon_id}-${quest.quest_form_id}`
fields.push('quest_pokemon_id', 'quest_form_id', 'quest_costume_id', 'quest_gender_id', 'quest_shiny'); break
case 9:
Expand Down Expand Up @@ -606,7 +607,7 @@ module.exports = class Pokestop extends Model {
case 'stardust': rewards.forEach(reward => finalList.add(`d${reward.amount}`)); break
case 'candy': rewards.forEach(reward => finalList.add(`c${reward.id}`)); break
case 'xlCandy': rewards.forEach(reward => finalList.add(`x${reward.id}`)); break
default: rewards.forEach(reward => finalList.add(`${reward.quest_pokemon_id}-${reward.form}`)); break
default: rewards.forEach(reward => finalList.add(`${reward.quest_pokemon_id}-${reward.form ?? 0}`)); break
}
})

Expand Down
117 changes: 117 additions & 0 deletions server/src/routes/api/v1/available.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* eslint-disable no-console */
const path = require('path')
const router = require('express').Router()
const { api } = require('../../../services/config')
const { Db, Event } = require('../../../services/initialization')

const queryObj = {
pokemon: { model: 'Pokemon', category: 'pokemon' },
quests: { model: 'Pokestop', category: 'pokestops' },
raids: { model: 'Gym', category: 'gyms' },
nests: { model: 'Nest', category: 'nests' },
}

const resolveCategory = (category) => {
switch (category) {
case 'gym':
case 'gyms':
case 'raid':
case 'raids': return 'raids'
case 'pokestop':
case 'pokestops':
case 'quest':
case 'quests': return 'quests'
case 'pokemon':
case 'pokemons': return 'pokemon'
default: return 'all'
}
}

const getAll = async (compare) => {
const available = compare
? await Promise.all([
Db.getAvailable('Pokemon'),
Db.getAvailable('Pokestop'),
Db.getAvailable('Gym'),
Db.getAvailable('Nest'),
])
: [
Event.available.pokemon,
Event.available.pokestops,
Event.available.gyms,
Event.available.nests,
]
return Object.fromEntries(Object.keys(queryObj).map((key, i) => [key, available[i]]))
}

router.get(['/', '/:category'], async (req, res) => {
const { model, category } = queryObj[resolveCategory(req.params.category)] || {}
const { current, equal } = req.query
try {
if (api.reactMapSecret && req.headers['react-map-secret'] === api.reactMapSecret) {
if (model && category) {
const available = current !== undefined
? await Db.getAvailable(model)
: Event.available[category]
available.sort((a, b) => a.localeCompare(b))

if (equal !== undefined) {
const compare = current !== undefined
? Event.available[category]
: await Db.getAvailable(model)
compare.sort((a, b) => a.localeCompare(b))
res.status(200).json(available.every((item, i) => item === compare[i]))
} else {
res.status(200).json(available)
}
} else {
const available = await getAll(current)
Object.values(available).forEach(c => c.sort((a, b) => a.localeCompare(b)))

if (equal !== undefined) {
const compare = await getAll(!current)
Object.values(compare).forEach(c => c.sort((a, b) => a.localeCompare(b)))

res.status(200).json(Object.keys(available).every(cat => (
available[cat].every((item, j) => item === compare[cat][j])
)))
} else {
res.status(200).json(available)
}
}
} else {
throw new Error('Incorrect or missing API secret')
}
console.log(`[API] api/v1/${path.parse(__filename).name}`)
} catch (e) {
console.error(`[API Error] api/v1/${path.parse(__filename).name}`, e)
res.status(500).json({ status: 'ServerError', reason: e.message })
}
})

router.put('/:category', async (req, res) => {
const { model, category } = queryObj[resolveCategory(req.params.category)] || {}
try {
if (api.reactMapSecret && req.headers['react-map-secret'] === api.reactMapSecret) {
if (model && category) {
await Event.setAvailable(category, model, Db)
} else {
await Promise.all([
Event.setAvailable('pokemon', 'Pokemon', Db),
Event.setAvailable('pokestops', 'Pokestop', Db),
Event.setAvailable('gyms', 'Gym', Db),
Event.setAvailable('nests', 'Nest', Db),
])
}
res.status(200).json({ status: `updated availabled for ${category || 'all'}` })
} else {
throw new Error('Incorrect or missing API secret')
}
console.log(`[API] api/v1/${path.parse(__filename).name} - updated availabled for ${category || 'all'}`)
} catch (e) {
console.error(`[API] api/v1/${path.parse(__filename).name}`, e)
res.status(500).json({ status: 'ServerError', reason: e.message })
}
})

module.exports = router
3 changes: 2 additions & 1 deletion server/src/routes/rootRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ rootRouter.get('/settings', async (req, res) => {
req.session.perms = {
areaRestrictions: Utility.areaPerms(['none']),
webhooks: [],
scanner: [],
scanner: Object.keys(config.scanner).filter((key) => key !== 'backendConfig' && config.scanner[key].enabled && !config.scanner[key].discordRoles.length && !config.scanner[key].telegramGroups.length),
}
config.authentication.alwaysEnabledPerms.forEach(perm => {
if (config.authentication.perms[perm]) {
Expand Down Expand Up @@ -112,6 +112,7 @@ rootRouter.get('/settings', async (req, res) => {
...config.map,
...config.multiDomainsObj[req.headers.host],
excludeList: config.authentication.excludeFromTutorial,
polling: config.api.polling,
},
localeSelection: Object.fromEntries(config.map.localeSelection.map(l => [l, { name: l }])),
tileServers: Object.fromEntries(config.tileServers.map(s => [s.name, s])),
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/api/fetchJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = async function fetchJson(url, options = undefined, log = false)
console.log('Request to', url, 'timed out and was aborted')
} else if (log) {
console.warn(e)
} else {
} else if (e instanceof Error) {
console.warn(e.message, '\n', e.code, `\nUnable to fetch ${url}`)
}
return null
Expand Down
Loading