From bfc41d2d37f3fc5d081b1d62009cfa77c14cd69e Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Sat, 6 Sep 2025 23:27:09 +0200 Subject: [PATCH 01/11] feat(api): egg - support passing multiple levels feat(api): raid - support passing multiple levels and pokemon+forms --- src/routes/apiTrackingEgg.js | 49 ++++++++++++------- src/routes/apiTrackingRaid.js | 92 ++++++++++++++++++++++++++--------- 2 files changed, 100 insertions(+), 41 deletions(-) diff --git a/src/routes/apiTrackingEgg.js b/src/routes/apiTrackingEgg.js index dadc66da6..bff7b6820 100644 --- a/src/routes/apiTrackingEgg.js +++ b/src/routes/apiTrackingEgg.js @@ -84,25 +84,40 @@ module.exports = async (fastify, options) => { const defaultTo = ((value, x) => ((value === undefined) ? x : value)) - const insert = insertReq.map((row) => { - const level = +row.level - if (row.level === undefined || level < 1 || (level > Math.max(...Object.keys(raidLevels).map((k) => +k)) && level !== 90)) { - throw new Error('Invalid level') + const insert = [] + + for (const row of insertReq) { + // Handle both single level and array of levels + let levels = row.level + if (!Array.isArray(levels)) { + levels = [levels] } - return { - id, - profile_no: currentProfileNo, - ping: '', - template: (row.template || fastify.config.general.defaultTemplateName).toString(), - exclusive: +defaultTo(row.exclusive, 0), - distance: +defaultTo(row.distance, 0), - team: row.team >= 0 && row.team <= 4 ? row.team : 4, // carefully chosen to get nulls/undefined to 4 but allow 0 - clean: +defaultTo(row.clean, 0), - level: +level, - gym_id: row.gym_id ? row.gym_id : null, - rsvp_changes: row.rsvp_changes >= 0 && row.rsvp_changes <= 2 ? row.rsvp_changes : 0, + + // Validate all levels + for (const levelValue of levels) { + const level = +levelValue + if (levelValue === undefined || level < 1 || (level > Math.max(...Object.keys(raidLevels).map((k) => +k)) && level !== 90)) { + throw new Error(`Invalid level: ${levelValue}`) + } } - }) + + // Create an entry for each level + for (const levelValue of levels) { + insert.push({ + id, + profile_no: currentProfileNo, + ping: '', + template: (row.template || fastify.config.general.defaultTemplateName).toString(), + exclusive: +defaultTo(row.exclusive, 0), + distance: +defaultTo(row.distance, 0), + team: row.team >= 0 && row.team <= 4 ? row.team : 4, // carefully chosen to get nulls/undefined to 4 but allow 0 + clean: +defaultTo(row.clean, 0), + level: +levelValue, + gym_id: row.gym_id ? row.gym_id : null, + rsvp_changes: row.rsvp_changes >= 0 && row.rsvp_changes <= 2 ? row.rsvp_changes : 0, + }) + } + } try { const tracked = await fastify.query.selectAllQuery('egg', { id, profile_no: currentProfileNo }) diff --git a/src/routes/apiTrackingRaid.js b/src/routes/apiTrackingRaid.js index c547f2a3b..6c4088ecd 100644 --- a/src/routes/apiTrackingRaid.js +++ b/src/routes/apiTrackingRaid.js @@ -82,33 +82,77 @@ module.exports = async (fastify, options) => { const defaultTo = ((value, x) => ((value === undefined) ? x : value)) - const insert = insertReq.map((row) => { - let level = 9000 - if (row.pokemon_id === 9000) { - level = +row.level - if (row.level === undefined || level < 1 || (level > Math.max(...Object.keys(fastify.GameData.utilData.raidLevels).map((k) => +k)) && level !== 90)) { - throw new Error('Invalid level (must be specified if no pokemon_id') + const insert = [] + + for (const row of insertReq) { + // Handle pokemon_form array: [{"pokemon_id": .., "form": ..}, ..] + if (row.pokemon_form && Array.isArray(row.pokemon_form)) { + for (const pokemonForm of row.pokemon_form) { + if (!pokemonForm || typeof pokemonForm !== 'object' || pokemonForm.pokemon_id === undefined || pokemonForm.form === undefined) { + throw new Error('pokemon_form entries must be objects with pokemon_id and form properties') + } + insert.push({ + id, + profile_no: currentProfileNo, + ping: '', + template: (row.template || fastify.config.general.defaultTemplateName).toString(), + pokemon_id: +pokemonForm.pokemon_id, + exclusive: +defaultTo(row.exclusive, 0), + distance: +defaultTo(row.distance, 0), + team: row.team >= 0 && row.team <= 4 ? row.team : 4, + clean: +defaultTo(+row.clean, 0), + level: 9000, // Default for pokemon raids + form: +pokemonForm.form, + move: +defaultTo(row.move, 9000), + evolution: +defaultTo(row.evolution, 9000), + gym_id: row.gym_id ? row.gym_id : null, + rsvp_changes: row.rsvp_changes >= 0 && row.rsvp_changes <= 2 ? row.rsvp_changes : 0, + }) + } + } else { + // Handle traditional single pokemon_id/form or level-based raids + let levels = [] + if (row.pokemon_id === 9000 || row.pokemon_id === undefined) { + // Level-based raid (egg) + if (row.level !== undefined) { + levels = Array.isArray(row.level) ? row.level : [row.level] + // Validate all levels + for (const levelValue of levels) { + const level = +levelValue + if (level < 1 || (level > Math.max(...Object.keys(fastify.GameData.utilData.raidLevels).map((k) => +k)) && level !== 90)) { + throw new Error(`Invalid level: ${levelValue}`) + } + } + } else { + throw new Error('Level must be specified if no pokemon_id') + } + } else { + // Pokemon-specific raid + levels = [9000] // Default level for pokemon raids } - } - return { - id, - profile_no: currentProfileNo, - ping: '', - template: (row.template || fastify.config.general.defaultTemplateName).toString(), - pokemon_id: +defaultTo(row.pokemon_id, 9000), - exclusive: +defaultTo(row.exclusive, 0), - distance: +defaultTo(row.distance, 0), - team: row.team >= 0 && row.team <= 4 ? row.team : 4, // carefully chosen to get nulls/undefined to 4 but allow 0 - clean: +defaultTo(+row.clean, 0), - level: +level, - form: +defaultTo(row.form, 0), - move: +defaultTo(row.move, 9000), - evolution: +defaultTo(row.evolution, 9000), - gym_id: row.gym_id ? row.gym_id : null, - rsvp_changes: row.rsvp_changes >= 0 && row.rsvp_changes <= 2 ? row.rsvp_changes : 0, + // Create entries for each level + for (const levelValue of levels) { + insert.push({ + id, + profile_no: currentProfileNo, + ping: '', + template: (row.template || fastify.config.general.defaultTemplateName).toString(), + pokemon_id: +defaultTo(row.pokemon_id, 9000), + exclusive: +defaultTo(row.exclusive, 0), + distance: +defaultTo(row.distance, 0), + team: row.team >= 0 && row.team <= 4 ? row.team : 4, + clean: +defaultTo(+row.clean, 0), + level: +levelValue, + form: +defaultTo(row.form, 0), + move: +defaultTo(row.move, 9000), + evolution: +defaultTo(row.evolution, 9000), + gym_id: row.gym_id ? row.gym_id : null, + rsvp_changes: row.rsvp_changes >= 0 && row.rsvp_changes <= 2 ? row.rsvp_changes : 0, + }) + } } - }) + } try { const tracked = await fastify.query.selectAllQuery('raid', { id, profile_no: currentProfileNo }) From b431e94bfb802fcc3a762a8114f537066f251249 Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:06:27 +0200 Subject: [PATCH 02/11] feat(api): query.silent to mute messages in tracking POST --- src/routes/apiTrackingEgg.js | 41 ++++++++++++++++--------------- src/routes/apiTrackingGym.js | 41 ++++++++++++++++--------------- src/routes/apiTrackingInvasion.js | 41 ++++++++++++++++--------------- src/routes/apiTrackingLure.js | 41 ++++++++++++++++--------------- src/routes/apiTrackingMonster.js | 41 ++++++++++++++++--------------- src/routes/apiTrackingNest.js | 41 ++++++++++++++++--------------- src/routes/apiTrackingQuest.js | 41 ++++++++++++++++--------------- src/routes/apiTrackingRaid.js | 41 ++++++++++++++++--------------- 8 files changed, 168 insertions(+), 160 deletions(-) diff --git a/src/routes/apiTrackingEgg.js b/src/routes/apiTrackingEgg.js index bff7b6820..028a8a28b 100644 --- a/src/routes/apiTrackingEgg.js +++ b/src/routes/apiTrackingEgg.js @@ -180,26 +180,27 @@ module.exports = async (fastify, options) => { await fastify.query.insertQuery('egg', [...insert, ...updates]) - // Send message to user - - const data = [{ - lat: 0, - lon: 0, - message: { content: message }, - target: human.id, - type: human.type, - name: human.name, - tth: { hours: 1, minutes: 0, seconds: 0 }, - clean: false, - emoji: '', - logReference: 'WebApi', - language, - }] - - data.forEach((job) => { - if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) - if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) - }) + // Send message to user (unless silent parameter is set) + if (!req.query.silent) { + const data = [{ + lat: 0, + lon: 0, + message: { content: message }, + target: human.id, + type: human.type, + name: human.name, + tth: { hours: 1, minutes: 0, seconds: 0 }, + clean: false, + emoji: '', + logReference: 'WebApi', + language, + }] + + data.forEach((job) => { + if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) + if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) + }) + } return { status: 'ok', diff --git a/src/routes/apiTrackingGym.js b/src/routes/apiTrackingGym.js index d4a8c9be6..2f3882c83 100644 --- a/src/routes/apiTrackingGym.js +++ b/src/routes/apiTrackingGym.js @@ -162,26 +162,27 @@ module.exports = async (fastify, options) => { await fastify.query.insertQuery('gym', [...insert, ...updates]) - // Send message to user - - const data = [{ - lat: 0, - lon: 0, - message: { content: message }, - target: human.id, - type: human.type, - name: human.name, - tth: { hours: 1, minutes: 0, seconds: 0 }, - clean: false, - emoji: '', - logReference: 'WebApi', - language, - }] - - data.forEach((job) => { - if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) - if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) - }) + // Send message to user (unless silent parameter is set) + if (!req.query.silent) { + const data = [{ + lat: 0, + lon: 0, + message: { content: message }, + target: human.id, + type: human.type, + name: human.name, + tth: { hours: 1, minutes: 0, seconds: 0 }, + clean: false, + emoji: '', + logReference: 'WebApi', + language, + }] + + data.forEach((job) => { + if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) + if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) + }) + } return { status: 'ok', diff --git a/src/routes/apiTrackingInvasion.js b/src/routes/apiTrackingInvasion.js index 41a263dd9..4a444f39f 100644 --- a/src/routes/apiTrackingInvasion.js +++ b/src/routes/apiTrackingInvasion.js @@ -155,26 +155,27 @@ module.exports = async (fastify, options) => { await fastify.query.insertQuery('invasion', [...insert, ...updates]) - // Send message to user - - const data = [{ - lat: 0, - lon: 0, - message: { content: message }, - target: human.id, - type: human.type, - name: human.name, - tth: { hours: 1, minutes: 0, seconds: 0 }, - clean: false, - emoji: '', - logReference: 'WebApi', - language, - }] - - data.forEach((job) => { - if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) - if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) - }) + // Send message to user (unless silent parameter is set) + if (!req.query.silent) { + const data = [{ + lat: 0, + lon: 0, + message: { content: message }, + target: human.id, + type: human.type, + name: human.name, + tth: { hours: 1, minutes: 0, seconds: 0 }, + clean: false, + emoji: '', + logReference: 'WebApi', + language, + }] + + data.forEach((job) => { + if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) + if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) + }) + } return { status: 'ok', diff --git a/src/routes/apiTrackingLure.js b/src/routes/apiTrackingLure.js index 81c7bcc4f..4356f4469 100644 --- a/src/routes/apiTrackingLure.js +++ b/src/routes/apiTrackingLure.js @@ -155,26 +155,27 @@ module.exports = async (fastify, options) => { await fastify.query.insertQuery('lures', [...insert, ...updates]) - // Send message to user - - const data = [{ - lat: 0, - lon: 0, - message: { content: message }, - target: human.id, - type: human.type, - name: human.name, - tth: { hours: 1, minutes: 0, seconds: 0 }, - clean: false, - emoji: '', - logReference: 'WebApi', - language, - }] - - data.forEach((job) => { - if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) - if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) - }) + // Send message to user (unless silent parameter is set) + if (!req.query.silent) { + const data = [{ + lat: 0, + lon: 0, + message: { content: message }, + target: human.id, + type: human.type, + name: human.name, + tth: { hours: 1, minutes: 0, seconds: 0 }, + clean: false, + emoji: '', + logReference: 'WebApi', + language, + }] + + data.forEach((job) => { + if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) + if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) + }) + } return { status: 'ok', diff --git a/src/routes/apiTrackingMonster.js b/src/routes/apiTrackingMonster.js index bd95d440b..2fca8903c 100644 --- a/src/routes/apiTrackingMonster.js +++ b/src/routes/apiTrackingMonster.js @@ -223,26 +223,27 @@ module.exports = async (fastify, options) => { await fastify.query.updateQuery('monsters', row, { uid: row.uid }) } - // Send message to user - - const data = [{ - lat: 0, - lon: 0, - message: { content: message }, - target: human.id, - type: human.type, - name: human.name, - tth: { hours: 1, minutes: 0, seconds: 0 }, - clean: false, - emoji: '', - logReference: 'WebApi', - language, - }] - - data.forEach((job) => { - if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) - if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) - }) + // Send message to user (unless silent parameter is set) + if (!req.query.silent) { + const data = [{ + lat: 0, + lon: 0, + message: { content: message }, + target: human.id, + type: human.type, + name: human.name, + tth: { hours: 1, minutes: 0, seconds: 0 }, + clean: false, + emoji: '', + logReference: 'WebApi', + language, + }] + + data.forEach((job) => { + if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) + if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) + }) + } if (fastify.triggerReloadAlerts) fastify.triggerReloadAlerts() diff --git a/src/routes/apiTrackingNest.js b/src/routes/apiTrackingNest.js index ec1ec811f..3dd5346d9 100644 --- a/src/routes/apiTrackingNest.js +++ b/src/routes/apiTrackingNest.js @@ -151,26 +151,27 @@ module.exports = async (fastify, options) => { await fastify.query.insertQuery('nests', [...insert, ...updates]) - // Send message to user - - const data = [{ - lat: 0, - lon: 0, - message: { content: message }, - target: human.id, - type: human.type, - name: human.name, - tth: { hours: 1, minutes: 0, seconds: 0 }, - clean: false, - emoji: '', - logReference: 'WebApi', - language, - }] - - data.forEach((job) => { - if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) - if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) - }) + // Send message to user (unless silent parameter is set) + if (!req.query.silent) { + const data = [{ + lat: 0, + lon: 0, + message: { content: message }, + target: human.id, + type: human.type, + name: human.name, + tth: { hours: 1, minutes: 0, seconds: 0 }, + clean: false, + emoji: '', + logReference: 'WebApi', + language, + }] + + data.forEach((job) => { + if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) + if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) + }) + } return { status: 'ok', diff --git a/src/routes/apiTrackingQuest.js b/src/routes/apiTrackingQuest.js index 715e62d10..afef51a21 100644 --- a/src/routes/apiTrackingQuest.js +++ b/src/routes/apiTrackingQuest.js @@ -158,26 +158,27 @@ module.exports = async (fastify, options) => { await fastify.query.insertQuery('quest', [...insert, ...updates]) - // Send message to user - - const data = [{ - lat: 0, - lon: 0, - message: { content: message }, - target: human.id, - type: human.type, - name: human.name, - tth: { hours: 1, minutes: 0, seconds: 0 }, - clean: false, - emoji: '', - logReference: 'WebApi', - language, - }] - - data.forEach((job) => { - if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) - if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) - }) + // Send message to user (unless silent parameter is set) + if (!req.query.silent) { + const data = [{ + lat: 0, + lon: 0, + message: { content: message }, + target: human.id, + type: human.type, + name: human.name, + tth: { hours: 1, minutes: 0, seconds: 0 }, + clean: false, + emoji: '', + logReference: 'WebApi', + language, + }] + + data.forEach((job) => { + if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) + if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) + }) + } return { status: 'ok', diff --git a/src/routes/apiTrackingRaid.js b/src/routes/apiTrackingRaid.js index 6c4088ecd..5ec832dbd 100644 --- a/src/routes/apiTrackingRaid.js +++ b/src/routes/apiTrackingRaid.js @@ -215,26 +215,27 @@ module.exports = async (fastify, options) => { await fastify.query.insertQuery('raid', [...insert, ...updates]) - // Send message to user - - const data = [{ - lat: 0, - lon: 0, - message: { content: message }, - target: human.id, - type: human.type, - name: human.name, - tth: { hours: 1, minutes: 0, seconds: 0 }, - clean: false, - emoji: '', - logReference: 'WebApi', - language, - }] - - data.forEach((job) => { - if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) - if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) - }) + // Send message to user (unless silent parameter is set) + if (!req.query.silent) { + const data = [{ + lat: 0, + lon: 0, + message: { content: message }, + target: human.id, + type: human.type, + name: human.name, + tth: { hours: 1, minutes: 0, seconds: 0 }, + clean: false, + emoji: '', + logReference: 'WebApi', + language, + }] + + data.forEach((job) => { + if (['discord:user', 'discord:channel', 'webhook'].includes(job.type)) fastify.discordQueue.push(job) + if (['telegram:user', 'telegram:channel'].includes(job.type)) fastify.telegramQueue.push(job) + }) + } return { status: 'ok', From 5d18861838c4f2ddc2ee5f04130529396d7d7789 Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Sat, 4 Oct 2025 14:58:34 +0200 Subject: [PATCH 03/11] feat(api): extend get/post with optional param profile_no overriding currently selected profile pull --- src/routes/apiTracking.js | 2 +- 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 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/routes/apiTracking.js b/src/routes/apiTracking.js index 77ad55cba..ef7f46a7b 100644 --- a/src/routes/apiTracking.js +++ b/src/routes/apiTracking.js @@ -19,7 +19,7 @@ module.exports = async (fastify, options) => { message: 'User not found', } } - const currentProfileNo = human.current_profile_no + const currentProfileNo = req.params.profile_no || human.current_profile_no const { id } = req.params const pokemon = await fastify.query.selectAllQuery('monsters', { id, profile_no: currentProfileNo }) diff --git a/src/routes/apiTrackingEgg.js b/src/routes/apiTrackingEgg.js index 028a8a28b..609f9fc3d 100644 --- a/src/routes/apiTrackingEgg.js +++ b/src/routes/apiTrackingEgg.js @@ -26,7 +26,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) - const eggs = await fastify.query.selectAllQuery('egg', { id: req.params.id, profile_no: human.current_profile_no }) + const eggs = await fastify.query.selectAllQuery('egg', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) const eggWithDesc = await Promise.all(eggs.map(async (row) => ({ ...row, description: await trackedCommand.eggRowText(fastify.config, translator, fastify.GameData, row, fastify.scannerQuery) }))) @@ -77,7 +77,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = human.current_profile_no + const currentProfileNo = req.params.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingGym.js b/src/routes/apiTrackingGym.js index 2f3882c83..f00721aba 100644 --- a/src/routes/apiTrackingGym.js +++ b/src/routes/apiTrackingGym.js @@ -24,7 +24,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) - const gyms = await fastify.query.selectAllQuery('gym', { id: req.params.id, profile_no: human.current_profile_no }) + const gyms = await fastify.query.selectAllQuery('gym', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) const gymWithDesc = await Promise.all(gyms.map(async (row) => ({ ...row, description: await trackedCommand.gymRowText(fastify.config, translator, fastify.GameData, row, fastify.scannerQuery) }))) @@ -75,7 +75,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = human.current_profile_no + const currentProfileNo = req.params.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingInvasion.js b/src/routes/apiTrackingInvasion.js index 4a444f39f..a36f46928 100644 --- a/src/routes/apiTrackingInvasion.js +++ b/src/routes/apiTrackingInvasion.js @@ -22,7 +22,7 @@ module.exports = async (fastify, options) => { } } - const invasion = await fastify.query.selectAllQuery('invasion', { id: req.params.id, profile_no: human.current_profile_no }) + const invasion = await fastify.query.selectAllQuery('invasion', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) return { status: 'ok', @@ -71,7 +71,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = human.current_profile_no + const currentProfileNo = req.params.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingLure.js b/src/routes/apiTrackingLure.js index 4356f4469..12be964f4 100644 --- a/src/routes/apiTrackingLure.js +++ b/src/routes/apiTrackingLure.js @@ -22,7 +22,7 @@ module.exports = async (fastify, options) => { } } - const lure = await fastify.query.selectAllQuery('lures', { id: req.params.id, profile_no: human.current_profile_no }) + const lure = await fastify.query.selectAllQuery('lures', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) return { status: 'ok', @@ -71,7 +71,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = human.current_profile_no + const currentProfileNo = req.params.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingMonster.js b/src/routes/apiTrackingMonster.js index 2fca8903c..cb03ee9d8 100644 --- a/src/routes/apiTrackingMonster.js +++ b/src/routes/apiTrackingMonster.js @@ -25,7 +25,7 @@ module.exports = async (fastify, options) => { } } - const monsters = await fastify.query.selectAllQuery('monsters', { id: req.params.id, profile_no: human.current_profile_no }) + const monsters = await fastify.query.selectAllQuery('monsters', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) return { status: 'ok', @@ -101,7 +101,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = human.current_profile_no + const currentProfileNo = req.params.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingNest.js b/src/routes/apiTrackingNest.js index 3dd5346d9..94db66e0e 100644 --- a/src/routes/apiTrackingNest.js +++ b/src/routes/apiTrackingNest.js @@ -22,7 +22,7 @@ module.exports = async (fastify, options) => { } } - const nest = await fastify.query.selectAllQuery('nests', { id: req.params.id, profile_no: human.current_profile_no }) + const nest = await fastify.query.selectAllQuery('nests', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) return { status: 'ok', @@ -71,7 +71,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = human.current_profile_no + const currentProfileNo = req.params.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingQuest.js b/src/routes/apiTrackingQuest.js index afef51a21..157b13844 100644 --- a/src/routes/apiTrackingQuest.js +++ b/src/routes/apiTrackingQuest.js @@ -22,7 +22,7 @@ module.exports = async (fastify, options) => { } } - const quest = await fastify.query.selectAllQuery('quest', { id: req.params.id, profile_no: human.current_profile_no }) + const quest = await fastify.query.selectAllQuery('quest', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) return { status: 'ok', @@ -71,7 +71,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = human.current_profile_no + const currentProfileNo = req.params.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingRaid.js b/src/routes/apiTrackingRaid.js index 5ec832dbd..0dc3ec926 100644 --- a/src/routes/apiTrackingRaid.js +++ b/src/routes/apiTrackingRaid.js @@ -24,7 +24,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) - const raids = await fastify.query.selectAllQuery('raid', { id: req.params.id, profile_no: human.current_profile_no }) + const raids = await fastify.query.selectAllQuery('raid', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) const raidWithDesc = await Promise.all(raids.map(async (row) => ({ ...row, description: await trackedCommand.raidRowText(fastify.config, translator, fastify.GameData, row, fastify.scannerQuery) }))) @@ -75,7 +75,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = human.current_profile_no + const currentProfileNo = req.params.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] From d1c7346949ace924ba9a20907686739b0c4c5b96 Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Sat, 4 Oct 2025 15:07:52 +0200 Subject: [PATCH 04/11] fix(api): switch optional profile_no from param to query --- src/routes/apiTracking.js | 2 +- 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 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/routes/apiTracking.js b/src/routes/apiTracking.js index ef7f46a7b..683c3d04c 100644 --- a/src/routes/apiTracking.js +++ b/src/routes/apiTracking.js @@ -19,7 +19,7 @@ module.exports = async (fastify, options) => { message: 'User not found', } } - const currentProfileNo = req.params.profile_no || human.current_profile_no + const currentProfileNo = req.query.profile_no || human.current_profile_no const { id } = req.params const pokemon = await fastify.query.selectAllQuery('monsters', { id, profile_no: currentProfileNo }) diff --git a/src/routes/apiTrackingEgg.js b/src/routes/apiTrackingEgg.js index 609f9fc3d..9345665eb 100644 --- a/src/routes/apiTrackingEgg.js +++ b/src/routes/apiTrackingEgg.js @@ -26,7 +26,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) - const eggs = await fastify.query.selectAllQuery('egg', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) + const eggs = await fastify.query.selectAllQuery('egg', { id: req.params.id, profile_no: req.query.profile_no || human.current_profile_no }) const eggWithDesc = await Promise.all(eggs.map(async (row) => ({ ...row, description: await trackedCommand.eggRowText(fastify.config, translator, fastify.GameData, row, fastify.scannerQuery) }))) @@ -77,7 +77,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = req.params.profile_no || human.current_profile_no + const currentProfileNo = req.query.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingGym.js b/src/routes/apiTrackingGym.js index f00721aba..64432cede 100644 --- a/src/routes/apiTrackingGym.js +++ b/src/routes/apiTrackingGym.js @@ -24,7 +24,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) - const gyms = await fastify.query.selectAllQuery('gym', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) + const gyms = await fastify.query.selectAllQuery('gym', { id: req.params.id, profile_no: req.query.profile_no || human.current_profile_no }) const gymWithDesc = await Promise.all(gyms.map(async (row) => ({ ...row, description: await trackedCommand.gymRowText(fastify.config, translator, fastify.GameData, row, fastify.scannerQuery) }))) @@ -75,7 +75,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = req.params.profile_no || human.current_profile_no + const currentProfileNo = req.query.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingInvasion.js b/src/routes/apiTrackingInvasion.js index a36f46928..7f483d39a 100644 --- a/src/routes/apiTrackingInvasion.js +++ b/src/routes/apiTrackingInvasion.js @@ -22,7 +22,7 @@ module.exports = async (fastify, options) => { } } - const invasion = await fastify.query.selectAllQuery('invasion', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) + const invasion = await fastify.query.selectAllQuery('invasion', { id: req.params.id, profile_no: req.query.profile_no || human.current_profile_no }) return { status: 'ok', @@ -71,7 +71,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = req.params.profile_no || human.current_profile_no + const currentProfileNo = req.query.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingLure.js b/src/routes/apiTrackingLure.js index 12be964f4..67c487373 100644 --- a/src/routes/apiTrackingLure.js +++ b/src/routes/apiTrackingLure.js @@ -22,7 +22,7 @@ module.exports = async (fastify, options) => { } } - const lure = await fastify.query.selectAllQuery('lures', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) + const lure = await fastify.query.selectAllQuery('lures', { id: req.params.id, profile_no: req.query.profile_no || human.current_profile_no }) return { status: 'ok', @@ -71,7 +71,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = req.params.profile_no || human.current_profile_no + const currentProfileNo = req.query.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingMonster.js b/src/routes/apiTrackingMonster.js index cb03ee9d8..2f46f7e81 100644 --- a/src/routes/apiTrackingMonster.js +++ b/src/routes/apiTrackingMonster.js @@ -25,7 +25,7 @@ module.exports = async (fastify, options) => { } } - const monsters = await fastify.query.selectAllQuery('monsters', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) + const monsters = await fastify.query.selectAllQuery('monsters', { id: req.params.id, profile_no: req.query.profile_no || human.current_profile_no }) return { status: 'ok', @@ -101,7 +101,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = req.params.profile_no || human.current_profile_no + const currentProfileNo = req.query.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingNest.js b/src/routes/apiTrackingNest.js index 94db66e0e..b66b2306d 100644 --- a/src/routes/apiTrackingNest.js +++ b/src/routes/apiTrackingNest.js @@ -22,7 +22,7 @@ module.exports = async (fastify, options) => { } } - const nest = await fastify.query.selectAllQuery('nests', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) + const nest = await fastify.query.selectAllQuery('nests', { id: req.params.id, profile_no: req.query.profile_no || human.current_profile_no }) return { status: 'ok', @@ -71,7 +71,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = req.params.profile_no || human.current_profile_no + const currentProfileNo = req.query.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingQuest.js b/src/routes/apiTrackingQuest.js index 157b13844..0b396e603 100644 --- a/src/routes/apiTrackingQuest.js +++ b/src/routes/apiTrackingQuest.js @@ -22,7 +22,7 @@ module.exports = async (fastify, options) => { } } - const quest = await fastify.query.selectAllQuery('quest', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) + const quest = await fastify.query.selectAllQuery('quest', { id: req.params.id, profile_no: req.query.profile_no || human.current_profile_no }) return { status: 'ok', @@ -71,7 +71,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = req.params.profile_no || human.current_profile_no + const currentProfileNo = req.query.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] diff --git a/src/routes/apiTrackingRaid.js b/src/routes/apiTrackingRaid.js index 0dc3ec926..0b0853ed9 100644 --- a/src/routes/apiTrackingRaid.js +++ b/src/routes/apiTrackingRaid.js @@ -24,7 +24,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) - const raids = await fastify.query.selectAllQuery('raid', { id: req.params.id, profile_no: req.params.profile_no || human.current_profile_no }) + const raids = await fastify.query.selectAllQuery('raid', { id: req.params.id, profile_no: req.query.profile_no || human.current_profile_no }) const raidWithDesc = await Promise.all(raids.map(async (row) => ({ ...row, description: await trackedCommand.raidRowText(fastify.config, translator, fastify.GameData, row, fastify.scannerQuery) }))) @@ -75,7 +75,7 @@ module.exports = async (fastify, options) => { const language = human.language || fastify.config.general.locale const translator = fastify.translatorFactory.Translator(language) const { id } = req.params - const currentProfileNo = req.params.profile_no || human.current_profile_no + const currentProfileNo = req.query.profile_no || human.current_profile_no let insertReq = req.body if (!Array.isArray(insertReq)) insertReq = [insertReq] From e93c0c35c8b3566a1c16116ff53daaa2aa1975ba Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Tue, 7 Oct 2025 13:55:55 +0200 Subject: [PATCH 05/11] feat(api): user create --- src/routes/apiHumans.js | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/routes/apiHumans.js b/src/routes/apiHumans.js index 60c28c143..66d848c77 100644 --- a/src/routes/apiHumans.js +++ b/src/routes/apiHumans.js @@ -536,4 +536,64 @@ module.exports = async (fastify, options) => { human, } }) + + fastify.post('/api/humans', 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` } + + const secret = req.headers['x-poracle-secret'] + if (!secret || !fastify.config.server.apiSecret || secret !== fastify.config.server.apiSecret) { + return { status: 'authError', reason: 'incorrect or missing api secret' } + } + + // Validate required fields + if (!req.body.id || !req.body.type || !req.body.name) { + return { + status: 'error', + message: 'Missing required fields: id, type, and name are required', + } + } + + // Check if user already exists + const existingUser = await fastify.query.selectOneQuery('humans', { id: req.body.id }) + + if (existingUser) { + return { + status: 'error', + message: 'User already exists', + } + } + + // Create new user + const newUser = { + id: req.body.id, + type: req.body.type || 'discord:user', + name: req.body.name, + enabled: req.body.enabled || 1, + area: req.body.area || '[]', + latitude: req.body.latitude || 0.0, + longitude: req.body.longitude || 0.0, + admin_disable: req.body.admin_disable || 0, + language: req.body.language || 'en', + community_membership: '[]', + area_restriction: null, + notes: req.body.notes || null, + } + + // Handle community membership + if (req.body.community) { + newUser.community_membership = JSON.stringify([req.body.community.toLowerCase()]) + newUser.area_restriction = JSON.stringify(communityLogic.calculateLocationRestrictions(fastify.config, [req.body.community])) + } + + await fastify.query.insertQuery('humans', newUser) + + return { + status: 'ok', + message: 'User created successfully', + human: newUser, + } + }) } From 27e0d91c08362c13801b39d86fb4bcbc829986de Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Tue, 7 Oct 2025 13:59:50 +0200 Subject: [PATCH 06/11] fix(api): user create validate --- src/routes/apiHumans.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/apiHumans.js b/src/routes/apiHumans.js index 66d848c77..d608c7dcd 100644 --- a/src/routes/apiHumans.js +++ b/src/routes/apiHumans.js @@ -549,10 +549,10 @@ module.exports = async (fastify, options) => { } // Validate required fields - if (!req.body.id || !req.body.type || !req.body.name) { + if (!req.body.id || !req.body.name) { return { status: 'error', - message: 'Missing required fields: id, type, and name are required', + message: 'Missing required fields: id and name are required', } } From b24e1320d76a35df107f5a12ad40fb41cec13f14 Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:00:37 +0200 Subject: [PATCH 07/11] fix(api): user create validate --- src/routes/apiHumans.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/apiHumans.js b/src/routes/apiHumans.js index d608c7dcd..dceef8802 100644 --- a/src/routes/apiHumans.js +++ b/src/routes/apiHumans.js @@ -579,7 +579,7 @@ module.exports = async (fastify, options) => { language: req.body.language || 'en', community_membership: '[]', area_restriction: null, - notes: req.body.notes || null, + notes: req.body.notes || '', } // Handle community membership From 192ae5cf532f19d4a46dbfb6b6e47ef699c22473 Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:08:09 +0200 Subject: [PATCH 08/11] feat(api): user create def profile --- src/routes/apiHumans.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/routes/apiHumans.js b/src/routes/apiHumans.js index dceef8802..e0ceb3d8d 100644 --- a/src/routes/apiHumans.js +++ b/src/routes/apiHumans.js @@ -590,6 +590,23 @@ module.exports = async (fastify, options) => { await fastify.query.insertQuery('humans', newUser) + // Handle profile creation if profile_name is provided + if (req.body.profile_name && req.body.profile_name !== '') { + const existingProfile = await fastify.query.selectOneQuery('profiles', { id: req.body.id, profile_no: 1 }) + + if (!existingProfile) { + await fastify.query.insertQuery('profiles', { + id: req.body.id, + profile_no: 1, + name: req.body.profile_name, + area: '[]', + latitude: 0.0, + longitude: 0.0, + active_hours: '[]', + }) + } + } + return { status: 'ok', message: 'User created successfully', From 630bc50e07702194362219b7a9916f5a8ea87af0 Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Mon, 17 Nov 2025 18:17:30 +0100 Subject: [PATCH 09/11] feat: api/humans - admin_disabled route --- src/routes/apiHumans.js | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/routes/apiHumans.js b/src/routes/apiHumans.js index e0ceb3d8d..e98b70bef 100644 --- a/src/routes/apiHumans.js +++ b/src/routes/apiHumans.js @@ -512,6 +512,50 @@ module.exports = async (fastify, options) => { } }) + fastify.post('/api/humans/:id/adminDisabled', 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` } + + const secret = req.headers['x-poracle-secret'] + if (!secret || !fastify.config.server.apiSecret || secret !== fastify.config.server.apiSecret) { + return { status: 'authError', reason: 'incorrect or missing api secret' } + } + + const human = await fastify.query.selectOneQuery('humans', { id: req.params.id }) + + if (!human) { + return { + status: 'error', + message: 'User not found', + } + } + + // Validate the state parameter + if (req.body.state === undefined || req.body.state === null) { + return { + status: 'error', + message: 'Missing required field: state', + } + } + + const adminDisabledState = req.body.state ? 1 : 0 + + await fastify.query.updateQuery( + 'humans', + { + admin_disable: adminDisabledState, + }, + { id: req.params.id }, + ) + + return { + status: 'ok', + admin_disabled: adminDisabledState, + } + }) + fastify.get('/api/humans/one/:id', options, async (req) => { fastify.logger.info(`API: ${req.ip} ${req.routeOptions.method} ${req.routeOptions.url}`) From db2225311e7d2d6585e78515a0ef0f7c338f017f Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Mon, 17 Nov 2025 18:31:24 +0100 Subject: [PATCH 10/11] feat: api/humans - admin_disabled update disabledDate --- src/app.js | 4 ++-- src/controllers/controller.js | 2 +- src/controllers/query.js | 2 +- src/controllers/weather.js | 2 +- src/controllers/weatherData.js | 2 +- src/init/initConfig.js | 4 ++-- src/init/migrateV3.js | 2 +- src/lib/cachingGeocoder.js | 4 ++-- src/lib/discord/commando/commands/autocreate.js | 2 +- src/lib/discord/commando/index.js | 4 ++-- src/lib/dtsloader.js | 2 +- src/lib/geofenceLoader.js | 2 +- src/lib/partials.js | 2 +- src/lib/poracleMessage/commands/broadcast.js | 2 +- src/lib/poracleMessage/commands/poracle-test.js | 2 +- src/lib/telegram/Telegram.js | 2 +- src/routes/apiHumans.js | 2 ++ 17 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/app.js b/src/app.js index 8af68ca22..c1390c622 100644 --- a/src/app.js +++ b/src/app.js @@ -6,8 +6,9 @@ const { writeHeapSnapshot } = require('v8') const fs = require('fs') const util = require('util') -const { S2 } = require('s2-geometry') const { Worker, MessageChannel } = require('worker_threads') +const path = require('path') +const { S2 } = require('s2-geometry') const NodeCache = require('node-cache') const pcache = require('flat-cache') const fastify = require('fastify')({ @@ -17,7 +18,6 @@ const fastify = require('fastify')({ const stringify = require('fast-json-stable-stringify') const { Telegraf } = require('telegraf') const Ohbem = require('ohbem') -const path = require('path') const chokidar = require('chokidar') const moment = require('moment-timezone') const geoTz = require('geo-tz') diff --git a/src/controllers/controller.js b/src/controllers/controller.js index 6df472859..bd94c8b0b 100644 --- a/src/controllers/controller.js +++ b/src/controllers/controller.js @@ -1,7 +1,7 @@ -const inside = require('point-in-polygon') const EventEmitter = require('events') const path = require('path') const fs = require('fs') +const inside = require('point-in-polygon') const Uicons = require('../lib/uicons') const TileserverPregen = require('../lib/tileserverPregen') const replaceAsync = require('../util/stringReplaceAsync') diff --git a/src/controllers/query.js b/src/controllers/query.js index 3edcf9cdd..d495e5561 100644 --- a/src/controllers/query.js +++ b/src/controllers/query.js @@ -1,6 +1,6 @@ +const cp = require('child_process') const inside = require('point-in-polygon') const NodeGeocoder = require('node-geocoder') -const cp = require('child_process') const TileserverPregen = require('../lib/tileserverPregen') class Query { diff --git a/src/controllers/weather.js b/src/controllers/weather.js index 09e9f158d..a14e6f01b 100644 --- a/src/controllers/weather.js +++ b/src/controllers/weather.js @@ -1,8 +1,8 @@ +const path = require('path') const moment = require('moment-timezone') const axios = require('axios') const { S2 } = require('s2-geometry') const S2ts = require('nodes2ts') -const path = require('path') const pcache = require('flat-cache') const { Mutex } = require('async-mutex') require('moment-precise-range-plugin') diff --git a/src/controllers/weatherData.js b/src/controllers/weatherData.js index 5460c6036..13315fd96 100644 --- a/src/controllers/weatherData.js +++ b/src/controllers/weatherData.js @@ -1,7 +1,7 @@ -const { S2 } = require('s2-geometry') const EventEmitter = require('events') const path = require('path') +const { S2 } = require('s2-geometry') const pcache = require('flat-cache') const weatherCache = pcache.load('weatherCache', path.join(__dirname, '../../.cache')) diff --git a/src/init/initConfig.js b/src/init/initConfig.js index e15dc6df7..4b9fcac1d 100644 --- a/src/init/initConfig.js +++ b/src/init/initConfig.js @@ -1,7 +1,7 @@ -const config = require('config') const path = require('path') -const reader = require('readline-sync') const fs = require('fs') +const config = require('config') +const reader = require('readline-sync') const { log } = require('../lib/logger') const discordRe = /[ODMN][A-Za-z\d]{23}\.[\w-]{6}\.[\w-]{27}/g diff --git a/src/init/migrateV3.js b/src/init/migrateV3.js index cb6e0d314..4dd895d87 100644 --- a/src/init/migrateV3.js +++ b/src/init/migrateV3.js @@ -1,6 +1,6 @@ +const path = require('path') const Knex = require('knex') const config = require('config') -const path = require('path') const reader = require('readline-sync') const { log } = require('../lib/logger') const Daptcha = require('./daptcha') diff --git a/src/lib/cachingGeocoder.js b/src/lib/cachingGeocoder.js index 70cb299ba..d4ddf4165 100644 --- a/src/lib/cachingGeocoder.js +++ b/src/lib/cachingGeocoder.js @@ -1,9 +1,9 @@ /* eslint-disable max-classes-per-file */ +const { performance } = require('perf_hooks') +const path = require('path') const NodeGeocoder = require('node-geocoder') const pcache = require('flat-cache') -const { performance } = require('perf_hooks') const emojiFlags = require('country-code-emoji') -const path = require('path') const NominatimGeocoder = require('./nominatimGeocoder') class NominatimGeocoderConverter extends NominatimGeocoder { diff --git a/src/lib/discord/commando/commands/autocreate.js b/src/lib/discord/commando/commands/autocreate.js index 94fa532a9..6836505ff 100644 --- a/src/lib/discord/commando/commands/autocreate.js +++ b/src/lib/discord/commando/commands/autocreate.js @@ -1,6 +1,6 @@ -const stripJsonComments = require('strip-json-comments') const fs = require('fs') const path = require('path') +const stripJsonComments = require('strip-json-comments') const { Permissions } = require('discord.js') const PoracleDiscordMessage = require('../../poracleDiscordMessage') const PoracleDiscordState = require('../../poracleDiscordState') diff --git a/src/lib/discord/commando/index.js b/src/lib/discord/commando/index.js index 571cb0d80..8645bddee 100644 --- a/src/lib/discord/commando/index.js +++ b/src/lib/discord/commando/index.js @@ -1,10 +1,10 @@ +const { EventEmitter } = require('events') +const fs = require('fs') const { Client, Intents, Options, } = require('discord.js') -const { EventEmitter } = require('events') -const fs = require('fs') const { S2 } = require('s2-geometry') const mustache = require('handlebars') const hastebin = require('hastebin-gen') diff --git a/src/lib/dtsloader.js b/src/lib/dtsloader.js index 187ed6a3f..dea64ae8b 100644 --- a/src/lib/dtsloader.js +++ b/src/lib/dtsloader.js @@ -1,6 +1,6 @@ -const stripJsonComments = require('strip-json-comments') const path = require('path') const fs = require('fs') +const stripJsonComments = require('strip-json-comments') function readDtsFiles() { let localDts = [] diff --git a/src/lib/geofenceLoader.js b/src/lib/geofenceLoader.js index 6e031eb7e..d74296117 100644 --- a/src/lib/geofenceLoader.js +++ b/src/lib/geofenceLoader.js @@ -1,6 +1,6 @@ -const stripJsonComments = require('strip-json-comments') const fs = require('fs') const path = require('path') +const stripJsonComments = require('strip-json-comments') const RBush = require('rbush') const { log } = require('./logger') diff --git a/src/lib/partials.js b/src/lib/partials.js index c8f680099..fa28ea366 100644 --- a/src/lib/partials.js +++ b/src/lib/partials.js @@ -1,6 +1,6 @@ -const stripJsonComments = require('strip-json-comments') const fs = require('fs') const path = require('path') +const stripJsonComments = require('strip-json-comments') function registerPartials(handlebars) { const filename = path.join(__dirname, '../../config/partials.json') diff --git a/src/lib/poracleMessage/commands/broadcast.js b/src/lib/poracleMessage/commands/broadcast.js index 4303eb448..9e2f901a9 100644 --- a/src/lib/poracleMessage/commands/broadcast.js +++ b/src/lib/poracleMessage/commands/broadcast.js @@ -1,6 +1,6 @@ -const stripJsonComments = require('strip-json-comments') const fs = require('fs') const path = require('path') +const stripJsonComments = require('strip-json-comments') exports.run = async (client, msg, args, options) => { try { diff --git a/src/lib/poracleMessage/commands/poracle-test.js b/src/lib/poracleMessage/commands/poracle-test.js index c65b08c1b..aeb285b4e 100644 --- a/src/lib/poracleMessage/commands/poracle-test.js +++ b/src/lib/poracleMessage/commands/poracle-test.js @@ -1,6 +1,6 @@ -const stripJsonComments = require('strip-json-comments') const fs = require('fs') const path = require('path') +const stripJsonComments = require('strip-json-comments') const geoTz = require('geo-tz') const moment = require('moment-timezone') diff --git a/src/lib/telegram/Telegram.js b/src/lib/telegram/Telegram.js index 3285ffc84..cedec9f05 100644 --- a/src/lib/telegram/Telegram.js +++ b/src/lib/telegram/Telegram.js @@ -1,9 +1,9 @@ const { EventEmitter } = require('events') const fs = require('fs') const fsp = require('fs').promises +const { performance } = require('perf_hooks') const NodeCache = require('node-cache') const mustache = require('handlebars') -const { performance } = require('perf_hooks') const emojiStrip = require('../../util/emojiStrip') const FairPromiseQueue = require('../FairPromiseQueue') diff --git a/src/routes/apiHumans.js b/src/routes/apiHumans.js index e98b70bef..60956b62d 100644 --- a/src/routes/apiHumans.js +++ b/src/routes/apiHumans.js @@ -541,11 +541,13 @@ module.exports = async (fastify, options) => { } const adminDisabledState = req.body.state ? 1 : 0 + const disabledDate = adminDisabledState === 1 ? fastify.query.dbNow() : null await fastify.query.updateQuery( 'humans', { admin_disable: adminDisabledState, + disabled_date: disabledDate, }, { id: req.params.id }, ) From 6f969c2094d11c5e809fe29fdc6a60a41b9acc37 Mon Sep 17 00:00:00 2001 From: lenisko <10072920+lenisko@users.noreply.github.com> Date: Tue, 16 Dec 2025 04:33:14 +0100 Subject: [PATCH 11/11] fix: accuweather --- src/controllers/weather.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/controllers/weather.js b/src/controllers/weather.js index a14e6f01b..2307f6063 100644 --- a/src/controllers/weather.js +++ b/src/controllers/weather.js @@ -176,10 +176,14 @@ class Weather extends Controller { if (apiKeyWeatherLocation) { try { // Fetch location information - const url = `https://dataservice.accuweather.com/locations/v1/cities/geoposition/search?apikey=${apiKeyWeatherLocation}&q=${latlng.lat}%2C${latlng.lng}` + const url = `https://dataservice.accuweather.com/locations/v1/cities/geoposition/search?q=${latlng.lat}%2C${latlng.lng}` this.log.debug(`${id}: Fetching AccuWeather location ${url}`) - const weatherLocation = await axios.get(url) + const weatherLocation = await axios.get(url, { + headers: { + Authorization: `Bearer ${apiKeyWeatherLocation}`, + }, + }) data.location = weatherLocation.data.Key } catch (err) { this.log.error(`${id}: Fetching AccuWeather location errored with: ${err}`) @@ -209,11 +213,15 @@ class Weather extends Controller { if (apiKeyWeatherInfo) { try { // Fetch new weather information - const url = `https://dataservice.accuweather.com/forecasts/v1/hourly/12hour/${data.location}?apikey=${apiKeyWeatherInfo}&details=true&metric=true` + const url = `https://dataservice.accuweather.com/forecasts/v1/hourly/12hour/${data.location}?details=true&metric=true` this.log.debug(`${id}: Fetching AccuWeather Forecast ${url}`) let logString = '' - const weatherInfo = await axios.get(url) + const weatherInfo = await axios.get(url, { + headers: { + Authorization: `Bearer ${apiKeyWeatherInfo}`, + }, + }) for (const forecast in Object.entries(weatherInfo.data)) { if (weatherInfo.data[forecast].EpochDateTime > currentHourTimestamp) { const pogoWeather = this.mapPoGoWeather(weatherInfo.data[forecast])