Compare commits
3
Commits
07b66a7323
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
026bd0f7a1 | ||
|
|
def1070589 | ||
|
|
3988db9bde |
+69
-5
@@ -1,7 +1,9 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
|
const os = require('os');
|
||||||
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;
|
||||||
@@ -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
|
// 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');
|
||||||
@@ -105,6 +124,8 @@ app.all('/locations_full.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 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];
|
||||||
@@ -191,10 +212,31 @@ 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({
|
||||||
|
...deviceInfo,
|
||||||
|
"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();
|
||||||
}
|
}
|
||||||
@@ -296,6 +338,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];
|
||||||
@@ -321,7 +364,7 @@ app.all('/locations.geojson', (req, res) => {
|
|||||||
"email": hazeUser
|
"email": hazeUser
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"socketMessageId": 0
|
"socketMessageId": hazeSocketCounter
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
case "authenticateAccount_response":
|
case "authenticateAccount_response":
|
||||||
@@ -329,7 +372,10 @@ 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({
|
||||||
|
...deviceInfo,
|
||||||
|
"socketMessageId": ++hazeSocketCounter
|
||||||
|
}));
|
||||||
} else {
|
} else {
|
||||||
console.dir(req.query);
|
console.dir(req.query);
|
||||||
res.status(401).json({ ...data });
|
res.status(401).json({ ...data });
|
||||||
@@ -337,6 +383,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 => {
|
||||||
@@ -368,8 +432,8 @@ app.all('/locations.geojson', (req, res) => {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.dir(data);
|
console.dir(data);
|
||||||
res.status(500).send('Unexpected response from Haze API');
|
|
||||||
haze.close();
|
haze.close();
|
||||||
|
res.status(500).send('Unexpected response from Haze API');
|
||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user