Compare commits
3
Commits
07b66a7323
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
026bd0f7a1 | ||
|
|
def1070589 | ||
|
|
3988db9bde |
+69
-5
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user