Compare commits
3 Commits
v2.0.0
...
2edf100fca
| Author | SHA1 | Date | |
|---|---|---|---|
| 2edf100fca | |||
| f7523ae5e2 | |||
| 024a43e20b |
@@ -42,7 +42,7 @@ async function run() {
|
|||||||
// scheduled running
|
// scheduled running
|
||||||
if (interval === 0) return;
|
if (interval === 0) return;
|
||||||
logger.debug(`Starting interval (${interval}s)...`);
|
logger.debug(`Starting interval (${interval}s)...`);
|
||||||
runInterval(fetchAndIndex, interval * 1000);
|
runInterval(() => fetchAndIndex().catch(handleError), interval * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch(handleError);
|
run().catch(handleError);
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ export async function createIndex(client, index) {
|
|||||||
mappings: {
|
mappings: {
|
||||||
[doctype]: {
|
[doctype]: {
|
||||||
properties: {
|
properties: {
|
||||||
operator: { type: 'keyword' },
|
operator: { type: 'text', fields: { raw: { type: 'keyword' } } },
|
||||||
aircraft: { type: 'text' },
|
aircraft: { type: 'text', fields: { raw: { type: 'keyword' } } },
|
||||||
aircraft_manufacturer: { type: 'keyword' },
|
aircraft_manufacturer: { type: 'keyword' },
|
||||||
transponder: { type: 'keyword' },
|
transponder: { type: 'keyword' },
|
||||||
callsign: { type: 'keyword' },
|
callsign: { type: 'keyword' },
|
||||||
@@ -45,8 +45,8 @@ export async function createIndex(client, index) {
|
|||||||
squawk: { type: 'keyword' },
|
squawk: { type: 'keyword' },
|
||||||
spi: { type: 'boolean' },
|
spi: { type: 'boolean' },
|
||||||
position_source: { type: 'keyword' },
|
position_source: { type: 'keyword' },
|
||||||
from: { type: 'text' },
|
from: { type: 'text', fields: { raw: { type: 'keyword' } } },
|
||||||
to: { type: 'text' },
|
to: { type: 'text', fields: { raw: { type: 'keyword' } } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import fetch from './fetch.mjs';
|
import fetch from './fetch.mjs';
|
||||||
|
|
||||||
|
const formatNumber = str => str && Number(`${str}`.replace(/[^0-9.-]/, ''));
|
||||||
|
const formatString = str => {
|
||||||
|
if (str == null) return 'N/A';
|
||||||
|
if (typeof str !== 'string') return str;
|
||||||
|
return str && str.length && str !== 'undefined' ? str.trim() : 'N/A';
|
||||||
|
};
|
||||||
|
|
||||||
export async function getOpenskyData() {
|
export async function getOpenskyData() {
|
||||||
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
|
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
|
||||||
const res = await fetch.get(`https://opensky-network.org/api/states/all`);
|
const res = await fetch.get(`https://opensky-network.org/api/states/all`);
|
||||||
@@ -25,15 +32,14 @@ export async function getOpenskyData() {
|
|||||||
|
|
||||||
export async function getAdbsExchangeData({ lat, lon, radius }) {
|
export async function getAdbsExchangeData({ lat, lon, radius }) {
|
||||||
const positionSourceMap = ['Unknown', 'Mode-S', 'ADS-B', 'ADS-B', 'ADS-B', 'ADS-B'];
|
const positionSourceMap = ['Unknown', 'Mode-S', 'ADS-B', 'ADS-B', 'ADS-B', 'ADS-B'];
|
||||||
const formatNumber = str => str && Number(`${str}`.replace(/[^0-9.-]/, ''));
|
|
||||||
|
|
||||||
const res = await fetch.get(
|
const res = await fetch.get(
|
||||||
`http://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat=${lat}&lng=${lon}&fDstL=0&fDstU=${radius}`
|
`http://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat=${lat}&lng=${lon}&fDstL=0&fDstU=${radius}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.data.acList.map(rec => ({
|
return res.data.acList.map(rec => ({
|
||||||
transponder: `${rec.Icao}`.toLowerCase(),
|
transponder: formatString(`${rec.Icao}`.toLowerCase()),
|
||||||
callsign: `${rec.Call}`.trim(),
|
callsign: formatString(rec.Call),
|
||||||
origin_country: rec.Cou,
|
origin_country: rec.Cou,
|
||||||
time_position: new Date(rec.PosTime),
|
time_position: new Date(rec.PosTime),
|
||||||
last_contact: new Date(rec.PosTime),
|
last_contact: new Date(rec.PosTime),
|
||||||
@@ -48,10 +54,10 @@ export async function getAdbsExchangeData({ lat, lon, radius }) {
|
|||||||
squawk: rec.Sqk,
|
squawk: rec.Sqk,
|
||||||
spi: false,
|
spi: false,
|
||||||
position_source: positionSourceMap[rec.Trt],
|
position_source: positionSourceMap[rec.Trt],
|
||||||
operator: rec.Op,
|
operator: formatString(rec.Op),
|
||||||
aircraft: rec.Mdl,
|
aircraft: formatString(rec.Mdl),
|
||||||
aircraft_manufacturer: rec.Man,
|
aircraft_manufacturer: formatString(rec.Man),
|
||||||
from: rec.From,
|
from: formatString(rec.From),
|
||||||
to: rec.To,
|
to: formatString(rec.To),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user