Skip to content

Commit

Permalink
Merge pull request #327 from WatWowMap/addl-version-checking
Browse files Browse the repository at this point in the history
Additional Version Error Checking
  • Loading branch information
TurtIeSocks authored Jan 22, 2022
2 parents 02eb343 + 1fb2795 commit 0644fc3
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 64 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: Set .gitsha
if: github.event_name == 'push'
run: "echo ${{github.sha}} > .gitsha"
- name: Set .gitref
if: github.event_name == 'push'
run: "echo ${{github.ref}} > .gitref"

- name: Log in to the Container registry
uses: docker/login-action@v1
with:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ server/src/data/masterfile.json

# Docker file
/docker-compose.yml
.gitref
.gitsha

# Favicon
public/favicon/*
Expand Down Expand Up @@ -55,4 +57,4 @@ Desktop.ini
*~

# VS Code
/.vscode/
/.vscode/
Empty file added .gitref
Empty file.
Empty file added .gitsha
Empty file.
6 changes: 3 additions & 3 deletions docker-compose.example.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: '3.1'
services:
reactmap:
image: ghcr.io/watwowmap/reactmap:main #pr-10
image: ghcr.io/watwowmap/reactmap:main
container_name: reactmap
command: sh -c "yarn migrate:latest && yarn start"
command: sh -c "yarn start"
restart: unless-stopped
volumes:
- ./server/src/configs/areas.json:/home/node/server/src/configs/areas.json
- ./server/src/configs/local.json:/home/node/server/src/local/config.json
- ./server/src/configs/local.json:/home/node/server/src/configs/local.json
- ./example.env:/home/node/.env
ports:
- "9090:8080"
20 changes: 15 additions & 5 deletions server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const passport = require('passport')
const rateLimit = require('express-rate-limit')
const i18next = require('i18next')
const Backend = require('i18next-fs-backend')
const { ValidationError } = require('apollo-server-core')
const { ApolloServer } = require('apollo-server-express')
require('./db/initialization')

Expand All @@ -19,7 +20,10 @@ const { sessionStore } = require('./services/sessionStore')
const rootRouter = require('./routes/rootRouter')
const typeDefs = require('./graphql/typeDefs')
const resolvers = require('./graphql/resolvers')
require('./services/checkForUpdates')

if (!config.devOptions.skipUpdateCheck) {
require('./services/checkForUpdates')
}

const app = express()

Expand All @@ -30,9 +34,15 @@ const server = new ApolloServer({
introspection: config.devOptions.enabled,
debug: config.devOptions.queryDebug,
context: ({ req }) => ({ req }),
formatError: (e) => config.devOptions.enabled
? console.error(e)
: console.error('GraphQL Error: ', e.message, e.path, e.location),
formatError: (e) => {
if (e instanceof ValidationError) {
console.warn('GraphQL Error:', e.message, '\nThis is very likely not a real issue and is caused by a user leaving an old browser session open, there is nothing you can do until they refresh.')
} else {
return config.devOptions.enabled
? console.error(e)
: console.error('GraphQL Error: ', e.message, e.path, e.location)
}
},
})

server.start().then(() => server.applyMiddleware({ app, path: '/graphql' }))
Expand Down Expand Up @@ -140,7 +150,7 @@ app.use((err, req, res, next) => {
})

if (config.api.pvp.reactMapHandlesPvp) {
(async () => Pokemon.initOhbem())()
Pokemon.initOhbem().then(() => console.log('Ohbem initialized'))
}

app.listen(config.port, config.interface, () => {
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/authRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { authentication: { strategies } } = require('../services/config')
// Loads up the base auth routes and any custom ones

strategies.forEach(strategy => {
const method = strategy.type === 'local' ? 'post' : 'get'
const method = strategy.type === 'discord' || strategy.type === 'telegram' ? 'get' : 'post'
if (strategy.enabled) {
router[method](`/${strategy.name}`, passport.authenticate(strategy.name, {
failureRedirect: '/',
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/rootRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ rootRouter.get('/settings', async (req, res) => {
const filtered = config.webhooks.filter(webhook => serverSettings.user.perms.webhooks.includes(webhook.name))
try {
await Promise.all(filtered.map(async webhook => {
if (config.webhookObj[webhook.name].client.valid) {
if (webhook.enabled && config.webhookObj?.[webhook.name]?.client?.valid) {
const { strategy, webhookStrategy, discordId, telegramId } = serverSettings.user
const webhookId = (() => {
switch (strategy) {
Expand Down
68 changes: 44 additions & 24 deletions server/src/services/checkForUpdates.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
/* eslint-disable no-console */
const { exec } = require('child_process')
const fs = require('fs')

