You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 22:13:53 +01:00
Fix PS exact match and update TX DB every 7 days
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 => ({
|
||||
|
||||
Reference in New Issue
Block a user