Add device reporting

This commit is contained in:
2026-08-02 14:01:59 -04:00
parent 3988db9bde
commit def1070589
+66 -4
View File
@@ -2,6 +2,7 @@ const express = require('express');
const WebSocket = require('ws'); const WebSocket = require('ws');
const { createHash } = require('crypto'); const { createHash } = require('crypto');
// TODO: make the code more reusable between the two endpoints
const app = express(); const app = express();
const port = 8355; const port = 8355;
@@ -97,6 +98,7 @@ const hazeTranslator = {
// Assemble full Haze location data, can take a LONG time // Assemble full Haze location data, can take a LONG time
app.all('/locations_full.geojson', (req, res) => { app.all('/locations_full.geojson', (req, res) => {
// TODO: Implement 1wk caching of location data
// Verify Inputs // Verify Inputs
if (!req.headers['authorization']) { if (!req.headers['authorization']) {
res.status(401).send('Unauthorized'); res.status(401).send('Unauthorized');
@@ -106,6 +108,7 @@ app.all('/locations_full.geojson', (req, res) => {
let hazePwHash = null; let hazePwHash = null;
let hazeUser = null; let hazeUser = null;
let hazeSocketCounter = 0; let hazeSocketCounter = 0;
let requestStartTime = new Date().getTime();
let authHeader = req.headers['authorization']; let authHeader = req.headers['authorization'];
let paramAuth = Buffer.from(authHeader.replace('Basic ', ''), 'base64').toString('utf-8'); let paramAuth = Buffer.from(authHeader.replace('Basic ', ''), 'base64').toString('utf-8');
hazeUser = paramAuth.split(":")[0]; hazeUser = paramAuth.split(":")[0];
@@ -192,10 +195,39 @@ app.all('/locations_full.geojson', (req, res) => {
haze_authToken = data['body']['authToken']; haze_authToken = data['body']['authToken'];
haze_username = data['body']['username']; haze_username = data['body']['username'];
// TODO: add platform report // 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 { } else {
console.dir(req.query); 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(); haze.close();
res.end(); res.end();
} }
@@ -297,6 +329,7 @@ app.all('/locations.geojson', (req, res) => {
// Setup standard authentication variables // Setup standard authentication variables
let hazePwHash = null; let hazePwHash = null;
let hazeUser = null; let hazeUser = null;
let hazeSocketCounter = 0;
let authHeader = req.headers['authorization']; let authHeader = req.headers['authorization'];
let paramAuth = Buffer.from(authHeader.replace('Basic ', ''), 'base64').toString('utf-8'); let paramAuth = Buffer.from(authHeader.replace('Basic ', ''), 'base64').toString('utf-8');
hazeUser = paramAuth.split(":")[0]; hazeUser = paramAuth.split(":")[0];
@@ -322,7 +355,7 @@ app.all('/locations.geojson', (req, res) => {
"email": hazeUser "email": hazeUser
} }
], ],
"socketMessageId": 0 "socketMessageId": hazeSocketCounter
})); }));
break; break;
case "authenticateAccount_response": case "authenticateAccount_response":
@@ -330,7 +363,18 @@ app.all('/locations.geojson', (req, res) => {
haze_authToken = data['body']['authToken']; haze_authToken = data['body']['authToken'];
haze_username = data['body']['username']; haze_username = data['body']['username'];
// TODO: add platform report // 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 { } else {
console.dir(req.query); console.dir(req.query);
res.status(401).json({ ...data }); res.status(401).json({ ...data });
@@ -338,6 +382,24 @@ app.all('/locations.geojson', (req, res) => {
res.end(); res.end();
} }
break; 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": case "getMyLocationsRequest_response":
if (data['body']['response'] === 1) { if (data['body']['response'] === 1) {
const hazeLocations = data['body']['locations'].map(location => { const hazeLocations = data['body']['locations'].map(location => {