diff --git a/server/controllers/api/claim/publish/index.js b/server/controllers/api/claim/publish/index.js index d5f6a312..ca958e4b 100644 --- a/server/controllers/api/claim/publish/index.js +++ b/server/controllers/api/claim/publish/index.js @@ -1,3 +1,5 @@ +const logger = require('winston'); + const { details: { host }, publishing: { disabled, disabledMessage } } = require('@config/siteConfig'); 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 if (disabled) { return res.status(503).json({ @@ -27,6 +29,16 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user }, res) => { 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 let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, license, name, nsfw, thumbnail, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title; // record the start time of the request diff --git a/server/middleware/torCheckMiddleware.js b/server/middleware/torCheckMiddleware.js index bb4d9840..3d415417 100644 --- a/server/middleware/torCheckMiddleware.js +++ b/server/middleware/torCheckMiddleware.js @@ -1,7 +1,8 @@ const logger = require('winston'); 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}`); return db.Tor.findAll( { @@ -12,17 +13,8 @@ const torCheck = ({ ip, headers, body }, res, next) => { }) .then(result => { logger.debug('tor check results:', result); - if (result.length >= 1) { - logger.debug('this is a tor 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(400).json(failureResponse); - } else { - logger.debug('this is not a tor ip'); - return next(); - } + req['tor'] = (result.length >= 1); // add this to the req object + next(); }) .catch(error => { logger.error(error);