kopia lustrzana https://github.com/manuelkasper/sotlas-api
Improve logging
rodzic
5db511f6b6
commit
8012964ad4
|
@ -27,7 +27,7 @@ router.get('/', (req, res) => {
|
||||||
|
|
||||||
function loadAlerts(noCache) {
|
function loadAlerts(noCache) {
|
||||||
if (noCache) {
|
if (noCache) {
|
||||||
console.log('load alerts (no cache)');
|
console.log('Load alerts (no cache)');
|
||||||
return loadAlertsDirect();
|
return loadAlertsDirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ function loadAlerts(noCache) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pendingLoad) {
|
if (!pendingLoad) {
|
||||||
console.log('load alerts (cache)');
|
console.log('Load alerts (cache)');
|
||||||
pendingLoad = loadAlertsDirect()
|
pendingLoad = loadAlertsDirect()
|
||||||
.then(response => {
|
.then(response => {
|
||||||
pendingLoad = null;
|
pendingLoad = null;
|
||||||
|
|
|
@ -78,11 +78,6 @@ config.sso = {
|
||||||
jwksUri: 'https://sso.sota.org.uk/auth/realms/SOTA/protocol/openid-connect/certs'
|
jwksUri: 'https://sso.sota.org.uk/auth/realms/SOTA/protocol/openid-connect/certs'
|
||||||
};
|
};
|
||||||
|
|
||||||
config.mail = {
|
|
||||||
host: process.env.MAIL_HOST,
|
|
||||||
port: process.env.MAIL_PORT
|
|
||||||
};
|
|
||||||
|
|
||||||
config.solardata = {
|
config.solardata = {
|
||||||
apiKey: process.env.SOLARDATA_API_KEY
|
apiKey: process.env.SOLARDATA_API_KEY
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"mongodb": "^4.8.1",
|
"mongodb": "^4.8.1",
|
||||||
"multer": "^1.4.2",
|
"multer": "^1.4.2",
|
||||||
"nodemailer": "^6.4.6",
|
|
||||||
"reconnect-net": "^1.1.1",
|
"reconnect-net": "^1.1.1",
|
||||||
"sharp": "^0.26.3",
|
"sharp": "^0.26.3",
|
||||||
"togeojson": "^0.16.0",
|
"togeojson": "^0.16.0",
|
||||||
|
@ -2896,15 +2895,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.1.0.tgz",
|
||||||
"integrity": "sha512-flmrDNB06LIl5lywUz7YlNGZH/5p0M7W28k8hzd9Lshtdh1wshD2Y+U4h9LD6KObOy1f+fEVdgprPrEymjM5uw=="
|
"integrity": "sha512-flmrDNB06LIl5lywUz7YlNGZH/5p0M7W28k8hzd9Lshtdh1wshD2Y+U4h9LD6KObOy1f+fEVdgprPrEymjM5uw=="
|
||||||
},
|
},
|
||||||
"node_modules/nodemailer": {
|
|
||||||
"version": "6.4.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.4.6.tgz",
|
|
||||||
"integrity": "sha512-/kJ+FYVEm2HuUlw87hjSqTss+GU35D4giOpdSfGp7DO+5h6RlJj7R94YaYHOkoxu1CSaM0d3WRBtCzwXrY6MKA==",
|
|
||||||
"hasInstallScript": true,
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/noop-logger": {
|
"node_modules/noop-logger": {
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz",
|
||||||
|
@ -6614,11 +6604,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.1.0.tgz",
|
||||||
"integrity": "sha512-flmrDNB06LIl5lywUz7YlNGZH/5p0M7W28k8hzd9Lshtdh1wshD2Y+U4h9LD6KObOy1f+fEVdgprPrEymjM5uw=="
|
"integrity": "sha512-flmrDNB06LIl5lywUz7YlNGZH/5p0M7W28k8hzd9Lshtdh1wshD2Y+U4h9LD6KObOy1f+fEVdgprPrEymjM5uw=="
|
||||||
},
|
},
|
||||||
"nodemailer": {
|
|
||||||
"version": "6.4.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.4.6.tgz",
|
|
||||||
"integrity": "sha512-/kJ+FYVEm2HuUlw87hjSqTss+GU35D4giOpdSfGp7DO+5h6RlJj7R94YaYHOkoxu1CSaM0d3WRBtCzwXrY6MKA=="
|
|
||||||
},
|
|
||||||
"noop-logger": {
|
"noop-logger": {
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz",
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"mongodb": "^4.8.1",
|
"mongodb": "^4.8.1",
|
||||||
"multer": "^1.4.2",
|
"multer": "^1.4.2",
|
||||||
"nodemailer": "^6.4.6",
|
|
||||||
"reconnect-net": "^1.1.1",
|
"reconnect-net": "^1.1.1",
|
||||||
"sharp": "^0.26.3",
|
"sharp": "^0.26.3",
|
||||||
"togeojson": "^0.16.0",
|
"togeojson": "^0.16.0",
|
||||||
|
|
11
photos.js
11
photos.js
|
@ -6,7 +6,6 @@ const exif = require('exif-reader')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const hasha = require('hasha')
|
const hasha = require('hasha')
|
||||||
const minio = require('minio')
|
const minio = require('minio')
|
||||||
const nodemailer = require('nodemailer')
|
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
|
|
||||||
|
@ -114,15 +113,7 @@ function uploadToCloud(storageConfig, targetPath, buffer) {
|
||||||
}
|
}
|
||||||
return minioClient.putObject(storageConfig.bucketName, targetPath, buffer, metadata)
|
return minioClient.putObject(storageConfig.bucketName, targetPath, buffer, metadata)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err)
|
console.error('Cloud photo upload failed: ' + err)
|
||||||
|
|
||||||
let transporter = nodemailer.createTransport(config.mail)
|
|
||||||
transporter.sendMail({
|
|
||||||
from: 'api@sotl.as',
|
|
||||||
to: 'mk@neon1.net',
|
|
||||||
subject: 'Cloud photo upload failed',
|
|
||||||
text: `The file ${filename} could not be uploaded to ${storageConfig.endpoint} at path ${targetPath}:\n${err}`
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ const config = require('./config')
|
||||||
const photos = require('./photos')
|
const photos = require('./photos')
|
||||||
const jwt = require('express-jwt')
|
const jwt = require('express-jwt')
|
||||||
const jwksRsa = require('jwks-rsa')
|
const jwksRsa = require('jwks-rsa')
|
||||||
const nodemailer = require('nodemailer')
|
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
|
|
||||||
let upload = multer({dest: config.photos.uploadPath})
|
let upload = multer({dest: config.photos.uploadPath})
|
||||||
|
|
2
rbn.js
2
rbn.js
|
@ -13,7 +13,7 @@ class RbnReceiver {
|
||||||
|
|
||||||
wsManager.on('message', (ws, message) => {
|
wsManager.on('message', (ws, message) => {
|
||||||
if (message.rbnFilter !== undefined) {
|
if (message.rbnFilter !== undefined) {
|
||||||
console.log("Set RBN filter to " + JSON.stringify(message.rbnFilter));
|
//console.log("Set RBN filter to " + JSON.stringify(message.rbnFilter));
|
||||||
ws.rbnFilter = message.rbnFilter;
|
ws.rbnFilter = message.rbnFilter;
|
||||||
|
|
||||||
this.sendSpotHistory(ws)
|
this.sendSpotHistory(ws)
|
||||||
|
|
|
@ -30,7 +30,7 @@ class SotaSpotReceiver {
|
||||||
if (this.latestSpots.getLength() == 0) {
|
if (this.latestSpots.getLength() == 0) {
|
||||||
numSpotsToLoad = config.sotaspots.initialLoadSpots;
|
numSpotsToLoad = config.sotaspots.initialLoadSpots;
|
||||||
}
|
}
|
||||||
console.log(`load ${numSpotsToLoad} spots`);
|
console.log(`Load ${numSpotsToLoad} spots`);
|
||||||
axios.get(config.sotaspots.url + '/' + numSpotsToLoad + '/all')
|
axios.get(config.sotaspots.url + '/' + numSpotsToLoad + '/all')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let minSpotId = undefined;
|
let minSpotId = undefined;
|
||||||
|
|
74
spots.js
74
spots.js
|
@ -1,74 +0,0 @@
|
||||||
const axios = require('axios');
|
|
||||||
const wsManager = require('./ws-manager');
|
|
||||||
const config = require('./config');
|
|
||||||
const db = require('./db');
|
|
||||||
const TreeMap = require("treemap-js");
|
|
||||||
|
|
||||||
const latestSpots = new TreeMap();
|
|
||||||
const maxSpots = 100;
|
|
||||||
const updateInterval = 30000;
|
|
||||||
let lastUpdate = null;
|
|
||||||
|
|
||||||
wsManager.on('connect', (ws) => {
|
|
||||||
let spots = []
|
|
||||||
latestSpots.each(spot => {
|
|
||||||
spots.push(spot)
|
|
||||||
});
|
|
||||||
wsManager.unicast({spots}, ws);
|
|
||||||
})
|
|
||||||
|
|
||||||
loadSpots();
|
|
||||||
setInterval(loadSpots, updateInterval);
|
|
||||||
|
|
||||||
function loadSpots() {
|
|
||||||
console.log('load spots');
|
|
||||||
axios.get('https://sota-api2.azurewebsites.net/api/spots/' + maxSpots + '/all')
|
|
||||||
.then(response => {
|
|
||||||
response.data.forEach(spot => {
|
|
||||||
spot.summit = {code: spot.associationCode + '/' + spot.summitCode};
|
|
||||||
delete spot.associationCode;
|
|
||||||
delete spot.summitCode;
|
|
||||||
delete spot.summitDetails;
|
|
||||||
delete spot.highlightColor;
|
|
||||||
if (spot.comments === '(null)') {
|
|
||||||
spot.comments = '';
|
|
||||||
}
|
|
||||||
updateSpot(spot);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateSpot(spot) {
|
|
||||||
// Check if we already have this spot in the list, and if it has changed
|
|
||||||
if (spotsAreEqual(latestSpots.get(spot.id), spot)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spot is new or modified
|
|
||||||
console.log("New/modified spot id " + spot.id);
|
|
||||||
lookupSummit(spot.summit.code)
|
|
||||||
.then(summit => {
|
|
||||||
if (summit) {
|
|
||||||
spot.summit = summit;
|
|
||||||
}
|
|
||||||
|
|
||||||
latestSpots.set(spot.id, spot);
|
|
||||||
while (latestSpots.getLength() > maxSpots) {
|
|
||||||
latestSpots.remove(latestSpots.getMinKey());
|
|
||||||
}
|
|
||||||
wsManager.broadcast({spot});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function lookupSummit(summitCode, callback) {
|
|
||||||
return db.getDb().collection('summits').findOne({code: summitCode}, {projection: {'_id': false, code: true, name: true, altitude: true, points: true, activationCount: true}});
|
|
||||||
}
|
|
||||||
|
|
||||||
function spotsAreEqual(spot1, spot2) {
|
|
||||||
if (spot1 === undefined || spot2 === undefined) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (spot1.id === spot2.id && spot1.comments === spot2.comments && spot1.callsign === spot2.callsign &&
|
|
||||||
spot1.summit.code === spot2.summit.code && spot1.activatorCallsign === spot2.activatorCallsign &&
|
|
||||||
spot1.frequency === spot2.frequency && spot1.mode === spot2.mode);
|
|
||||||
}
|
|
|
@ -11,7 +11,7 @@ class WebSocketManager extends EventEmitter {
|
||||||
this.router = express.Router();
|
this.router = express.Router();
|
||||||
|
|
||||||
this.router.ws('/', (ws, req) => {
|
this.router.ws('/', (ws, req) => {
|
||||||
console.log('WebSocket client connected');
|
//console.log('WebSocket client connected');
|
||||||
ws.isAlive = true;
|
ws.isAlive = true;
|
||||||
this.webSocketClients.add(ws);
|
this.webSocketClients.add(ws);
|
||||||
console.log("Number of clients: " + this.webSocketClients.size);
|
console.log("Number of clients: " + this.webSocketClients.size);
|
||||||
|
@ -28,7 +28,7 @@ class WebSocketManager extends EventEmitter {
|
||||||
ws.isAlive = true;
|
ws.isAlive = true;
|
||||||
});
|
});
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
console.log("WebSocket closed");
|
//console.log("WebSocket closed");
|
||||||
clearInterval(ws.pingInterval);
|
clearInterval(ws.pingInterval);
|
||||||
this.webSocketClients.delete(ws);
|
this.webSocketClients.delete(ws);
|
||||||
console.log("Number of clients: " + this.webSocketClients.size);
|
console.log("Number of clients: " + this.webSocketClients.size);
|
||||||
|
@ -42,7 +42,7 @@ class WebSocketManager extends EventEmitter {
|
||||||
|
|
||||||
ws.pingInterval = setInterval(() => {
|
ws.pingInterval = setInterval(() => {
|
||||||
if (!ws.isAlive) {
|
if (!ws.isAlive) {
|
||||||
console.log("WebSocket ping timeout");
|
//console.log("WebSocket ping timeout");
|
||||||
ws.terminate();
|
ws.terminate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue