added tor middleware response handling

This commit is contained in:
bill bittner 2018-06-27 18:10:47 -07:00
parent aed4e05b24
commit a46b157fe1
2 changed files with 17 additions and 13 deletions

View file

@ -1,3 +1,5 @@
const logger = require('winston');
const { details: { host }, publishing: { disabled, disabledMessage } } = require('@config/siteConfig'); const { details: { host }, publishing: { disabled, disabledMessage } } = require('@config/siteConfig');
const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js'); const { sendGATimingEvent } = require('../../../../utils/googleAnalytics.js');
@ -19,7 +21,7 @@ const authenticateUser = require('./authentication.js');
*/ */
const claimPublish = ({ body, files, headers, ip, originalUrl, user }, res) => { const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res) => {
// check for disabled publishing // check for disabled publishing
if (disabled) { if (disabled) {
return res.status(503).json({ return res.status(503).json({
@ -27,6 +29,16 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user }, res) => {
message: disabledMessage message: disabledMessage
}); });
} }
// check for tor
logger.debug('tor:', tor);
if (tor) {
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(400).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

@ -1,7 +1,8 @@
const logger = require('winston'); const logger = require('winston');
const db = require('../models'); const db = require('../models');
const torCheck = ({ ip, headers, body }, res, next) => { const torCheck = (req, res, next) => {
const { ip } = req;
logger.debug(`tor check for: ${ip}`); logger.debug(`tor check for: ${ip}`);
return db.Tor.findAll( return db.Tor.findAll(
{ {
@ -12,17 +13,8 @@ const torCheck = ({ ip, headers, body }, res, next) => {
}) })
.then(result => { .then(result => {
logger.debug('tor check results:', result); logger.debug('tor check results:', result);
if (result.length >= 1) { req['tor'] = (result.length >= 1); // add this to the req object
logger.debug('this is a tor ip'); next();
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(400).json(failureResponse);
} else {
logger.debug('this is not a tor ip');
return next();
}
}) })
.catch(error => { .catch(error => {
logger.error(error); logger.error(error);