Skip to content
This repository was archived by the owner on Jul 28, 2026. It is now read-only.

Commit 8b3e006

Browse files
committed
refactor: extract hardcoded nest IDs and add cache TTL to nodeCache
- Move hardcoded nest IDs [5,6,7] from services/pyrodactyl.js to config/pyrodactyl.js as NEST_IDS for better maintainability - Add 5-minute TTL to nodeCache to prevent stale node data from being served indefinitely after panel configuration changes
1 parent eb1cb3b commit 8b3e006

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

config/pyrodactyl.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ export const FEATURE_LIMITS = {
1616
};
1717

1818
export const DEPLOY_LOCATIONS = [1];
19+
20+
export const NEST_IDS = [5, 6, 7];

services/pyrodactyl.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { PTERO_URL, PTERO_API_KEY, SERVER_LIMITS, FEATURE_LIMITS, DEPLOY_LOCATIONS } from '../config/pyrodactyl.js';
1+
import { PTERO_URL, PTERO_API_KEY, SERVER_LIMITS, FEATURE_LIMITS, DEPLOY_LOCATIONS, NEST_IDS } from '../config/pyrodactyl.js';
22

33
const FETCH_TIMEOUT = 15000;
4+
const CACHE_TTL = 5 * 60 * 1000;
45
const nodeCache = new Map();
56

67
async function fetchWithTimeout(url, options = {}, timeout = FETCH_TIMEOUT) {
@@ -65,10 +66,13 @@ export async function getPteroUserById(id) {
6566
}
6667

6768
async function getNode(nodeId) {
68-
if (nodeCache.has(nodeId)) return nodeCache.get(nodeId);
69+
if (nodeCache.has(nodeId)) {
70+
const cached = nodeCache.get(nodeId);
71+
if (Date.now() - cached.ts < CACHE_TTL) return cached.data;
72+
}
6973
const data = await pteroFetch(`/nodes/${nodeId}`);
7074
const node = data.attributes;
71-
nodeCache.set(nodeId, node);
75+
nodeCache.set(nodeId, { data: node, ts: Date.now() });
7276
return node;
7377
}
7478

@@ -232,7 +236,7 @@ export async function deletePteroUser(userId) {
232236
export async function getAllEggs() {
233237
const eggs = [];
234238

235-
for (const nestId of [5, 6, 7]) {
239+
for (const nestId of NEST_IDS) {
236240
try {
237241
const nestData = await pteroFetch(`/nests/${nestId}/eggs`);
238242
for (const e of nestData.data) {

0 commit comments

Comments
 (0)