Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix?: .env is not created, not sure if this is relevant or no though #22

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/dist/
.env
.DS_Store
*.log
*.log

.vscode
2 changes: 1 addition & 1 deletion index.d.ts
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
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint:fix": "eslint --ext .ts . --fix",
"prettier": "prettier --ignore-path .gitignore --write \"**/*.+(ts|json)\"",
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "#cp -n .env.template .env"
"postinstall": "cp -n .env.template .env || echo 'Keeping existing .env'"
},
"author": "",
"license": "ISC",
Expand Down Expand Up @@ -48,4 +48,4 @@
"puppeteer": "^19.11.1",
"request": "^2.88.2"
}
}
}
132 changes: 66 additions & 66 deletions src/classes/server.ts
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
20 changes: 10 additions & 10 deletions src/classes/sources/Position.d.ts
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
}
}
50 changes: 25 additions & 25 deletions src/classes/sources/Source.ts
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
Loading
Loading