This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
381 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
declare module "position-api" { | ||
declare module 'position-api' { | ||
// Define the exported types and interfaces here | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,105 @@ | ||
import express from "express"; | ||
import cors from "cors"; | ||
import path from "path"; | ||
import { api } from "../legacy/api"; | ||
import { areaApi } from "../legacy/area"; | ||
import ADSBexchange from "./sources/adsb/adsbe"; | ||
import express from 'express' | ||
import cors from 'cors' | ||
import path from 'path' | ||
import { api } from '../legacy/api' | ||
import { areaApi } from '../legacy/area' | ||
import ADSBexchange from './sources/adsb/adsbe' | ||
class Server { | ||
app: any; | ||
constructor(port) { | ||
this.init(port); | ||
app: any | ||
constructor (port) { | ||
this.init(port) | ||
} | ||
|
||
init(port: number) { | ||
this.app = express(); | ||
this.app.set("port", port); | ||
init (port: number) { | ||
this.app = express() | ||
this.app.set('port', port) | ||
this.app.use( | ||
cors({ | ||
origin: "*", | ||
}), | ||
); | ||
this.app.get("/", (_request: any, response: any) => { | ||
response.sendFile(path.join(__dirname, "/../static/index.html")); | ||
}); | ||
this.loadLegacyRoutes(); | ||
this.loadRoutes(); | ||
this.app.listen(this.app.get("port"), () => { | ||
console.log("Node this.app is running on port", this.app.get("port")); | ||
}); | ||
origin: '*' | ||
}) | ||
) | ||
this.app.get('/', (_request: any, response: any) => { | ||
response.sendFile(path.join(__dirname, '/../static/index.html')) | ||
}) | ||
this.loadLegacyRoutes() | ||
this.loadRoutes() | ||
this.app.listen(this.app.get('port'), () => { | ||
console.log('Node this.app is running on port', this.app.get('port')) | ||
}) | ||
} | ||
|
||
loadRoutes() { | ||
loadRoutes () { | ||
// /:sourcetype/:source/:vehicleidentifier/location/latest | ||
this.app.get( | ||
"/adsb/adsbe/:icao/location/latest", | ||
'/adsb/adsbe/:icao/location/latest', | ||
async (req: any, res: any) => { | ||
console.log(req.params.icao); | ||
const adsbe = new ADSBexchange(); | ||
const location = await adsbe.getLocation(req.params.icao); | ||
console.log(location); | ||
console.log(req.params.icao) | ||
const adsbe = new ADSBexchange() | ||
const location = await adsbe.getLocation(req.params.icao) | ||
console.log(location) | ||
res.send({ | ||
error: null, | ||
data: location, | ||
}); | ||
}, | ||
); | ||
data: location | ||
}) | ||
} | ||
) | ||
} | ||
|
||
loadLegacyRoutes() { | ||
loadLegacyRoutes () { | ||
// this route is wrongly named on purpose for legacy reasons. | ||
// AS VF is not as easy to reverse as the other ones, it is replaced by MST | ||
this.app.get( | ||
"/legacy/getLastPositionFromVF/:mmsi", | ||
'/legacy/getLastPositionFromVF/:mmsi', | ||
(req: any, res: any) => { | ||
api.getLocationFromMST(req.params.mmsi, (result) => { | ||
res.send(result); | ||
}); | ||
}, | ||
); | ||
res.send(result) | ||
}) | ||
} | ||
) | ||
this.app.get( | ||
"/legacy/getLastPositionFromMT/:mmsi", | ||
'/legacy/getLastPositionFromMT/:mmsi', | ||
(req: any, res: any) => { | ||
api.getLocationFromMT(req.params.mmsi, (result) => { | ||
res.send(result); | ||
}); | ||
}, | ||
); | ||
this.app.get("/legacy/getLastPosition/:mmsi", (req: any, res: any) => { | ||
res.send(result) | ||
}) | ||
} | ||
) | ||
this.app.get('/legacy/getLastPosition/:mmsi', (req: any, res: any) => { | ||
api.getLocation(req.params.mmsi, (result) => { | ||
res.send(result); | ||
}); | ||
}); | ||
res.send(result) | ||
}) | ||
}) | ||
// e.g. /getVesselsInArea/WMED,EMED | ||
this.app.get( | ||
"/legacy/getVesselsInArea/:area", | ||
'/legacy/getVesselsInArea/:area', | ||
async (req: any, res: any) => { | ||
await areaApi.fetchVesselsInArea( | ||
req.params.area.split(","), | ||
req.params.area.split(','), | ||
(result) => { | ||
res.json(result); | ||
}, | ||
); | ||
}, | ||
); | ||
res.json(result) | ||
} | ||
) | ||
} | ||
) | ||
this.app.get( | ||
"/legacy/getVesselsNearMe/:lat/:lng/:distance", | ||
'/legacy/getVesselsNearMe/:lat/:lng/:distance', | ||
async (req: any, res: any) => { | ||
await areaApi.fetchVesselsNearMe( | ||
req.params.lat, | ||
req.params.lng, | ||
req.params.distance, | ||
(result) => { | ||
res.json(result); | ||
}, | ||
); | ||
}, | ||
); | ||
this.app.get("/legacy/getVesselsInPort/:shipPort", (req: any, res: any) => { | ||
res.json(result) | ||
} | ||
) | ||
} | ||
) | ||
this.app.get('/legacy/getVesselsInPort/:shipPort', (req: any, res: any) => { | ||
api.getVesselsInPort(req.params.shipPort, (result) => { | ||
res.send(result); | ||
}); | ||
}); | ||
res.send(result) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
export default Server; | ||
export default Server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
declare module "PositionTypes" { | ||
declare module 'PositionTypes' { | ||
export interface Position { | ||
timestamp: string; | ||
latitude: number; | ||
longitude: number; | ||
course: number; | ||
speed: number; | ||
source: string; | ||
source_type: string; | ||
altitude?: number; | ||
raw?: any; | ||
timestamp: string | ||
latitude: number | ||
longitude: number | ||
course: number | ||
speed: number | ||
source: string | ||
source_type: string | ||
altitude?: number | ||
raw?: any | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import fetch from "node-fetch"; | ||
import puppeteer from "puppeteer"; | ||
import fetch from 'node-fetch' | ||
import puppeteer from 'puppeteer' | ||
|
||
class Source { | ||
browser: any; | ||
constructor() { | ||
this.browser = false; | ||
browser: any | ||
constructor () { | ||
this.browser = false | ||
} | ||
|
||
getBrowser: any = async () => { | ||
if (this.browser) { | ||
return this.browser; | ||
return this.browser | ||
} | ||
this.browser = await puppeteer.launch({ | ||
headless: true, | ||
defaultViewport: { | ||
width: 1280, // Width of a MacBook screen | ||
height: 1400, // Height of a MacBook screen | ||
height: 1400 // Height of a MacBook screen | ||
}, | ||
// waitUntil: "domcontentloaded", | ||
args: [ | ||
"--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", | ||
], | ||
}); | ||
return this.browser; | ||
}; | ||
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36' | ||
] | ||
}) | ||
return this.browser | ||
} | ||
|
||
convertRawCoordinatesIntoDecimal(input): number { | ||
const grade = parseInt(input.substring(0, input.indexOf("°"))); | ||
const rest = input.substring(input.indexOf("°") + 1); | ||
const minutes = parseInt(rest.substring(0, rest.indexOf("'"))); | ||
convertRawCoordinatesIntoDecimal (input): number { | ||
const grade = parseInt(input.substring(0, input.indexOf('°'))) | ||
const rest = input.substring(input.indexOf('°') + 1) | ||
const minutes = parseInt(rest.substring(0, rest.indexOf("'"))) | ||
const seconds = parseInt( | ||
rest.substring(rest.indexOf("'") + 1).split('"')[0], | ||
); | ||
return grade + (minutes + seconds / 60) / 60; | ||
rest.substring(rest.indexOf("'") + 1).split('"')[0] | ||
) | ||
return grade + (minutes + seconds / 60) / 60 | ||
} | ||
|
||
fetch = async function (url: string, headers: any, method: string) { | ||
const response = await fetch(url, { | ||
headers, | ||
body: undefined, | ||
method, | ||
}); | ||
const text = await response.text(); | ||
return text; | ||
}; | ||
method | ||
}) | ||
const text = await response.text() | ||
return text | ||
} | ||
} | ||
|
||
export default Source; | ||
export default Source |
Oops, something went wrong.