diff --git a/README.md b/README.md index 5c70adb..8013b77 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,10 @@ Install dependencies with `npm install` and run dev server with `npn run dev`. ## Changelog +### 1.8.1 (2023-11-11) + +- (o0shojo0o) small fixes + ### 1.8.0 (2023-11-11) - (o0shojo0o) only active telemetry users can see statistics diff --git a/libs/pixelItRepo.js b/libs/pixelItRepo.js index 0439fef..1f4f54b 100644 --- a/libs/pixelItRepo.js +++ b/libs/pixelItRepo.js @@ -37,13 +37,14 @@ async function getBMPByID(id) { a.id = ?`, id ) + if (result[0][0]) { + result[0][0].animated = tools.mysqlToBool(result[0][0].animated) + return result[0][0] + } - result[0][0].animated = tools.mysqlToBool(result[0][0].animated) - - return result[0][0] } catch (error) { log.error('getBMPByID: {error}', { error: error }) - return null + return undefined } }; diff --git a/main.js b/main.js index 0031adf..67e4bc3 100644 --- a/main.js +++ b/main.js @@ -38,7 +38,13 @@ app.get('/api/GetBMPByID/:id', async (req, res) => { return; } - const bmp = (await cache.getOrSet(`GetBMPByID_${id}`, () => { return repo.getBMPByID(id) }, 0)) ?? {}; + const bmp = (await cache.getOrSet(`GetBMPByID_${id}`, () => { return repo.getBMPByID(id) }, 0)); + + if (!bmp) { + log.warn('{apiPath}: BMP ID: {id} is not valide', { apiPath: 'GetBMPByID', id: id, sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, }); + res.status(400).send(`BMP ID: ${id} is not valide`); + return; + } log.info('{apiPath}: BMP with ID {id} and name {name} successfully delivered', { apiPath: 'GetBMPByID', id: bmp.id, name: bmp.name, sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, }); res.send(bmp);