Add openBlocks API
This commit is contained in:
parent
7d1a75b0fb
commit
7ba88939b9
33
index.js
33
index.js
|
@ -612,6 +612,39 @@ app.get("/api/v1/directory", (req, res) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Function to find open number blocks
|
||||||
|
app.get("/api/v1/directory/openBlocks", (req, res) => {
|
||||||
|
const invalidBlocks = [
|
||||||
|
// Emergency number prefixes (112, 911, 999, 110, 117, 119, 113, 191, 111)
|
||||||
|
1120000, 9110000, 9990000, 1100000, 1170000, 1190000, 1130000, 1910000, 1110000
|
||||||
|
]
|
||||||
|
pool.query("SELECT block_start, block_length FROM routes").then((rows) => {
|
||||||
|
const takenBlocks = rows.map(row => {
|
||||||
|
return { start: row.block_start, end: row.block_start + row.block_length };
|
||||||
|
});
|
||||||
|
const openBlocks = [];
|
||||||
|
for (let i = 100000; i <= 9999999; i += 10000) {
|
||||||
|
const blockStart = i;
|
||||||
|
const blockEnd = i + 9999;
|
||||||
|
// Check if block is invalid
|
||||||
|
if (invalidBlocks.includes(blockStart)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Check if block overlaps with any taken blocks
|
||||||
|
const overlap = takenBlocks.some(taken => {
|
||||||
|
return (blockStart <= taken.end && blockEnd >= taken.start);
|
||||||
|
});
|
||||||
|
if (!overlap) {
|
||||||
|
openBlocks.push(blockStart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.json(openBlocks);
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('Error getting open blocks:', err);
|
||||||
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Other public endpoints that need special handling
|
// Other public endpoints that need special handling
|
||||||
discordInviteCache = { time: 0, url: "" };
|
discordInviteCache = { time: 0, url: "" };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue