moved response into middleware
This commit is contained in:
parent
d01db5b5df
commit
60ee901faf
3 changed files with 26 additions and 29 deletions
|
@ -35,17 +35,6 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
|
|||
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
|
||||
let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, license, name, nsfw, thumbnail, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title;
|
||||
// record the start time of the request
|
||||
|
|
|
@ -13,8 +13,16 @@ const torCheck = (req, res, next) => {
|
|||
})
|
||||
.then(result => {
|
||||
logger.debug('tor check results:', result);
|
||||
req['tor'] = (result.length >= 1); // add this to the req object
|
||||
next();
|
||||
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();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
logger.error(error);
|
||||
|
|
|
@ -21,26 +21,26 @@ const torCheckMiddleware = require('../../middleware/torCheckMiddleware');
|
|||
|
||||
module.exports = (app) => {
|
||||
// channel routes
|
||||
app.get('/api/channel/availability/:name', channelAvailability);
|
||||
app.get('/api/channel/short-id/:longId/:name', channelShortId);
|
||||
app.get('/api/channel/data/:channelName/:channelClaimId', channelData);
|
||||
app.get('/api/channel/claims/:channelName/:channelClaimId/:page', channelClaims);
|
||||
app.get('/api/channel/availability/:name', torCheckMiddleware, channelAvailability);
|
||||
app.get('/api/channel/short-id/:longId/:name', torCheckMiddleware, channelShortId);
|
||||
app.get('/api/channel/data/:channelName/:channelClaimId', torCheckMiddleware, channelData);
|
||||
app.get('/api/channel/claims/:channelName/:channelClaimId/:page', torCheckMiddleware, channelClaims);
|
||||
// claim routes
|
||||
app.get('/api/claim/availability/:name', claimAvailability);
|
||||
app.get('/api/claim/blocked-list/', claimBlockedList);
|
||||
app.get('/api/claim/data/:claimName/:claimId', claimData);
|
||||
app.get('/api/claim/get/:name/:claimId', claimGet);
|
||||
app.get('/api/claim/list/:name', claimList);
|
||||
app.post('/api/claim/long-id', claimLongId); // should be a get
|
||||
app.get('/api/claim/availability/:name', torCheckMiddleware, claimAvailability);
|
||||
app.get('/api/claim/blocked-list/', torCheckMiddleware, claimBlockedList);
|
||||
app.get('/api/claim/data/:claimName/:claimId', torCheckMiddleware, claimData);
|
||||
app.get('/api/claim/get/:name/:claimId', torCheckMiddleware, claimGet);
|
||||
app.get('/api/claim/list/:name', torCheckMiddleware, claimList);
|
||||
app.post('/api/claim/long-id', torCheckMiddleware, claimLongId); // note: should be a 'get'
|
||||
app.post('/api/claim/publish', torCheckMiddleware, multipartMiddleware, claimPublish);
|
||||
app.get('/api/claim/resolve/:name/:claimId', claimResolve);
|
||||
app.get('/api/claim/short-id/:longId/:name', claimShortId);
|
||||
app.get('/api/claim/resolve/:name/:claimId', torCheckMiddleware, claimResolve);
|
||||
app.get('/api/claim/short-id/:longId/:name', torCheckMiddleware, claimShortId);
|
||||
// file routes
|
||||
app.get('/api/file/availability/:name/:claimId', fileAvailability);
|
||||
app.get('/api/file/availability/:name/:claimId', torCheckMiddleware, fileAvailability);
|
||||
// user routes
|
||||
app.put('/api/user/password/', userPassword);
|
||||
app.put('/api/user/password/', torCheckMiddleware, userPassword);
|
||||
// configs
|
||||
app.get('/api/config/site/publishing', publishingConfig);
|
||||
app.get('/api/config/site/publishing', torCheckMiddleware, publishingConfig);
|
||||
// tor
|
||||
app.get('/api/tor', getTorList);
|
||||
app.get('/api/tor', torCheckMiddleware, getTorList);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue