Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.get('/pilots', function(req, res) {
- let dataToSend = [];
- try {
- fetch(URL_TEST_MALFORMED)
- .then(response => {
- //console.log(response.body._outBuffer.length)
- if (response.body._outBuffer) {
- return response.text();
- } else {
- return data = null;
- }
- })
- .then(
- data => {
- //console.log(data)
- if (data !== null) {
- let splitted = data.split('\n');
- let startIndex = splitted.indexOf("!CLIENTS") + 1;
- let endIndex = splitted.indexOf("!AIRPORTS") + 2;
- //console.log(startIndex, endIndex)
- if (startIndex || startIndex == 0) {
- res.send("Something wrong, malformed file retrived")
- return
- } else {
- let clients = splitted.slice(startIndex, endIndex);
- clients.forEach(line => {
- let fields = line.split(":");
- let temp = {}
- temp.callsign = fields[0];
- temp.vid = fields[1];
- temp.connectionTime = fields[37];
- temp.softwareName = fields[38];
- temp.softwareVersion = fields[39];
- temp.latitiude = fields[5];
- temp.longtitude = fields[6];
- temp.altitude = fields[7];
- temp.groundSpeed = fields[8];
- temp.heading = fields[45];
- temp.onGround = fields[46];
- temp.squawk = fields[17];
- temp.rating = fields[41];
- dataToSend.push(temp);
- })
- res.status(200).send({
- status: 'success',
- code: 200,
- response: {
- message: 'fetch data ok',
- data: dataToSend,
- },
- })
- }
- } else {
- res.send("Response ok, but data not found!")
- }
- })
- } catch (error) {
- console.log(error)
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement