Compare commits

..
3 Commits
Author SHA1 Message Date
Elizabeth Cray 026bd0f7a1 Fixed device reporting 2026-08-02 14:15:56 -04:00
Elizabeth Cray def1070589 Add device reporting 2026-08-02 14:01:59 -04:00
Elizabeth Cray 3988db9bde Fix missing define 2026-07-27 07:34:55 -04:00
+69 -5
View File
@@ -1,7 +1,9 @@
const express = require('express');
const WebSocket = require('ws');
const os = require('os');
const { createHash } = require('crypto');
// TODO: make the code more reusable between the two endpoints
const app = express();
const port = 8355;
@@ -95,8 +97,25 @@ const hazeTranslator = {
]
};
const deviceInfo = {
// modelname: "GeoJSON_connector"
"event": "reportDeviceInfo_request",
"body": [
"third-party",
"Linux",
"dehaze",
"Firefox",
"154.0",
"GeoJSON_connector",
null,
"desktop",
"web"
]
};
// 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');
@@ -105,6 +124,8 @@ app.all('/locations_full.geojson', (req, res) => {
// Setup standard authentication variables
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];
@@ -191,10 +212,31 @@ 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({
...deviceInfo,
"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();
}
@@ -296,6 +338,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];
@@ -321,7 +364,7 @@ app.all('/locations.geojson', (req, res) => {
"email": hazeUser
}
],
"socketMessageId": 0
"socketMessageId": hazeSocketCounter
}));
break;
case "authenticateAccount_response":
@@ -329,7 +372,10 @@ 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({
...deviceInfo,
"socketMessageId": ++hazeSocketCounter
}));
} else {
console.dir(req.query);
res.status(401).json({ ...data });
@@ -337,6 +383,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 => {
@@ -368,8 +432,8 @@ app.all('/locations.geojson', (req, res) => {
break;
default:
console.dir(data);
res.status(500).send('Unexpected response from Haze API');
haze.close();
res.status(500).send('Unexpected response from Haze API');
res.end();
}
});