From f1abaa22be45cbf714d7e8d1e78038df48a9f4f7 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Wed, 30 Oct 2019 14:13:05 +0100 Subject: [PATCH] loading stuff. config.js is now without numbers again and should survive updates --- 88-tar1090.conf | 5 +++ README.md | 8 ++-- html/early.js | 110 ++++++++++++++++++++++++++------------------- html/index.html | 11 ++--- html/script.js | 10 ++--- install.sh | 4 +- nginx.conf | 3 ++ nginx_webroot.conf | 3 ++ 8 files changed, 92 insertions(+), 62 deletions(-) diff --git a/88-tar1090.conf b/88-tar1090.conf index c3b54f5..0df342b 100644 --- a/88-tar1090.conf +++ b/88-tar1090.conf @@ -47,6 +47,11 @@ $HTTP["url"] =~ "^/INSTANCE/.*\.js$" { "Cache-Control" => "public, max-age=31536000", ) } +$HTTP["url"] =~ "^/INSTANCE/config.js$" { + setenv.add-response-header += ( + "Cache-Control" => "must-revalidate", + ) +} $HTTP["url"] =~ "^/INSTANCE/.*\.css$" { setenv.add-response-header += ( "Cache-Control" => "public, max-age=31536000", diff --git a/README.md b/README.md index 9453c5d..6275f18 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ The duration of the history in seconds can be calculated as interval times histo ## Configuring the web interface (optional): ``` -sudo nano /usr/local/share/tar1090/html/config*.js +sudo nano /usr/local/share/tar1090/html/config.js ``` Ctrl-x to exit, y (yes) and enter to save. @@ -55,11 +55,11 @@ Then Ctrl-F5 to refresh the web interface in the browser. ``` # ENABLE: -sudo sed -i -e 's?.*flightawareLinks.*?flightawareLinks = true;?' /usr/local/share/tar1090/html/config*.js +sudo sed -i -e 's?.*flightawareLinks.*?flightawareLinks = true;?' /usr/local/share/tar1090/html/config.js # ENABLE if the above doesn't work (updated from previous version) -echo 'flightawareLinks = true;' | sudo tee -a /usr/local/share/tar1090/html/config*.js +echo 'flightawareLinks = true;' | sudo tee -a /usr/local/share/tar1090/html/config.js # DISABLE: -sudo sed -i -e 's?.*flightawareLinks.*?flightawareLinks = false;?' /usr/local/share/tar1090/html/config*.js +sudo sed -i -e 's?.*flightawareLinks.*?flightawareLinks = false;?' /usr/local/share/tar1090/html/config.js ``` Then Ctrl-F5 to refresh the web interface in the browser. diff --git a/html/early.js b/html/early.js index bfec46e..c36e523 100644 --- a/html/early.js +++ b/html/early.js @@ -6,61 +6,56 @@ var enable_uat = false; var enable_pf_data = false; var HistoryChunks = false; var nHistoryItems = 0; +var nChunks = 0; var HistoryItemsReturned = 0; var chunkNames; var PositionHistoryBuffer = []; var receiverJson; var deferHistory = []; var configureReceiver = $.Deferred(); +var historyTimeout = 60; // get configuration json files, will be used in initialize function -var get_receiver_defer = $.ajax({ url: 'data/receiver.json', - timeout: 15000, - cache: false, - dataType: 'json' -}); var test_chunk_defer = $.ajax({ url:'chunks/chunks.json', timeout: 10000, cache: false, dataType: 'json' }); - - -$.when(get_receiver_defer).done(function(data){ - get_receiver_defer = null; - receiverJson = data; - Dump1090Version = data.version; - RefreshInterval = data.refresh; - nHistoryItems = data.history; - - $.when(test_chunk_defer).done(function(data) { - test_chunk_defer = null; - HistoryChunks = true; - chunkNames = data.chunks; - nHistoryItems = chunkNames.length; - enable_uat = (data.enable_uat == "true"); - enable_pf_data = (data.pf_data == "true"); - if (enable_uat) - console.log("UAT/978 enabled!"); - console.log("Chunks enabled"); - get_history(); - }).fail(function() { - HistoryChunks = false; - get_history(); - }); +var get_receiver_defer = $.ajax({ url: 'data/receiver.json', + timeout: 15000, + cache: false, + dataType: 'json' }); + +$.when(test_chunk_defer).done(function(data) { + test_chunk_defer = null; + HistoryChunks = true; + chunkNames = data.chunks; + nChunks = chunkNames.length; + enable_uat = (data.enable_uat == "true"); + enable_pf_data = (data.pf_data == "true"); + if (enable_uat) + console.log("UAT/978 enabled!"); + console.log("Chunks enabled"); + get_history(); +}).fail(function() { + HistoryChunks = false; + get_history(); +}); + +$.ajax({ url: 'data/aircraft.json', + timeout: historyTimeout-2, + cache: false, + dataType: 'json' }).done(function(data) { + if (HistoryItemsReturned < nHistoryItems) { + PositionHistoryBuffer.push(data); + } + }); + function get_history() { - $.ajax({ url: 'data/aircraft.json', - timeout: historyTimeout-2, - cache: false, - dataType: 'json' }).done(function(data) { - if (HistoryItemsReturned < nHistoryItems) { - PositionHistoryBuffer.push(data); - } - }); if (enable_uat) { $.ajax({ url: 'chunks/978.json', timeout: historyTimeout-2, @@ -72,15 +67,40 @@ function get_history() { }); } - if (nHistoryItems > 0) { - console.log("Starting to load history (" + nHistoryItems + " items)"); - console.time("Downloaded History"); - // Queue up the history file downloads - for (var i = nHistoryItems-1; i >= 0; i--) { - get_history_item(i); + if (HistoryChunks) { + if (nChunks > 0) { + console.log("Starting to load history (" + nChunks + " chunks)"); + console.time("Downloaded History"); + for (var i = nChunks-1; i >= 0; i--) { + get_history_item(i); + } } + $.when(get_receiver_defer).done(function(data){ + get_receiver_defer = null; + receiverJson = data; + Dump1090Version = data.version; + RefreshInterval = data.refresh; + nHistoryItems = nChunks; + configureReceiver.resolve(); + }); + } else { + $.when(get_receiver_defer).done(function(data){ + get_receiver_defer = null; + receiverJson = data; + Dump1090Version = data.version; + RefreshInterval = data.refresh; + nHistoryItems = data.history; + if (nHistoryItems > 0) { + console.log("Starting to load history (" + nHistoryItems + " items)"); + console.time("Downloaded History"); + // Queue up the history file downloads + for (var i = nHistoryItems-1; i >= 0; i--) { + get_history_item(i); + } + } + configureReceiver.resolve(); + }); } - configureReceiver.resolve(); } function get_history_item(i) { @@ -89,7 +109,7 @@ function get_history_item(i) { if (HistoryChunks) { request = $.ajax({ url: 'chunks/' + chunkNames[i], - timeout: (i > nHistoryItems-5 ? historyTimeout*3 : historyTimeout) * 1000, // timeout magic + timeout: historyTimeout * 1000, dataType: 'json' }); } else { diff --git a/html/index.html b/html/index.html index 646088f..dd0ec5a 100644 --- a/html/index.html +++ b/html/index.html @@ -5,18 +5,19 @@ + + + - - - - - + + + diff --git a/html/script.js b/html/script.js index 0d3ceb3..0d8c6e4 100644 --- a/html/script.js +++ b/html/script.js @@ -91,11 +91,6 @@ var layers_group; // piaware vs flightfeeder var isFlightFeeder = false; -// this will be needed later, get it right when the script is loaded -$.getJSON("db/aircraft_types/icao_aircraft_types.json") - .done(function(typeLookupData) { - _aircraft_type_cache = typeLookupData; - }) function processReceiverUpdate(data, init) { @@ -409,6 +404,11 @@ function initialize() { // Wait for history item downloads and append them to the buffer push_history(); + // this will be needed later + $.getJSON("db/aircraft_types/icao_aircraft_types.json") + .done(function(typeLookupData) { + _aircraft_type_cache = typeLookupData; + }) }); } diff --git a/install.sh b/install.sh index 58e2a15..fedd94d 100755 --- a/install.sh +++ b/install.sh @@ -135,7 +135,7 @@ do # keep some stuff around if [ -f $html_path/defaults_*.js ]; then - cp $html_path/config_*.js /tmp/tar1090_config.js + cp $html_path/config.js /tmp/tar1090_config.js 2>/dev/null || true fi cp $html_path/upintheair.json /tmp/tar1090_upintheair.json 2>/dev/null || true cp $html_path/color*.css /tmp/tar1090_colors.css/ 2>/dev/null || true @@ -164,7 +164,6 @@ do -e "s/planeObject.js/planeObject_$epoch.js/" \ -e "s/registrations.js/registrations_$epoch.js/" \ -e "s/script.js/script_$epoch.js/" \ - -e "s/config.js/config_$epoch.js/" \ -e "s/colors.css/colors_$epoch.css/" \ -e "s/style.css/style_$epoch.css/" \ index.html @@ -179,7 +178,6 @@ do mv planeObject.js planeObject_$epoch.js mv registrations.js registrations_$epoch.js mv script.js script_$epoch.js - mv config.js config_$epoch.js mv colors.css colors_$epoch.css mv style.css style_$epoch.css diff --git a/nginx.conf b/nginx.conf index 09a1dfc..f05b33b 100644 --- a/nginx.conf +++ b/nginx.conf @@ -29,6 +29,9 @@ location /INSTANCE { location ~ .*\.gif$ { add_header Cache-Control "public, max-age=31536000"; } + location ~ config.js$ { + add_header Cache-Control "must-revalidate"; + } location ~ .*\.js$ { add_header Cache-Control "public, max-age=31536000"; } diff --git a/nginx_webroot.conf b/nginx_webroot.conf index f2a4a6b..6f94ec5 100644 --- a/nginx_webroot.conf +++ b/nginx_webroot.conf @@ -28,6 +28,9 @@ location / { location ~ .*\.gif$ { add_header Cache-Control "public, max-age=31536000"; } + location ~ config.js$ { + add_header Cache-Control "must-revalidate"; + } location ~ .*\.js$ { add_header Cache-Control "public, max-age=31536000"; }