2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-04-07 00:20:33 +08:00
|
|
|
const layergroupToken = require('../middlewares/layergroup-token');
|
|
|
|
const cleanUpQueryParams = require('../middlewares/clean-up-query-params');
|
|
|
|
const credentials = require('../middlewares/credentials');
|
|
|
|
const dbConnSetup = require('../middlewares/db-conn-setup');
|
|
|
|
const authorize = require('../middlewares/authorize');
|
|
|
|
const rateLimit = require('../middlewares/rate-limit');
|
2018-03-24 04:20:37 +08:00
|
|
|
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
|
|
|
|
const dbParamsFromResLocals = require('../../utils/database-params');
|
|
|
|
|
2018-03-29 01:37:31 +08:00
|
|
|
module.exports = class AnalysisLayergroupController {
|
2018-04-12 00:51:44 +08:00
|
|
|
constructor (analysisStatusBackend, pgConnection, userLimitsBackend, authBackend) {
|
2018-03-24 04:20:37 +08:00
|
|
|
this.analysisStatusBackend = analysisStatusBackend;
|
|
|
|
this.pgConnection = pgConnection;
|
2018-04-10 16:16:07 +08:00
|
|
|
this.userLimitsBackend = userLimitsBackend;
|
2018-04-10 00:08:56 +08:00
|
|
|
this.authBackend = authBackend;
|
2018-03-24 04:20:37 +08:00
|
|
|
}
|
|
|
|
|
2019-10-04 18:22:23 +08:00
|
|
|
route (mapRouter) {
|
2018-05-11 18:38:52 +08:00
|
|
|
mapRouter.get('/:token/analysis/node/:nodeId', this.middlewares());
|
|
|
|
}
|
|
|
|
|
|
|
|
middlewares () {
|
|
|
|
return [
|
2018-03-24 04:20:37 +08:00
|
|
|
layergroupToken(),
|
|
|
|
credentials(),
|
2018-04-10 00:08:56 +08:00
|
|
|
authorize(this.authBackend),
|
2018-03-24 04:20:37 +08:00
|
|
|
dbConnSetup(this.pgConnection),
|
2018-04-10 16:16:07 +08:00
|
|
|
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ANALYSIS),
|
2018-03-24 04:20:37 +08:00
|
|
|
cleanUpQueryParams(),
|
2018-04-05 01:15:51 +08:00
|
|
|
analysisNodeStatus(this.analysisStatusBackend)
|
2018-05-11 18:38:52 +08:00
|
|
|
];
|
2018-03-24 04:20:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function analysisNodeStatus (analysisStatusBackend) {
|
|
|
|
return function analysisNodeStatusMiddleware(req, res, next) {
|
|
|
|
const { nodeId } = req.params;
|
|
|
|
const dbParams = dbParamsFromResLocals(res.locals);
|
|
|
|
|
|
|
|
analysisStatusBackend.getNodeStatus(nodeId, dbParams, (err, nodeStatus, stats = {}) => {
|
|
|
|
req.profiler.add(stats);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
err.label = 'GET NODE STATUS';
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.set({
|
|
|
|
'Cache-Control': 'public,max-age=5',
|
|
|
|
'Last-Modified': new Date().toUTCString()
|
|
|
|
});
|
|
|
|
|
2018-05-09 21:00:18 +08:00
|
|
|
res.statusCode = 200;
|
2018-03-24 04:20:37 +08:00
|
|
|
res.body = nodeStatus;
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|