From 098b6ba4e9b83b4b2fde627be19042848e47b027 Mon Sep 17 00:00:00 2001 From: Adam Wisher <37659188+mrwish7@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:18:06 +0100 Subject: [PATCH] Fix PS exact match and update TX DB every 7 days --- server/console.js | 6 +++--- server/index.js | 8 ++++---- server/tx_search.js | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/server/console.js b/server/console.js index 4c4397f..d0bbde0 100644 --- a/server/console.js +++ b/server/console.js @@ -30,10 +30,10 @@ const getCurrentTime = () => { const removeANSIEscapeCodes = (str) => str.replace(ANSI_ESCAPE_CODE_PATTERN, ''); // Strip ANSI escape codes from a string -const logMessage = (type, messages, verbose = false) => { +const logMessage = (type, messages) => { const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX[type]} ${messages.join(' ')}`; - if (type === 'DEBUG' && verboseMode || type === 'FFMPEG' && verboseModeFfmpeg || type !== 'DEBUG' && type !== 'FFMPEG') { + if ((type === 'DEBUG' && verboseMode) || (type === 'FFMPEG' && verboseModeFfmpeg) || type !== 'DEBUG' && type !== 'FFMPEG') { logs.push(logMessage); if (logs.length > maxConsoleLogLines) logs.shift(); console.log(logMessage); @@ -42,7 +42,7 @@ const logMessage = (type, messages, verbose = false) => { if(type !== 'FFMPEG') appendLogToBuffer(logMessage); }; -const logDebug = (...messages) => logMessage('DEBUG', messages, verboseMode); +const logDebug = (...messages) => logMessage('DEBUG', messages); const logChat = (message) => logMessage('CHAT', [`${message.nickname} (${message.ip}) sent a chat message: ${message.message}`]); const logError = (...messages) => logMessage('ERROR', messages); const logFfmpeg = (...messages) => logMessage('FFMPEG', messages, verboseModeFfmpeg); diff --git a/server/index.js b/server/index.js index 11b1ed8..a3e3d91 100644 --- a/server/index.js +++ b/server/index.js @@ -81,11 +81,11 @@ const terminalWidth = readline.createInterface({ // Couldn't get figlet.js or something like that? console.log(`\x1b[32m - _____ __ __ ______ __ __ __ _ -| ___| \\/ | | _ \\ \\/ / \\ \\ / /__| |__ ___ ___ _ ____ _____ _ __ + _____ __ __ ______ __ __ __ _ +| ___| \\/ | | _ \\ \\/ / \\ \\ / /__| |__ ___ ___ _ ____ _____ _ __ | |_ | |\\/| |_____| | | \\ / \\ \\ /\\ / / _ \\ '_ \\/ __|/ _ \\ '__\\ \\ / / _ \\ '__| -| _| | | | |_____| |_| / \\ \\ V V / __/ |_) \\__ \\ __/ | \\ V / __/ | -|_| |_| |_| |____/_/\\_\\ \\_/\\_/ \\___|_.__/|___/\\___|_| \\_/ \\___|_| +| _| | | | |_____| |_| / \\ \\ V V / __/ |_) \\__ \\ __/ | \\ V / __/ | +|_| |_| |_| |____/_/\\_\\ \\_/\\_/ \\___|_.__/|___/\\___|_| \\_/ \\___|_| `); console.log('\x1b[32m\x1b[2mby Noobish @ \x1b[4mFMDX.org\x1b[0m'); console.log("v" + pjson.version) diff --git a/server/tx_search.js b/server/tx_search.js index 09dc781..753dbc6 100644 --- a/server/tx_search.js +++ b/server/tx_search.js @@ -3,6 +3,9 @@ const { serverConfig } = require('./server_config'); const consoleCmd = require('./console'); let localDb = {}; +let nextLocalDbUpdate = 0; +const localDbUpdateInterval = 7 * 24 * 60 * 60 * 1000; // 7-day database update interval +let awaitingTxInfo = true; let lastFetchTime = 0; let piFreqIndex = {}; // Indexing for speedier PI+Freq combinations const fetchInterval = 1000; @@ -71,7 +74,7 @@ if (serverConfig.identification.gpsMode) { // Function to build local TX database from FMDX Maps endpoint. async function buildTxDatabase() { if (Latitude.length > 0 && Longitude.length > 0) { - let awaitingTxInfo = true; + awaitingTxInfo = true; while (awaitingTxInfo) { try { consoleCmd.logInfo('Fetching transmitter database...'); @@ -240,6 +243,10 @@ async function fetchTx(freq, piCode, rdsPs) { let match = null; let multiMatches = []; const now = Date.now(); + if (now > nextLocalDbUpdate && !awaitingTxInfo) { + consoleCmd.logInfo('Time to update transmitter database.'); + buildTxDatabase(); + } freq = parseFloat(freq); if ( @@ -265,6 +272,15 @@ async function fetchTx(freq, piCode, rdsPs) { stations: [station] })); + if (filteredLocations.length > 1) { + const extraFilteredLocations = filteredLocations.map(locData => ({ + ...locData, + stations: locData.stations.filter(station => (station.ps.toLowerCase() === rdsPs.replace(/ /g, '_').toLowerCase())) + })).filter(locData => locData.stations.length > 0); + + if (extraFilteredLocations.length > 0) filteredLocations = extraFilteredLocations; + } + // Only check PS if we have more than one match. if (filteredLocations.length > 1) { filteredLocations = filteredLocations.map(locData => ({