Skip to content

Commit

Permalink
fastify fix and package update (KartulUdus#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReuschelCGN authored Jan 10, 2024
1 parent 5332022 commit 7eeb5cb
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-alpine
FROM node:20-alpine

WORKDIR /usr/src/app
ADD . ./
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "poracle",
"version": "4.7.0",
"version": "4.8.0",
"description": "Webhook processing and personalised discord|telegram alarms",
"keywords": [
"poracle",
Expand Down Expand Up @@ -36,20 +36,20 @@
"async-mutex": "^0.4.0",
"axios": "^1.4.0",
"chokidar": "^3.5.3",
"config": "^3.3.9",
"config": "^3.3.10",
"country-code-emoji": "^2.3.0",
"deep-object-diff": "^1.1.9",
"discord.js": "^13.16.0",
"fast-json-stable-stringify": "^2.1.0",
"fastify": "^4.25.2",
"flat-cache": "^3.0.4",
"flat-cache": "^4.0.0",
"form-data": "^4.0.0",
"geo-tz": "^7.0.7",
"geo-tz": "^8.0.0",
"handlebars": "^4.7.7",
"hastebin-gen": "^2.0.5",
"import-fresh": "^3.3.0",
"json5": "^2.2.3",
"knex": "^2.0.0",
"knex": "^3.1.0",
"moment": "^2.29.4",
"moment-precise-range-plugin": "^1.3.0",
"moment-timezone": "^0.5.43",
Expand All @@ -72,7 +72,7 @@
},
"devDependencies": {
"ajv": "^8.12.0",
"chai": "^4.3.7",
"chai": "^5.0.0",
"eslint": "^8.41.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.27.0",
Expand Down
4 changes: 1 addition & 3 deletions src/routes/apiConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { version } = require('../../package.json')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/config/poracleWeb', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)
if (fastify.config.server.ipWhitelist.length && !fastify.config.server.ipWhitelist.includes(req.ip)) return { webserver: 'unhappy', reason: `ip ${req.ip} not in whitelist` }
Expand Down Expand Up @@ -72,6 +72,4 @@ module.exports = async (fastify, options, next) => {
telegram: Object.fromEntries(typesForPlatform('telegram').map((x) => [x, Object.fromEntries(languagesForType('telegram', x).map((y) => [y, templatesForLanguage('telegram', x, y)]))])),
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiGeofence.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const geofenceTileGenerator = require('../lib/geofenceTileGenerator')
const { getKojiFences } = require('../util/koji')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/geofence/:area/map', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -281,6 +281,4 @@ module.exports = async (fastify, options, next) => {

return { status: 'ok' }
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiHumans.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const communityLogic = require('../lib/communityLogic')
const DiscordUtil = require('../lib/discord/discordUtil')
const DiscordRoleSetter = require('../lib/discord/discordRoleSetter')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/humans/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -536,6 +536,4 @@ module.exports = async (fastify, options, next) => {
human,
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiMasterData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/masterdata/grunts', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)
if (fastify.config.server.ipWhitelist.length && !fastify.config.server.ipWhitelist.includes(req.ip)) return { webserver: 'unhappy', reason: `ip ${req.ip} not in whitelist` }
Expand All @@ -24,6 +24,4 @@ module.exports = async (fastify, options, next) => {

return fastify.GameData.monsters
})

next()
}
3 changes: 1 addition & 2 deletions src/routes/apiPostMessage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.post('/api/postMessage', options, async (req, reply) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -34,5 +34,4 @@ module.exports = async (fastify, options, next) => {

if (!reply.sent) return { status: 'ok' }
})
next()
}
4 changes: 1 addition & 3 deletions src/routes/apiProfiles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ProfileLogic = require('../lib/profileLogic')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/profiles/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -192,6 +192,4 @@ module.exports = async (fastify, options, next) => {
}
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiTracking.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const tracked = require('../lib/poracleMessage/commands/tracked')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/tracking/all/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -99,6 +99,4 @@ module.exports = async (fastify, options, next) => {
profile,
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiTrackingEgg.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { diff } = require('deep-object-diff')
const trackedCommand = require('../lib/poracleMessage/commands/tracked')
const { raidLevels } = require('../util/util.json')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/tracking/egg/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -220,6 +220,4 @@ module.exports = async (fastify, options, next) => {
status: 'ok',
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiTrackingGym.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { diff } = require('deep-object-diff')

const trackedCommand = require('../lib/poracleMessage/commands/tracked')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/tracking/gym/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -218,6 +218,4 @@ module.exports = async (fastify, options, next) => {
status: 'ok',
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiTrackingInvasion.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { diff } = require('deep-object-diff')

const trackedCommand = require('../lib/poracleMessage/commands/tracked')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/tracking/invasion/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -211,6 +211,4 @@ module.exports = async (fastify, options, next) => {
status: 'ok',
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiTrackingLure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { diff } = require('deep-object-diff')

const trackedCommand = require('../lib/poracleMessage/commands/tracked')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/tracking/lure/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -211,6 +211,4 @@ module.exports = async (fastify, options, next) => {
status: 'ok',
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiTrackingMonster.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { diff } = require('deep-object-diff')
const trackedCommand = require('../lib/poracleMessage/commands/tracked')
const tracked = require('../lib/poracleMessage/commands/tracked')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/tracking/pokemon/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -276,6 +276,4 @@ module.exports = async (fastify, options, next) => {
status: 'ok',
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiTrackingNest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { diff } = require('deep-object-diff')

const trackedCommand = require('../lib/poracleMessage/commands/tracked')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/tracking/nest/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -207,6 +207,4 @@ module.exports = async (fastify, options, next) => {
status: 'ok',
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiTrackingQuest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { diff } = require('deep-object-diff')

const trackedCommand = require('../lib/poracleMessage/commands/tracked')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/tracking/quest/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -214,6 +214,4 @@ module.exports = async (fastify, options, next) => {
status: 'ok',
}
})

next()
}
4 changes: 1 addition & 3 deletions src/routes/apiTrackingRaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { diff } = require('deep-object-diff')

const trackedCommand = require('../lib/poracleMessage/commands/tracked')

module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/api/tracking/raid/:id', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

Expand Down Expand Up @@ -226,6 +226,4 @@ module.exports = async (fastify, options, next) => {
status: 'ok',
}
})

next()
}
3 changes: 1 addition & 2 deletions src/routes/getHealthCheck.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.get('/health', options, async (req) => {
fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`)

if (fastify.config.server.ipWhitelist.length && !fastify.config.server.ipWhitelist.includes(req.ip)) return { webserver: 'unhappy', reason: `ip ${req.ip} not in whitelist` }
if (fastify.config.server.ipBlacklist.length && fastify.config.server.ipBlacklist.includes(req.ip)) return { webserver: 'unhappy', reason: `ip ${req.ip} in blacklist` }
return { webserver: 'happy', query: req.query, port: fastify.config.server.port }
})
next()
}
8 changes: 4 additions & 4 deletions src/routes/postWebhooks.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = async (fastify, options, next) => {
module.exports = async (fastify, options) => {
fastify.post('/', options, async (req, reply) => {
if (fastify.config.server.ipWhitelist.length && !fastify.config.server.ipWhitelist.includes(req.ip)) return { webserver: 'unhappy', reason: `ip ${req.ip} not in whitelist` }
if (fastify.config.server.ipBlacklist.length && fastify.config.server.ipBlacklist.includes(req.ip)) return { webserver: 'unhappy', reason: `ip ${req.ip} in blacklist` }

let data = req.body
if (!Array.isArray(data)) data = [data]
fastify.hookQueue.push(...data)
await fastify.hookQueue.push(...data)

if (!reply.sent) return { webserver: 'happy' }
})
next()
}
}

0 comments on commit 7eeb5cb

Please sign in to comment.