Skip to content

Commit a57ebab

Browse files
committed
added new api endpoint
added new api endpoint `getBMPByID_v2`
1 parent eed15eb commit a57ebab

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Install dependencies with `npm install` and run dev server with `npn run dev`.
5555

5656
## Changelog
5757

58+
### 1.8.8 (2025-12-28)
59+
- (o0shojo0o) added new api endpoint `getBMPByID_v2` for better handling of animated bitmaps
60+
5861
### 1.8.7 (2024-10-07)
5962

6063
- (o0shojo0o) add uuid to each request

libs/pixelItRepo.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const connection = mysql.createPool({
1616
});
1717

1818
async function getBMPByID(id) {
19-
let result
19+
let result;
2020
try {
2121
result = await connection.query(
2222
`select
@@ -36,10 +36,10 @@ async function getBMPByID(id) {
3636
where
3737
a.id = ?`,
3838
id
39-
)
39+
);
4040
if (result[0][0]) {
41-
result[0][0].animated = tools.mysqlToBool(result[0][0].animated)
42-
return result[0][0]
41+
result[0][0].animated = tools.mysqlToBool(result[0][0].animated);
42+
return result[0][0];
4343
}
4444

4545
} catch (error) {
@@ -48,6 +48,23 @@ async function getBMPByID(id) {
4848
}
4949
};
5050

51+
async function getBMPByID_v2(id) {
52+
let result;
53+
try {
54+
result = await getBMPByID(id);
55+
if (result) {
56+
if (result.animated == true) {
57+
result.rgb565array = `[${result.rgb565array}]`;
58+
}
59+
return result;
60+
}
61+
62+
} catch (error) {
63+
log.error('getBMPByID_v2: {error}', { error: error })
64+
return undefined
65+
}
66+
};
67+
5168
async function getBMPAll() {
5269
let result
5370
try {
@@ -229,6 +246,7 @@ async function getStatistics() {
229246

230247
module.exports = {
231248
getBMPByID,
249+
getBMPByID_v2,
232250
getBMPAll,
233251
getBMPNewst,
234252
saveTelemetry,

main.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ app.get('/api/GetBMPByID/:id', async (req, res) => {
5151
res.send(bmp);
5252
});
5353

54+
app.get('/api/GetBMPByID_v2/:id', async (req, res) => {
55+
const sourceIP = tools.getIPFromRequest(req);
56+
const rawUrl = tools.getRawURLFromRequest(req);
57+
const id = req.params.id;
58+
const uuid = req.query.uuid || '';
59+
60+
if (tools.isNumeric(id) == false) {
61+
log.warn('{apiPath}: {id} is not a valid ID!', { apiPath: 'GetBMPByID_v2', id, sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, uuid: uuid, });
62+
res.status(400).send('Not valid ID');
63+
return;
64+
}
65+
66+
const bmp = (await cache.getOrSet(`GetBMPByID_v2_${id}`, () => { return repo.getBMPByID(id) }, 0));
67+
68+
if (!bmp) {
69+
log.warn('{apiPath}: BMP ID: {id} is not valide', { apiPath: 'GetBMPByID_v2', id: id, sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, uuid: uuid, });
70+
res.status(400).send(`BMP ID: ${id} is not valide`);
71+
return;
72+
}
73+
74+
log.info('{apiPath}: BMP with ID {id} and name {name} successfully delivered', { apiPath: 'GetBMPByID_v2', id: bmp.id, name: bmp.name, sourceIP, rawUrl, useragent: req.useragent, rateLimit: req.rateLimit, uuid: uuid, });
75+
res.send(bmp);
76+
});
77+
5478
app.get('/api/GetBMPNewst', async (req, res) => {
5579
const sourceIP = tools.getIPFromRequest(req);
5680
const rawUrl = tools.getRawURLFromRequest(req);

0 commit comments

Comments
 (0)