const { version: currentVersion } = require('../../../package.json')
const Fetch = require('./Fetch')
try {
exec('git branch --show-current', async (err, stdout) => {
try {
const gitRef = fs.readFileSync('.gitref', 'utf8')

exec('git branch --show-current', async (err, stdout) => {
try {
if (err || typeof stdout !== 'string') {
throw new Error('Unable to get current branch', err.message)
}
const { version } = await Fetch.json(`https://raw.githubusercontent.com/WatWowMap/ReactMap/${stdout.trim()}/package.json`)
if (!gitRef && (err || typeof stdout !== 'string' || !stdout.trim())) {
throw new Error('Unable to get current branch', err)
}
const branch = typeof gitRef === 'string' && gitRef.trim()
? gitRef.split('/')[2].trim()
: stdout.trim()

if (!version) {
throw new Error('Unable to fetch latest version')
}
exec('git rev-parse HEAD', async (err2, stdout2) => {
try {
const gitSha = fs.readFileSync('.gitsha', 'utf8')

const [majorC, minorC, patchC] = currentVersion.split('.').map(x => parseInt(x))
const [majorN, minorN, patchN] = version.split('.').map(x => parseInt(x))
if (!gitSha && (err2 || typeof stdout2 !== 'string' || !stdout2.trim())) {
throw new Error('Unable to get current sha', err)
}
const sha = typeof gitSha === 'string' && gitSha.trim()
? gitSha.trim()
: stdout2.trim()

if (stdout.trim() === 'main') {
console.info('You are on the main branch, there may be additional features available on the "develop" branch. Type "git checkout develop" in the console if you would like the latest features.')
}
if (majorC < majorN
|| (majorC === majorN && minorC < minorN)
|| (majorC === majorN && minorC === minorN && patchC < patchN)) {
console.info(`[${stdout.trim().toUpperCase()}] New version available: ${version} (Current: ${currentVersion})`)
exec(`git ls-remote https://github.com/WatWowMap/ReactMap/ refs/heads/${branch}`, (err3, stdout3) => {
try {
if (err3 || typeof stdout3 !== 'string' || !stdout3?.split('\t')?.[0]) {
throw new Error('Unable to get remote sha', err3)
}
const remoteSha = stdout3.split('\t')[0]

if (remoteSha !== sha) {
console.log('There is a new version available:', remoteSha)
}
} catch (e) {
console.warn('Unable to get remote SHA', e.message, 'Branch:', branch, 'Local SHA:', sha)
}
})
} catch (e) {
console.warn('Unable to get current SHA', e.message, 'Branch:', branch)
}
})
} catch (e) {
console.warn('Unable to get current branch', e.message)
}
} catch (e) {
console.error(e.message)
}
})
})
} catch (e) {
console.log(e.message)
}
4 changes: 2 additions & 2 deletions src/components/layout/dialogs/webhooks/ProfileEditing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Query from '@services/Query'
import Header from '@components/layout/general/Header'
import Footer from '@components/layout/general/Footer'

const profilesObject = (data) => Object.fromEntries(data.map(profile => {
const profilesObject = (data) => data ? Object.fromEntries(data.map(profile => {
const newProfile = { ...profile, active_hours: [] }
const parsed = Array.isArray(profile.active_hours)
? profile.active_hours
Expand All @@ -25,7 +25,7 @@ const profilesObject = (data) => Object.fromEntries(data.map(profile => {
})
}
return [profile.name, newProfile]
}))
})) : {}

export default function ProfileEditing({
webhookData, setWebhookData, selectedWebhook, handleClose, isMobile,
Expand Down
18 changes: 9 additions & 9 deletions src/components/markers/gym.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export default function GymMarker(gym, hasHatched, hasRaid, filters, Icons, user
style={{
width: gymSize,
height: gymSize,
bottom: -1 + gymMod.offsetY,
left: `${gymMod.offsetX * 100}%`,
bottom: 2 + gymMod.offsetY,
left: `${gymMod.offsetX * 50}%`,
transform: 'translateX(-50%)',
}}
/>
Expand All @@ -74,8 +74,8 @@ export default function GymMarker(gym, hasHatched, hasRaid, filters, Icons, user
style={{
width: gymSize / 1.5,
height: 'auto',
bottom: -1 + gymMod.offsetY,
left: `${gymMod.offsetX * 15}%`,
bottom: 2 + gymMod.offsetY,
left: `${gymMod.offsetX * -33}%`,
transform: 'translateX(-50%)',
}}
/>
Expand All @@ -86,8 +86,8 @@ export default function GymMarker(gym, hasHatched, hasRaid, filters, Icons, user
style={{
width: gymSize / 2,
height: 'auto',
bottom: 20 + gymMod.offsetY,
left: `${gymMod.offsetX * 10}%`,
bottom: 23 + gymMod.offsetY,
left: `${gymMod.offsetX * -40}%`,
transform: 'translateX(-50%)',
}}
/>
Expand All @@ -98,8 +98,8 @@ export default function GymMarker(gym, hasHatched, hasRaid, filters, Icons, user
style={{
width: gymSize,
height: 'auto',
bottom: 10 + gymMod.offsetY,
left: `${gymMod.offsetX * 100}%`,
bottom: 13 + gymMod.offsetY,
left: `${gymMod.offsetX * 55}%`,
transform: 'translateX(-50%)',
}}
/>
Expand All @@ -111,7 +111,7 @@ export default function GymMarker(gym, hasHatched, hasRaid, filters, Icons, user
width: raidSize,
height: raidSize,
bottom: gymSize * 0.4 + slotModifier * raidMod.offsetY,
left: `${raidMod.offsetX * 100}%`,
left: `${raidMod.offsetX * 55}%`,
transform: 'translateX(-50%)',
}}
/>
Expand Down
10 changes: 5 additions & 5 deletions src/components/markers/pokestop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export default function stopMarker(pokestop, hasQuest, hasLure, hasInvasion, fil
style={{
width: baseSize,
height: baseSize,
bottom: -1 + pokestopMod.offsetY,
left: `${pokestopMod.offsetX * 100}%`,
bottom: 2 + pokestopMod.offsetY,
left: `${pokestopMod.offsetX * 50}%`,
transform: 'translateX(-50%)',
}}
/>
Expand All @@ -123,7 +123,7 @@ export default function stopMarker(pokestop, hasQuest, hasLure, hasInvasion, fil
style={{
width: baseSize / 2,
height: 'auto',
bottom: 20 + pokestopMod.offsetY,
bottom: 23 + pokestopMod.offsetY,
left: `${pokestopMod.offsetX * 10}%`,
transform: 'translateX(-50%)',
}}
Expand All @@ -139,7 +139,7 @@ export default function stopMarker(pokestop, hasQuest, hasLure, hasInvasion, fil
bottom: (baseSize * 0.6 + (invasionMod.removeQuest ? 10 : totalInvasionSize))
* rewardMod.offsetY
+ (questSizes[i] * i),
left: `${rewardMod.offsetX * 100}%`,
left: `${rewardMod.offsetX * 50}%`,
transform: 'translateX(-50%)',
}}
/>
Expand All @@ -156,7 +156,7 @@ export default function stopMarker(pokestop, hasQuest, hasLure, hasInvasion, fil
height: invasionSizes[i],
bottom: baseSize * 0.5 * invasionMod.offsetY
+ (invasionSizes[i] * i),
left: `${invasionMod.offsetX * 100}%`,
left: `${invasionMod.offsetX * 50}%`,
transform: 'translateX(-50%)',
}}
/>
Expand Down
7 changes: 5 additions & 2 deletions src/components/popups/DevicePoly.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import React, { memo } from 'react'
import { Polyline, Polygon } from 'react-leaflet'

const DevicePoly = ({ device, color }) => {
if (typeof device.route === 'string') {
device.route = JSON.parse(device.route)
}
const arrayRoute = device.route[0].lat ? [device.route] : device.route

return arrayRoute ? (
return arrayRoute && Array.isArray(arrayRoute) ? (
<>
{(device.type === 'circle_pokemon')
? arrayRoute.map((polygon, i) => (
Expand All @@ -28,6 +30,7 @@ const DevicePoly = ({ device, color }) => {

const areEqual = (prev, next) => (
prev.device.type === next.device.type
&& prev.color === next.color
)

export default memo(DevicePoly, areEqual)
Loading

0 comments on commit 0644fc3

Please sign in to comment.