From 7eeb5cb41e9c373a00a6be499c33846ed32dfc34 Mon Sep 17 00:00:00 2001 From: ReuschelCGN <82573872+ReuschelCGN@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:28:28 +0100 Subject: [PATCH] fastify fix and package update (#890) --- Dockerfile | 2 +- package.json | 12 ++++++------ src/routes/apiConfig.js | 4 +--- src/routes/apiGeofence.js | 4 +--- src/routes/apiHumans.js | 4 +--- src/routes/apiMasterData.js | 4 +--- src/routes/apiPostMessage.js | 3 +-- src/routes/apiProfiles.js | 4 +--- src/routes/apiTracking.js | 4 +--- src/routes/apiTrackingEgg.js | 4 +--- src/routes/apiTrackingGym.js | 4 +--- src/routes/apiTrackingInvasion.js | 4 +--- src/routes/apiTrackingLure.js | 4 +--- src/routes/apiTrackingMonster.js | 4 +--- src/routes/apiTrackingNest.js | 4 +--- src/routes/apiTrackingQuest.js | 4 +--- src/routes/apiTrackingRaid.js | 4 +--- src/routes/getHealthCheck.js | 3 +-- src/routes/postWebhooks.js | 8 ++++---- 19 files changed, 27 insertions(+), 57 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4a35c021d..2cb8a3def 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-alpine +FROM node:20-alpine WORKDIR /usr/src/app ADD . ./ diff --git a/package.json b/package.json index 2034bf652..8a7fd42fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "poracle", - "version": "4.7.0", + "version": "4.8.0", "description": "Webhook processing and personalised discord|telegram alarms", "keywords": [ "poracle", @@ -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", @@ -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", diff --git a/src/routes/apiConfig.js b/src/routes/apiConfig.js index 869f8df07..ec72c0f2a 100644 --- a/src/routes/apiConfig.js +++ b/src/routes/apiConfig.js @@ -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` } @@ -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() } diff --git a/src/routes/apiGeofence.js b/src/routes/apiGeofence.js index f3a373494..766b3bbaa 100644 --- a/src/routes/apiGeofence.js +++ b/src/routes/apiGeofence.js @@ -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}`) @@ -281,6 +281,4 @@ module.exports = async (fastify, options, next) => { return { status: 'ok' } }) - - next() } diff --git a/src/routes/apiHumans.js b/src/routes/apiHumans.js index cb5a07aa7..60c28c143 100644 --- a/src/routes/apiHumans.js +++ b/src/routes/apiHumans.js @@ -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}`) @@ -536,6 +536,4 @@ module.exports = async (fastify, options, next) => { human, } }) - - next() } diff --git a/src/routes/apiMasterData.js b/src/routes/apiMasterData.js index 37067879f..3ded032d0 100644 --- a/src/routes/apiMasterData.js +++ b/src/routes/apiMasterData.js @@ -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` } @@ -24,6 +24,4 @@ module.exports = async (fastify, options, next) => { return fastify.GameData.monsters }) - - next() } diff --git a/src/routes/apiPostMessage.js b/src/routes/apiPostMessage.js index 569e1c7da..af4c16f6f 100644 --- a/src/routes/apiPostMessage.js +++ b/src/routes/apiPostMessage.js @@ -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}`) @@ -34,5 +34,4 @@ module.exports = async (fastify, options, next) => { if (!reply.sent) return { status: 'ok' } }) - next() } diff --git a/src/routes/apiProfiles.js b/src/routes/apiProfiles.js index 9325ba554..bbb9ed4cc 100644 --- a/src/routes/apiProfiles.js +++ b/src/routes/apiProfiles.js @@ -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}`) @@ -192,6 +192,4 @@ module.exports = async (fastify, options, next) => { } } }) - - next() } diff --git a/src/routes/apiTracking.js b/src/routes/apiTracking.js index 72d5bc09c..77ad55cba 100644 --- a/src/routes/apiTracking.js +++ b/src/routes/apiTracking.js @@ -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}`) @@ -99,6 +99,4 @@ module.exports = async (fastify, options, next) => { profile, } }) - - next() } diff --git a/src/routes/apiTrackingEgg.js b/src/routes/apiTrackingEgg.js index 5942841a9..1e88c196d 100644 --- a/src/routes/apiTrackingEgg.js +++ b/src/routes/apiTrackingEgg.js @@ -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}`) @@ -220,6 +220,4 @@ module.exports = async (fastify, options, next) => { status: 'ok', } }) - - next() } diff --git a/src/routes/apiTrackingGym.js b/src/routes/apiTrackingGym.js index b05ed648f..97694c8b1 100644 --- a/src/routes/apiTrackingGym.js +++ b/src/routes/apiTrackingGym.js @@ -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}`) @@ -218,6 +218,4 @@ module.exports = async (fastify, options, next) => { status: 'ok', } }) - - next() } diff --git a/src/routes/apiTrackingInvasion.js b/src/routes/apiTrackingInvasion.js index e1d4edf80..51e1214f1 100644 --- a/src/routes/apiTrackingInvasion.js +++ b/src/routes/apiTrackingInvasion.js @@ -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}`) @@ -211,6 +211,4 @@ module.exports = async (fastify, options, next) => { status: 'ok', } }) - - next() } diff --git a/src/routes/apiTrackingLure.js b/src/routes/apiTrackingLure.js index 62d2fc8fd..d185b8292 100644 --- a/src/routes/apiTrackingLure.js +++ b/src/routes/apiTrackingLure.js @@ -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}`) @@ -211,6 +211,4 @@ module.exports = async (fastify, options, next) => { status: 'ok', } }) - - next() } diff --git a/src/routes/apiTrackingMonster.js b/src/routes/apiTrackingMonster.js index b3921cf36..aa694fd73 100644 --- a/src/routes/apiTrackingMonster.js +++ b/src/routes/apiTrackingMonster.js @@ -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}`) @@ -276,6 +276,4 @@ module.exports = async (fastify, options, next) => { status: 'ok', } }) - - next() } diff --git a/src/routes/apiTrackingNest.js b/src/routes/apiTrackingNest.js index 56885405c..f88c0ec20 100644 --- a/src/routes/apiTrackingNest.js +++ b/src/routes/apiTrackingNest.js @@ -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}`) @@ -207,6 +207,4 @@ module.exports = async (fastify, options, next) => { status: 'ok', } }) - - next() } diff --git a/src/routes/apiTrackingQuest.js b/src/routes/apiTrackingQuest.js index 078ef734e..95be98a9f 100644 --- a/src/routes/apiTrackingQuest.js +++ b/src/routes/apiTrackingQuest.js @@ -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}`) @@ -214,6 +214,4 @@ module.exports = async (fastify, options, next) => { status: 'ok', } }) - - next() } diff --git a/src/routes/apiTrackingRaid.js b/src/routes/apiTrackingRaid.js index 597fb0171..0fd6a57c6 100644 --- a/src/routes/apiTrackingRaid.js +++ b/src/routes/apiTrackingRaid.js @@ -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}`) @@ -226,6 +226,4 @@ module.exports = async (fastify, options, next) => { status: 'ok', } }) - - next() } diff --git a/src/routes/getHealthCheck.js b/src/routes/getHealthCheck.js index dbeff1127..1171aa310 100644 --- a/src/routes/getHealthCheck.js +++ b/src/routes/getHealthCheck.js @@ -1,4 +1,4 @@ -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}`) @@ -6,5 +6,4 @@ module.exports = async (fastify, options, next) => { 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() } diff --git a/src/routes/postWebhooks.js b/src/routes/postWebhooks.js index dc95a1dd7..c7d03e025 100644 --- a/src/routes/postWebhooks.js +++ b/src/routes/postWebhooks.js @@ -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() -} \ No newline at end of file +}