diff --git a/88-tar1090.conf b/88-tar1090.conf index 86a6c8f..5303fc3 100644 --- a/88-tar1090.conf +++ b/88-tar1090.conf @@ -39,33 +39,26 @@ $HTTP["url"] =~ "^/INSTANCE/data/aircraft\.json$" { ) } $HTTP["url"] =~ "^/INSTANCE/data/globe_.*" { + compress.filetype = () setenv.add-response-header += ( "Cache-Control" => "public, max-age=0", "Content-Encoding" => "gzip", ) } $HTTP["url"] =~ "^/INSTANCE/data/traces/" { + compress.filetype = () setenv.add-response-header += ( "Cache-Control" => "public, max-age=10", "Content-Encoding" => "gzip", ) } $HTTP["url"] =~ "^/INSTANCE/globe_history/" { + compress.filetype = () setenv.add-response-header += ( "Cache-Control" => "public, max-age=3600", "Content-Encoding" => "gzip", ) } -$HTTP["url"] =~ "^/INSTANCE/data/icao_.*\.json$" { - setenv.add-response-header += ( - "Cache-Control" => "public, max-age=10", - ) -} -$HTTP["url"] =~ "^/INSTANCE/db.*\.json$" { - setenv.add-response-header += ( - "Cache-Control" => "public, max-age=1209600", - ) -} $HTTP["url"] =~ "^/INSTANCE/.*\.png$" { setenv.add-response-header += ( "Cache-Control" => "public, max-age=2419200", @@ -76,12 +69,18 @@ $HTTP["url"] =~ "^/INSTANCE/config.js$" { "Cache-Control" => "public, must-revalidate", ) } - -$HTTP["url"] =~ "^/INSTANCE/.*_.*\.js$" { +$HTTP["url"] =~ "^/INSTANCE/[^/]*\.js$" { setenv.add-response-header += ( "Cache-Control" => "public, max-age=1209600", ) } +$HTTP["url"] =~ "^/INSTANCE/db-.*\.js$" { + compress.filetype = () + setenv.add-response-header += ( + "Cache-Control" => "public, max-age=1209600", + "Content-Encoding" => "gzip", + ) +} $HTTP["url"] =~ "^/INSTANCE/ol/.*$" { setenv.add-response-header += ( "Cache-Control" => "public, max-age=1209600", diff --git a/95-tar1090-otherport.conf b/95-tar1090-otherport.conf index 8928fba..f9b192c 100644 --- a/95-tar1090-otherport.conf +++ b/95-tar1090-otherport.conf @@ -1,8 +1,14 @@ # serve tar1090 directly on port 8504 $SERVER["socket"] == ":8504" { +# redirect the slash-less URL +url.redirect += ( + "^/INSTANCE$" => "/INSTANCE/" +) + alias.url += ( "/INSTANCE/data/" => "SOURCE_DIR/", "/INSTANCE/chunks/" => "/run/SERVICE/", + "/INSTANCE/globe_history/" => "/var/globe_history/", "/INSTANCE/" => "HTMLPATH/" ) @@ -33,25 +39,24 @@ $HTTP["url"] =~ "^/INSTANCE/data/aircraft\.json$" { ) } $HTTP["url"] =~ "^/INSTANCE/data/globe_.*" { + compress.filetype = () setenv.add-response-header += ( "Cache-Control" => "public, max-age=0", "Content-Encoding" => "gzip", ) } $HTTP["url"] =~ "^/INSTANCE/data/traces/" { + compress.filetype = () setenv.add-response-header += ( "Cache-Control" => "public, max-age=10", "Content-Encoding" => "gzip", ) } -$HTTP["url"] =~ "^/INSTANCE/data/icao_.*\.json$" { +$HTTP["url"] =~ "^/INSTANCE/globe_history/" { + compress.filetype = () setenv.add-response-header += ( - "Cache-Control" => "public, max-age=10", - ) -} -$HTTP["url"] =~ "^/INSTANCE/db.*\.json$" { - setenv.add-response-header += ( - "Cache-Control" => "public, max-age=1209600", + "Cache-Control" => "public, max-age=3600", + "Content-Encoding" => "gzip", ) } $HTTP["url"] =~ "^/INSTANCE/.*\.png$" { @@ -59,14 +64,31 @@ $HTTP["url"] =~ "^/INSTANCE/.*\.png$" { "Cache-Control" => "public, max-age=2419200", ) } -$HTTP["url"] =~ "^/INSTANCE/.*\.js$" { +$HTTP["url"] =~ "^/INSTANCE/config.js$" { + setenv.add-response-header += ( + "Cache-Control" => "public, must-revalidate", + ) +} +$HTTP["url"] =~ "^/INSTANCE/[^/]*\.js$" { setenv.add-response-header += ( "Cache-Control" => "public, max-age=1209600", ) } -$HTTP["url"] =~ "^/INSTANCE/config.js$" { +$HTTP["url"] =~ "^/INSTANCE/db-.*\.js$" { + compress.filetype = () setenv.add-response-header += ( - "Cache-Control" => "must-revalidate", + "Cache-Control" => "public, max-age=1209600", + "Content-Encoding" => "gzip", + ) +} +$HTTP["url"] =~ "^/INSTANCE/ol/.*$" { + setenv.add-response-header += ( + "Cache-Control" => "public, max-age=1209600", + ) +} +$HTTP["url"] =~ "^/INSTANCE/jquery/.*$" { + setenv.add-response-header += ( + "Cache-Control" => "public, max-age=1209600", ) } $HTTP["url"] =~ "^/INSTANCE/.*\.css$" { diff --git a/html/dbloader.js b/html/dbloader.js index cd2fc44..907a7a0 100644 --- a/html/dbloader.js +++ b/html/dbloader.js @@ -24,6 +24,12 @@ let _aircraft_cache = {}; let _airport_coords_cache = null; +let _request_count = 0; +let _request_queue = []; +let _request_cache = {}; + +let regCache = null; + function getAircraftData(icao) { let defer = $.Deferred(); if (icao.charAt(0) == '~') { @@ -107,10 +113,6 @@ function lookupIcaoAircraftType(aircraftData, defer) { defer.resolve(aircraftData); } -let _request_count = 0; -let _request_queue = []; -let _request_cache = {}; - function db_ajax(bkey) { let req; @@ -143,6 +145,7 @@ function db_ajax_request_complete() { dataType : 'json' }); ajaxreq.done(function(data) { req.resolve(data); + /* const keys = Object.keys(data); for (let i in keys) { if (keys[i] == 'children') @@ -152,6 +155,7 @@ function db_ajax_request_complete() { //console.log(reg); regCache[reg] = icao; } + */ }); ajaxreq.fail(function(jqxhr, status, error) { if (status == 'timeout') { @@ -166,3 +170,24 @@ function db_ajax_request_complete() { }); } } +/* +function dbLoadAll() { + return $.getJSON(databaseFolder + "/files.js") + .done(function(data) { + for (let i in data) { + const icao = data[i].padEnd(6, 0); + //console.log(icao); + let req = getAircraftData(icao); + req.icao = icao; + req.fail(function(jqXHR,textStatus,errorThrown) { + if (textStatus == 'timeout') { + getAircraftData(this.icao); + console.log('Database load timeout:' + this.icao); + } else { + console.log(this.icao + ': Database load error: ' + textStatus + ' at URL: ' + jqXHR.url); + } + }); + } + }); +} +*/ diff --git a/html/early.js b/html/early.js index cb12071..49ff2d0 100644 --- a/html/early.js +++ b/html/early.js @@ -16,7 +16,6 @@ let historyTimeout = 60; let globeIndex = 0; let binCraft = false; let dbServer = false; -let regCache = {}; let l3harris = false; let heatmap = false; let heatLoaded = 0; @@ -30,6 +29,7 @@ let pTracks = false; let lastTraceGet = 0; let traceRate = 0; let _aircraft_type_cache = null; +let dbLoadedAll = false; let databaseFolder = "db2"; diff --git a/html/planeObject.js b/html/planeObject.js index 92d71e1..4b81446 100644 --- a/html/planeObject.js +++ b/html/planeObject.js @@ -113,8 +113,9 @@ function PlaneObject(icao) { this.wtc = null; + this.regLoaded = false; // request metadata - if (!dbServer) + if (!dbServer && !this.regLoaded) this.getAircraftData(); // military icao ranges @@ -1955,6 +1956,7 @@ PlaneObject.prototype.getAircraftData = function() { let req = getAircraftData(this.icao); req.done(function(data) { + this.regLoaded = true; if (data == null) { //console.log(this.icao + ': Not found in database!'); return; @@ -2480,11 +2482,16 @@ PlaneObject.prototype.setTypeData = function() { this.wtc = typeData.wtc; } PlaneObject.prototype.checkForDB = function(t) { - if (!t) + if (!t) { return; + } if (t.desc) this.typeLong = t.desc; if (t.r) this.registration = t.r; + + if (!t.r && !dbServer && !this.regLoaded) + this.getAircraftData(); + if (t.t) { this.icaoType = t.t; this.setTypeData(); diff --git a/html/script.js b/html/script.js index 03f5a50..62f4ead 100644 --- a/html/script.js +++ b/html/script.js @@ -686,26 +686,6 @@ function initialize() { // Wait for history item downloads and append them to the buffer push_history(); - // this will be needed later - if (!dbServer && !onMobile && !hideButtons && !heatmap) { - $.getJSON(databaseFolder + "/files.js") - .done(function(data) { - for (let i in data) { - const icao = data[i].padEnd(6, 0); - //console.log(icao); - let req = getAircraftData(icao); - req.icao = icao; - req.fail(function(jqXHR,textStatus,errorThrown) { - if (textStatus == 'timeout') { - getAircraftData(this.icao); - console.log('Database load timeout:' + this.icao); - } else { - console.log(this.icao + ': Database load error: ' + textStatus + ' at URL: ' + jqXHR.url); - } - }); - } - }); - } }); let coll = document.getElementsByClassName("collapseButton"); @@ -3180,9 +3160,20 @@ function onSearch(e) { $("#search_input").val(""); $("#search_input").blur(); if (searchTerm) - findPlanes(searchTerm, true, true, true, true); + findPlanes(searchTerm, "byIcao", "byCallsign", "byReg", "byType"); return false; } +/* +function onSearchReg(e) { + e.preventDefault(); + const searchTerm = $("#search_reg_input").val().trim(); + $("#search_reg_input").val(""); + $("#search_reg_input").blur(); + if (searchTerm) + findPlanes(searchTerm, false, false, "byReg", false); + return false; +} +*/ function onResetCallsignFilter(e) { $("#callsign_filter").val(""); @@ -3688,9 +3679,27 @@ function findPlanes(query, byIcao, byCallsign, byReg, byType) { return; query = query.toLowerCase(); let results = []; - if (byReg && regCache[query.toUpperCase()]) { - selectPlaneByHex(regCache[query.toUpperCase()].toLowerCase(), {follow: true}); - return; + if (byReg) { + if (regCache) { + if (regCache[query.toUpperCase()]) { + selectPlaneByHex(regCache[query.toUpperCase()].toLowerCase(), {follow: true}); + return; + } + } else { + let req_url = databaseFolder + "/regIcao.js"; + let req = $.ajax({ url: req_url, + cache: true, + timeout: 10000, + dataType : 'json' + }); + req.done(function(data) { + regCache = data; + if (regCache[query.toUpperCase()]) { + selectPlaneByHex(regCache[query.toUpperCase()].toLowerCase(), {follow: true}); + return; + } + }); + } } for (let i in PlanesOrdered) { const plane = PlanesOrdered[i]; @@ -3963,6 +3972,7 @@ function toggleLargeMode() { function toggleShowTrace() { if (!showTrace) { + dbServer = false; // temporary until i get the traces supplemented with registration data toggleMultiSelect("off"); showTrace = true; toggleFollow(false); diff --git a/install.sh b/install.sh index 88a3042..33e1272 100755 --- a/install.sh +++ b/install.sh @@ -70,7 +70,7 @@ fi { [[ "$1" == "test" ]] && cd "$ipath/git-db" && git rev-parse; } || { cd "$ipath/git-db" &>/dev/null && git fetch --depth 1 origin master && git reset --hard FETCH_HEAD; } || - { rm -rf "$ipath/git-db" && git clone --depth 1 "$db_repo" "$ipath/git-db"; } + { cd && rm -rf "$ipath/git-db" && git clone --depth 1 "$db_repo" "$ipath/git-db"; } if ! cd $ipath/git-db || ! git rev-parse then diff --git a/nginx.conf b/nginx.conf index 761d66d..54d9d7f 100644 --- a/nginx.conf +++ b/nginx.conf @@ -58,8 +58,10 @@ location /INSTANCE { gzip_static on; - location ~ db.*\.json$ { + location ~ db-.*\.js$ { + gzip off; add_header Cache-Control "public, max-age=1209600"; + add_header Content-Encoding "gzip"; } location ~ .*\.png$ { add_header Cache-Control "public, max-age=1209600";