BROKEN: WIP data expansion
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
haze.json
|
||||||
|
|||||||
@@ -25,3 +25,4 @@ curl "http://localhost:3000/locations?auth=BASE64_ENCODED_STRING"
|
|||||||
|
|
||||||
|
|
||||||
`basicauth_serve.js` does the same thing bus expects account details to be passed via basic HTTP auth, but does not work with QGIS.
|
`basicauth_serve.js` does the same thing bus expects account details to be passed via basic HTTP auth, but does not work with QGIS.
|
||||||
|
This is from a limitation of express-basic-auth.
|
||||||
|
|||||||
+119
-22
@@ -5,7 +5,7 @@ const { createHash } = require('crypto');
|
|||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 8355;
|
const port = 8355;
|
||||||
const geonJsonTemplate = {
|
const geoJsonTemplate = {
|
||||||
type: "FeatureCollection",
|
type: "FeatureCollection",
|
||||||
features: [],
|
features: [],
|
||||||
"marker-symbol-images": {
|
"marker-symbol-images": {
|
||||||
@@ -13,6 +13,35 @@ const geonJsonTemplate = {
|
|||||||
"star-stroked": "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'><path fill='currentColor' d='M64 32C28.7 32 0 60.7 0 96L0 416c0 35.3 28.7 64 64 64l320 0c35.3 0 64-28.7 64-64l0-320c0-35.3-28.7-64-64-64L64 32zm73.8 149.3c7.9-22.3 29.1-37.3 52.8-37.3l58.3 0c34.9 0 63.1 28.3 63.1 63.1 0 22.6-12.1 43.5-31.7 54.8L248 280.4c-.2 13-10.9 23.6-24 23.6-13.3 0-24-10.7-24-24l0-13.5c0-8.6 4.6-16.5 12.1-20.8l44.3-25.4c4.7-2.7 7.6-7.7 7.6-13.1 0-8.4-6.8-15.1-15.1-15.1l-58.3 0c-3.4 0-6.4 2.1-7.5 5.3l-.4 1.2c-4.4 12.5-18.2 19-30.6 14.6s-19-18.2-14.6-30.6l.4-1.2zM192 368a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zM48 104a24 24 0 1 1 48 0 24 24 0 1 1 -48 0zM376 80a24 24 0 1 1 0 48 24 24 0 1 1 0-48zM48 408a24 24 0 1 1 48 0 24 24 0 1 1 -48 0zm328-24a24 24 0 1 1 0 48 24 24 0 1 1 0-48z'/></svg>"
|
"star-stroked": "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'><path fill='currentColor' d='M64 32C28.7 32 0 60.7 0 96L0 416c0 35.3 28.7 64 64 64l320 0c35.3 0 64-28.7 64-64l0-320c0-35.3-28.7-64-64-64L64 32zm73.8 149.3c7.9-22.3 29.1-37.3 52.8-37.3l58.3 0c34.9 0 63.1 28.3 63.1 63.1 0 22.6-12.1 43.5-31.7 54.8L248 280.4c-.2 13-10.9 23.6-24 23.6-13.3 0-24-10.7-24-24l0-13.5c0-8.6 4.6-16.5 12.1-20.8l44.3-25.4c4.7-2.7 7.6-7.7 7.6-13.1 0-8.4-6.8-15.1-15.1-15.1l-58.3 0c-3.4 0-6.4 2.1-7.5 5.3l-.4 1.2c-4.4 12.5-18.2 19-30.6 14.6s-19-18.2-14.6-30.6l.4-1.2zM192 368a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zM48 104a24 24 0 1 1 48 0 24 24 0 1 1 -48 0zM376 80a24 24 0 1 1 0 48 24 24 0 1 1 0-48zM48 408a24 24 0 1 1 48 0 24 24 0 1 1 -48 0zm328-24a24 24 0 1 1 0 48 24 24 0 1 1 0-48z'/></svg>"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const hazeTranslator = {
|
||||||
|
category: [
|
||||||
|
"Urbex",
|
||||||
|
"Nature",
|
||||||
|
"Spontaneous"
|
||||||
|
],
|
||||||
|
difficulty: [
|
||||||
|
"Not Sure",
|
||||||
|
"Baby",
|
||||||
|
"Walk in the Park",
|
||||||
|
"Challenge",
|
||||||
|
"Madman",
|
||||||
|
"Deathwish"
|
||||||
|
],
|
||||||
|
rating: [
|
||||||
|
"Not Sure",
|
||||||
|
"Check it Out",
|
||||||
|
"Worth the Trip",
|
||||||
|
"Must See"
|
||||||
|
],
|
||||||
|
level: [
|
||||||
|
"Lost Soul",
|
||||||
|
"Roamer",
|
||||||
|
"Adventurer",
|
||||||
|
"Pathfinder",
|
||||||
|
"Trailblazer",
|
||||||
|
"Maven"
|
||||||
|
]
|
||||||
|
};
|
||||||
app.use(auth({
|
app.use(auth({
|
||||||
authorizer: (username, password) => {
|
authorizer: (username, password) => {
|
||||||
return true;
|
return true;
|
||||||
@@ -28,9 +57,11 @@ app.all('/locations.geojson', (req, res) => {
|
|||||||
// Query Haze API Websocket
|
// Query Haze API Websocket
|
||||||
let hazePwHash = null;
|
let hazePwHash = null;
|
||||||
let hazeUser = null;
|
let hazeUser = null;
|
||||||
|
let hazeSocketCounter = 0;
|
||||||
|
let requestStartTime = new Date().getTime();
|
||||||
if (req.query.auth) {
|
if (req.query.auth) {
|
||||||
let paramAuth = Buffer.from(req.query.auth, 'base64').toString('utf-8');
|
let paramAuth = Buffer.from(req.query.auth, 'base64').toString('utf-8');
|
||||||
hawUser = paramAuth.split(":")[0];
|
hazeUser = paramAuth.split(":")[0];
|
||||||
hazePwHash = paramAuth.split(":")[1];
|
hazePwHash = paramAuth.split(":")[1];
|
||||||
} else {
|
} else {
|
||||||
hazeUser = req.auth.user;
|
hazeUser = req.auth.user;
|
||||||
@@ -41,6 +72,7 @@ app.all('/locations.geojson', (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const haze = new WebSocket('wss://do.ecven.com:8120/explr');
|
const haze = new WebSocket('wss://do.ecven.com:8120/explr');
|
||||||
|
let locations = [];
|
||||||
haze.addEventListener('message', (event) => {
|
haze.addEventListener('message', (event) => {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
let haze_authToken = '', haze_username = '';
|
let haze_authToken = '', haze_username = '';
|
||||||
@@ -54,14 +86,14 @@ app.all('/locations.geojson', (req, res) => {
|
|||||||
"email": hazeUser
|
"email": hazeUser
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"socketMessageId": 0
|
"socketMessageId": hazeSocketCounter++
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
case "authenticateAccount_response":
|
case "authenticateAccount_response":
|
||||||
if (data['body']['response'] === 1) {
|
if (data['body']['response'] === 1) {
|
||||||
haze_authToken = data['body']['authToken'];
|
haze_authToken = data['body']['authToken'];
|
||||||
haze_username = data['body']['username'];
|
haze_username = data['body']['username'];
|
||||||
haze.send('{"event": "getMyLocationsRequest_request","body": [{"higlightImages": true}],"socketMessageId": 0}');
|
haze.send('{"event": "getMyLocationsRequest_request","body": [{"higlightImages": true}],"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, password: req.auth.password });
|
||||||
@@ -71,26 +103,37 @@ app.all('/locations.geojson', (req, res) => {
|
|||||||
break;
|
break;
|
||||||
case "getMyLocationsRequest_response":
|
case "getMyLocationsRequest_response":
|
||||||
if (data['body']['response'] === 1) {
|
if (data['body']['response'] === 1) {
|
||||||
const hazeLocations = data['body']['locations'].map(location => {
|
// locations = data['body']['locations'].map(location => {
|
||||||
return {
|
// return {
|
||||||
type: "Feature",
|
// id: location['id'],
|
||||||
geometry: {
|
// title: location['name'],
|
||||||
type: "Point",
|
// completed: false
|
||||||
coordinates: [location['coordinates']['longitude'], location['coordinates']['latitude']]
|
// };
|
||||||
},
|
// });
|
||||||
properties: {
|
data['body']['locations'].forEach(location => {
|
||||||
id: location['id'],
|
locations[hazeSocketCounter++] = {
|
||||||
title: location['name'],
|
id: location['id'],
|
||||||
"marker-symbol": location['isUnconfirmedLocation'] === 1 ? "star-stroked" : "star",
|
title: location['name'],
|
||||||
}
|
latitude: location['coordinates']['latitude'],
|
||||||
|
longitude: location['coordinates']['longitude'],
|
||||||
|
isExplored: location['explored'] > 0,
|
||||||
|
isConfirmed: location['isUnconfirmedLocation'] !== 1,
|
||||||
|
category: hazeTranslator.category[location['locationCategory']],
|
||||||
|
completed: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// need to make the socketIDs dynamic and handle completed status before returning final payload
|
||||||
|
// FIX: Currently throwing response 2 "User does not have access to location."
|
||||||
|
locations.forEach((location, index) => {
|
||||||
|
if (location) {
|
||||||
|
haze.send(JSON.stringify({
|
||||||
|
event: "getLocation_request",
|
||||||
|
body: locations.map(location => location.id),
|
||||||
|
socketMessageId: index
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
res.setHeader('Content-Type', 'application/json');
|
|
||||||
haze.close();
|
|
||||||
res.end(JSON.stringify({
|
|
||||||
...geonJsonTemplate,
|
|
||||||
features: hazeLocations
|
|
||||||
}));
|
|
||||||
} else {
|
} else {
|
||||||
console.dir(data);
|
console.dir(data);
|
||||||
res.status(500).send('Failed to retrieve locations');
|
res.status(500).send('Failed to retrieve locations');
|
||||||
@@ -98,6 +141,60 @@ app.all('/locations.geojson', (req, res) => {
|
|||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "getLocation_response":
|
||||||
|
if (data['body']['response'] === 1) {
|
||||||
|
locations[data['socketMessageId']] = {
|
||||||
|
...locations[data['socketMessageId']],
|
||||||
|
completed: true,
|
||||||
|
author: `${data['body']['location']['submittorUserDatas']['username']} (${data['body']['location']['submittorUserDatas']['email']})`,
|
||||||
|
rating: hazeTranslator.rating[data['body']['location']['locationRating']['overallRating']],
|
||||||
|
difficulty: hazeTranslator.difficulty[data['body']['location']['locationRating']['difficultyRating']],
|
||||||
|
level: hazeTranslator.level[data['body']['location']['locationRating']['levelRating']],
|
||||||
|
// TODO: use body.location.locationRating.ratingItemsList for location tags
|
||||||
|
comments: data['body']['location']['locationCommentsAndCommunityVotes'].map(comment => ({
|
||||||
|
id: comment['id'],
|
||||||
|
text: comment['comment'],
|
||||||
|
rating: (comment['upvotes']*1)+(comment['downvotes']* -1),
|
||||||
|
author: comment['submittor']['username'],
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
let testTime = (new Date().getTime() - requestStartTime) > 30000; // 30s timeout
|
||||||
|
if (locations.every(location => location && location.completed) || testTime) {
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
haze.close();
|
||||||
|
res.end(JSON.stringify({
|
||||||
|
...geoJsonTemplate,
|
||||||
|
features: locations.map(location => ({
|
||||||
|
type: "Feature",
|
||||||
|
geometry: {
|
||||||
|
type: "Point",
|
||||||
|
coordinates: [location['longitude'], location['latitude']]
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
id: location['id'],
|
||||||
|
title: location['name'],
|
||||||
|
"marker-symbol": location['isUnconfirmedLocation'] === 1 ? "star-stroked" : "star",
|
||||||
|
author: location['author'] || '',
|
||||||
|
explored: location['isExplored'] || false,
|
||||||
|
confirmed: location['isConfirmed'] || false,
|
||||||
|
category: location['category'] || '',
|
||||||
|
level: location['level'] || '',
|
||||||
|
rating: location['rating'] || '',
|
||||||
|
difficulty: location['difficulty'] || '',
|
||||||
|
comments: location['comments'] || [],
|
||||||
|
querySuccess: location['completed']
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.dir(data);
|
||||||
|
// res.status(500).send('Failed to retrieve locations');
|
||||||
|
// haze.close();
|
||||||
|
// res.end();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.dir(data);
|
console.dir(data);
|
||||||
res.status(500).send('Unexpected response from Haze API');
|
res.status(500).send('Unexpected response from Haze API');
|
||||||
|
|||||||
Reference in New Issue
Block a user