chore: change get-data exports
export a function for the specific opensky data, re-org code
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const api = 'https://opensky-network.org/api';
|
||||
|
||||
export default axios.create({
|
||||
baseURL: api,
|
||||
timeout: 3000,
|
||||
responseType: 'json',
|
||||
headers: {
|
||||
'X-Custom-Header': 'foobar',
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,25 @@
|
||||
import fetch from './fetch.mjs';
|
||||
|
||||
export default async function getData() {
|
||||
const res = await fetch.get('/states/all');
|
||||
return res.data.states;
|
||||
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
|
||||
|
||||
export async function getOpenskyData() {
|
||||
const res = await fetch.get(`https://opensky-network.org/api/states/all`);
|
||||
return res.data.states.map(rec => ({
|
||||
transponder: `${rec[0]}`.toLowerCase(),
|
||||
callsign: `${rec[1]}`.trim(),
|
||||
origin_country: rec[2],
|
||||
time_position: new Date(rec[3] * 1000),
|
||||
last_contact: new Date(rec[4] * 1000),
|
||||
location: rec[5] && rec[6] ? `${rec[6]},${rec[5]}` : null,
|
||||
lat: rec[6],
|
||||
lon: rec[5],
|
||||
baro_altitude: rec[7],
|
||||
geo_altitude: rec[13],
|
||||
on_ground: rec[8],
|
||||
velocity: rec[9],
|
||||
vertical_rate: rec[11],
|
||||
squawk: rec[14],
|
||||
spi: rec[15],
|
||||
position_source: positionSourceMap[rec[16]],
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user