moved response into middleware

This commit is contained in:
bill bittner 2018-06-28 17:58:51 -07:00
parent d01db5b5df
commit 60ee901faf
3 changed files with 26 additions and 29 deletions

View file

@ -35,17 +35,6 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
message: disabledMessage message: disabledMessage
}); });
} }
// check for tor
logger.debug('tor:', tor);
if (tor) {
logger.info('Tor publish request blocked:', ip);
const failureResponse = {
success: 'false',
message: 'Unfortunately this api route is not currently available for tor users. We are working on a solution that will allow tor users to use this endpoint in the future.',
};
return res.status(403).json(failureResponse);
}
// define variables // define variables
let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, license, name, nsfw, thumbnail, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title; let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, license, name, nsfw, thumbnail, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title;
// record the start time of the request // record the start time of the request

View file

@ -13,8 +13,16 @@ const torCheck = (req, res, next) => {
}) })
.then(result => { .then(result => {
logger.debug('tor check results:', result); logger.debug('tor check results:', result);
req['tor'] = (result.length >= 1); // add this to the req object if (result.length >= 1) {
logger.info('Tor request blocked:', ip);
const failureResponse = {
success: false,
message: 'Unfortunately this api route is not currently available for tor users. We are working on a solution that will allow tor users to use this endpoint in the future.',
};
res.status(403).json(failureResponse);
} else {
next(); next();
}
}) })
.catch(error => { .catch(error => {
logger.error(error); logger.error(error);

View file

@ -21,26 +21,26 @@ const torCheckMiddleware = require('../../middleware/torCheckMiddleware');
module.exports = (app) => { module.exports = (app) => {
// channel routes // channel routes
app.get('/api/channel/availability/:name', channelAvailability); app.get('/api/channel/availability/:name', torCheckMiddleware, channelAvailability);
app.get('/api/channel/short-id/:longId/:name', channelShortId); app.get('/api/channel/short-id/:longId/:name', torCheckMiddleware, channelShortId);
app.get('/api/channel/data/:channelName/:channelClaimId', channelData); app.get('/api/channel/data/:channelName/:channelClaimId', torCheckMiddleware, channelData);
app.get('/api/channel/claims/:channelName/:channelClaimId/:page', channelClaims); app.get('/api/channel/claims/:channelName/:channelClaimId/:page', torCheckMiddleware, channelClaims);
// claim routes // claim routes
app.get('/api/claim/availability/:name', claimAvailability); app.get('/api/claim/availability/:name', torCheckMiddleware, claimAvailability);
app.get('/api/claim/blocked-list/', claimBlockedList); app.get('/api/claim/blocked-list/', torCheckMiddleware, claimBlockedList);
app.get('/api/claim/data/:claimName/:claimId', claimData); app.get('/api/claim/data/:claimName/:claimId', torCheckMiddleware, claimData);
app.get('/api/claim/get/:name/:claimId', claimGet); app.get('/api/claim/get/:name/:claimId', torCheckMiddleware, claimGet);
app.get('/api/claim/list/:name', claimList); app.get('/api/claim/list/:name', torCheckMiddleware, claimList);
app.post('/api/claim/long-id', claimLongId); // should be a get app.post('/api/claim/long-id', torCheckMiddleware, claimLongId); // note: should be a 'get'
app.post('/api/claim/publish', torCheckMiddleware, multipartMiddleware, claimPublish); app.post('/api/claim/publish', torCheckMiddleware, multipartMiddleware, claimPublish);
app.get('/api/claim/resolve/:name/:claimId', claimResolve); app.get('/api/claim/resolve/:name/:claimId', torCheckMiddleware, claimResolve);
app.get('/api/claim/short-id/:longId/:name', claimShortId); app.get('/api/claim/short-id/:longId/:name', torCheckMiddleware, claimShortId);
// file routes // file routes
app.get('/api/file/availability/:name/:claimId', fileAvailability); app.get('/api/file/availability/:name/:claimId', torCheckMiddleware, fileAvailability);
// user routes // user routes
app.put('/api/user/password/', userPassword); app.put('/api/user/password/', torCheckMiddleware, userPassword);
// configs // configs
app.get('/api/config/site/publishing', publishingConfig); app.get('/api/config/site/publishing', torCheckMiddleware, publishingConfig);
// tor // tor
app.get('/api/tor', getTorList); app.get('/api/tor', torCheckMiddleware, getTorList);
}; };