Fixing adsb enrichment
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import {cfg} from './config.mjs';
|
import {cfg} from './config.mjs';
|
||||||
import Database from 'better-sqlite3';
|
import Database from 'better-sqlite3';
|
||||||
import {createWriteStream, existsSync, mkdirSync} from 'fs';
|
import {createWriteStream, existsSync, mkdirSync} from 'fs';
|
||||||
import {readFile, rm} from 'fs/promises';
|
|
||||||
import {resolve, dirname} from 'path';
|
import {resolve, dirname} from 'path';
|
||||||
import {fileURLToPath} from 'url';
|
import {fileURLToPath} from 'url';
|
||||||
import {pipeline} from 'stream/promises';
|
import {pipeline} from 'stream/promises';
|
||||||
import {createGunzip} from 'zlib';
|
import {createGunzip} from 'zlib';
|
||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
|
import * as fs from 'node:fs';
|
||||||
|
|
||||||
const DIR = dirname(fileURLToPath(import.meta.url));
|
const DIR = dirname(fileURLToPath(import.meta.url));
|
||||||
const DATA = resolve(DIR, '../data');
|
const DATA = resolve(DIR, '../data');
|
||||||
@@ -33,7 +33,7 @@ async function downloadTypes() {
|
|||||||
const gunzip = createGunzip();
|
const gunzip = createGunzip();
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
await new Promise((res, rej) => {
|
await new Promise((res, rej) => {
|
||||||
const gz = require('fs').createReadStream(TY_GZ);
|
const gz = fs.createReadStream(TY_GZ);
|
||||||
gz.pipe(gunzip);
|
gz.pipe(gunzip);
|
||||||
gunzip.on('data', c => chunks.push(c));
|
gunzip.on('data', c => chunks.push(c));
|
||||||
gunzip.on('end', res);
|
gunzip.on('end', res);
|
||||||
@@ -105,10 +105,8 @@ export async function initAircraftDb() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('✈️ Downloading aircraft DB...');
|
console.log('✈️ Downloading aircraft DB...');
|
||||||
const [, types] = await Promise.all([
|
await Promise.all([importAircraftDb(), downloadTypes().then(t => importTypes(t))]);
|
||||||
importAircraftDb(),
|
await Promise.all([fs.promises.rm(DB_ZIP), fs.promises.rm(TY_GZ),]);
|
||||||
downloadTypes().then(t => importTypes(t))
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const lookupAircraft = (icao) =>
|
const lookupAircraft = (icao) =>
|
||||||
@@ -133,7 +131,7 @@ export function enrichAircraft(a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getShapes() {
|
export async function getShapes() {
|
||||||
return JSON.parse(await readFile(SHAPES_PATH, 'utf8'));
|
return JSON.parse(await fs.promises.readFile(SHAPES_PATH, 'utf8'));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getADSB() {
|
export async function getADSB() {
|
||||||
|
|||||||
Reference in New Issue
Block a user