ADSB updates
This commit is contained in:
Binary file not shown.
@@ -14,15 +14,39 @@ const history = new Map();
|
|||||||
const MAX_HISTORY = 500;
|
const MAX_HISTORY = 500;
|
||||||
|
|
||||||
const CSV_URL = 'https://s3.opensky-network.org/data-samples/metadata/aircraft-database-complete-2024-06.csv';
|
const CSV_URL = 'https://s3.opensky-network.org/data-samples/metadata/aircraft-database-complete-2024-06.csv';
|
||||||
const MIL_RANGES_URL = ':8080/db-3.14.1707/ranges.js';
|
const MIL_RANGES_URL = ':8080/db-3.14.1708/ranges.js';
|
||||||
|
|
||||||
const MILITARY_OPERATORS = ['air force', 'army', 'navy', 'marine', 'coast guard', 'military', 'defence', 'defense', 'luftwaffe', 'RAF', 'USAF', 'USN', 'USMC'];
|
const MILITARY_OPERATORS = ['air force', 'army', 'navy', 'marine', 'coast guard', 'military', 'defence', 'defense', 'luftwaffe', 'RAF', 'USAF', 'USN', 'USMC'];
|
||||||
const CARGO_OPERATORS = ['fedex', 'ups', 'dhl', 'cargo', 'freight', 'logistic', 'atlas air', 'kalitta', 'air freight'];
|
const CARGO_OPERATORS = ['fedex', 'ups', 'dhl', 'cargo', 'freight', 'logistic', 'atlas air', 'kalitta', 'air freight'];
|
||||||
const PASSENGER_OPERATORS = ['airlines', 'airways', 'air ', 'jet', 'easyjet', 'ryanair', 'delta', 'united', 'american', 'southwest', 'lufthansa', 'emirates', 'british'];
|
const PASSENGER_OPERATORS = ['airlines', 'airways', 'air ', 'jet', 'easyjet', 'ryanair', 'delta', 'united', 'american', 'southwest', 'lufthansa', 'emirates', 'british'];
|
||||||
const MILITARY_CLASSES = ['H1M', 'H2M', 'L1M', 'L2M', 'L4M', 'A0'];
|
const MILITARY_CLASSES = ['H1M', 'H2M', 'L1M', 'L2M', 'L4M', 'A0'];
|
||||||
|
|
||||||
|
const milRanges = [];
|
||||||
let db;
|
let db;
|
||||||
|
|
||||||
|
async function syncMilitaryRanges() {
|
||||||
|
const { ADSB_URL } = cfg();
|
||||||
|
try {
|
||||||
|
const res = await fetch(ADSB_URL + MIL_RANGES_URL);
|
||||||
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
const { military } = await res.json();
|
||||||
|
|
||||||
|
db.exec('DELETE FROM military_ranges');
|
||||||
|
const insert = db.prepare('INSERT INTO military_ranges (start, end) VALUES (?, ?)');
|
||||||
|
const insertMany = db.transaction(ranges => {
|
||||||
|
for (const [s, e] of ranges) insert.run(s.toUpperCase(), e.toUpperCase());
|
||||||
|
});
|
||||||
|
|
||||||
|
insertMany(military);
|
||||||
|
milRanges.length = 0;
|
||||||
|
milRanges.push(...military.map(([s, e]) => [s.toUpperCase(), e.toUpperCase()]));
|
||||||
|
} catch (e) {
|
||||||
|
const rows = db.prepare('SELECT start, end FROM military_ranges').all();
|
||||||
|
milRanges.length = 0;
|
||||||
|
milRanges.push(...rows.map(r => [r.start, r.end]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function initAircraftDb() {
|
export async function initAircraftDb() {
|
||||||
if (!fs.existsSync(DATA)) fs.mkdirSync(DATA, { recursive: true });
|
if (!fs.existsSync(DATA)) fs.mkdirSync(DATA, { recursive: true });
|
||||||
|
|
||||||
@@ -54,15 +78,7 @@ export async function initAircraftDb() {
|
|||||||
);
|
);
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// Always refresh military ranges on startup
|
await syncMilitaryRanges();
|
||||||
const { ADSB_URL } = cfg();
|
|
||||||
const res = await fetch(ADSB_URL + MIL_RANGES_URL);
|
|
||||||
if (!res.ok) throw new Error(`Failed to fetch military ranges: HTTP ${res.status}`);
|
|
||||||
const { military } = await res.json();
|
|
||||||
db.exec('DELETE FROM military_ranges');
|
|
||||||
const insertRange = db.prepare('INSERT INTO military_ranges (start, end) VALUES (?, ?)');
|
|
||||||
const insertRanges = db.transaction(ranges => { for (const [s, e] of ranges) insertRange.run(s.toUpperCase(), e.toUpperCase()); });
|
|
||||||
insertRanges(military);
|
|
||||||
|
|
||||||
if (missing) {
|
if (missing) {
|
||||||
const res = await fetch(CSV_URL);
|
const res = await fetch(CSV_URL);
|
||||||
@@ -112,8 +128,7 @@ export async function initAircraftDb() {
|
|||||||
function isIcaoInMilitaryRange(icao) {
|
function isIcaoInMilitaryRange(icao) {
|
||||||
if (!icao) return false;
|
if (!icao) return false;
|
||||||
const hex = icao.toUpperCase();
|
const hex = icao.toUpperCase();
|
||||||
const match = db.prepare('SELECT 1 FROM military_ranges WHERE start <= ? AND end >= ? LIMIT 1').get(hex, hex);
|
return milRanges.some(([s, e]) => hex >= s && hex <= e);
|
||||||
return !!match;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function wordMatch(text, keyword) {
|
function wordMatch(text, keyword) {
|
||||||
|
|||||||
Reference in New Issue
Block a user