Add device reporting
This commit is contained in:
+66
-4
@@ -2,6 +2,7 @@ const express = require('express');
|
||||
const WebSocket = require('ws');
|
||||
const { createHash } = require('crypto');
|
||||
|
||||
// TODO: make the code more reusable between the two endpoints
|
||||
|
||||
const app = express();
|
||||
const port = 8355;
|
||||
@@ -97,6 +98,7 @@ const hazeTranslator = {
|
||||
|
||||
// Assemble full Haze location data, can take a LONG time
|
||||
app.all('/locations_full.geojson', (req, res) => {
|
||||
// TODO: Implement 1wk caching of location data
|
||||
// Verify Inputs
|
||||
if (!req.headers['authorization']) {
|
||||
res.status(401).send('Unauthorized');
|
||||
@@ -106,6 +108,7 @@ app.all('/locations_full.geojson', (req, res) => {
|
||||
let hazePwHash = null;
|
||||
let hazeUser = null;
|
||||
let hazeSocketCounter = 0;
|
||||
let requestStartTime = new Date().getTime();
|
||||
let authHeader = req.headers['authorization'];
|
||||
let paramAuth = Buffer.from(authHeader.replace('Basic ', ''), 'base64').toString('utf-8');
|
||||
hazeUser = paramAuth.split(":")[0];
|
||||
@@ -192,10 +195,39 @@ app.all('/locations_full.geojson', (req, res) => {
|
||||
haze_authToken = data['body']['authToken'];
|
||||
haze_username = data['body']['username'];
|
||||
// TODO: add platform report
|
||||
haze.send('{"event": "getMyLocationsRequest_request","body": [{"higlightImages": true}],"socketMessageId": ' + hazeSocketCounter++ + '}');
|
||||
haze.send(JSON.stringify({
|
||||
"event": "reportDeviceInfo_request",
|
||||
"body": [
|
||||
{
|
||||
"sessionType": {
|
||||
"third-party": "GeoJSON_connector",
|
||||
"name": "dehaze"
|
||||
}
|
||||
}
|
||||
],
|
||||
"socketMessageId": ++hazeSocketCounter
|
||||
}));
|
||||
} else {
|
||||
console.dir(req.query);
|
||||
res.status(401).json({ ...data, password: req.auth.password });
|
||||
res.status(401).json({ ...data });
|
||||
haze.close();
|
||||
res.end();
|
||||
}
|
||||
break;
|
||||
case "reportDeviceInfo_response":
|
||||
if (data['body']['response'] === 1) {
|
||||
haze.send(JSON.stringify({
|
||||
"event": "getMyLocationsRequest_request",
|
||||
"body": [
|
||||
{
|
||||
"highlightImages": true
|
||||
}
|
||||
],
|
||||
"socketMessageId": ++hazeSocketCounter
|
||||
}));
|
||||
} else {
|
||||
console.dir(data);
|
||||
res.status(500).send('Failed to report device info');
|
||||
haze.close();
|
||||
res.end();
|
||||
}
|
||||
@@ -297,6 +329,7 @@ app.all('/locations.geojson', (req, res) => {
|
||||
// Setup standard authentication variables
|
||||
let hazePwHash = null;
|
||||
let hazeUser = null;
|
||||
let hazeSocketCounter = 0;
|
||||
let authHeader = req.headers['authorization'];
|
||||
let paramAuth = Buffer.from(authHeader.replace('Basic ', ''), 'base64').toString('utf-8');
|
||||
hazeUser = paramAuth.split(":")[0];
|
||||
@@ -322,7 +355,7 @@ app.all('/locations.geojson', (req, res) => {
|
||||
"email": hazeUser
|
||||
}
|
||||
],
|
||||
"socketMessageId": 0
|
||||
"socketMessageId": hazeSocketCounter
|
||||
}));
|
||||
break;
|
||||
case "authenticateAccount_response":
|
||||
@@ -330,7 +363,18 @@ app.all('/locations.geojson', (req, res) => {
|
||||
haze_authToken = data['body']['authToken'];
|
||||
haze_username = data['body']['username'];
|
||||
// TODO: add platform report
|
||||
haze.send('{"event": "getMyLocationsRequest_request","body": [{"higlightImages": true}],"socketMessageId": 0}');
|
||||
haze.send(JSON.stringify({
|
||||
"event": "reportDeviceInfo_request",
|
||||
"body": [
|
||||
{
|
||||
"sessionType": {
|
||||
"third-party": "GeoJSON_connector",
|
||||
"name": "dehaze"
|
||||
}
|
||||
}
|
||||
],
|
||||
"socketMessageId": ++hazeSocketCounter
|
||||
}));
|
||||
} else {
|
||||
console.dir(req.query);
|
||||
res.status(401).json({ ...data });
|
||||
@@ -338,6 +382,24 @@ app.all('/locations.geojson', (req, res) => {
|
||||
res.end();
|
||||
}
|
||||
break;
|
||||
case "reportDeviceInfo_response":
|
||||
if (data['body']['response'] === 1) {
|
||||
haze.send(JSON.stringify({
|
||||
"event": "getMyLocationsRequest_request",
|
||||
"body": [
|
||||
{
|
||||
"highlightImages": true
|
||||
}
|
||||
],
|
||||
"socketMessageId": ++hazeSocketCounter
|
||||
}));
|
||||
} else {
|
||||
console.dir(data);
|
||||
res.status(500).send('Failed to report device info');
|
||||
haze.close();
|
||||
res.end();
|
||||
}
|
||||
break;
|
||||
case "getMyLocationsRequest_response":
|
||||
if (data['body']['response'] === 1) {
|
||||
const hazeLocations = data['body']['locations'].map(location => {
|
||||
|
||||
Reference in New Issue
Block a user