Merge pull request #503 from lbryio/refresh-blocked-list-on-start

updated startup to refresh blocked list
This commit is contained in:
Bill Bittner 2018-06-29 10:00:04 -07:00 committed by GitHub
commit d2c6acaed5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 16 deletions

View file

@ -31,6 +31,7 @@ const { getWalletBalance } = require('./server/lbrynet');
const configureLogging = require('./server/utils/configureLogging.js');
const configureSlack = require('./server/utils/configureSlack.js');
const speechPassport = require('./server/speechPassport');
const refreshBlockedList = require('./server/models/utils/refreshBlockedList.js');
const {
details: { port: PORT },
@ -135,7 +136,7 @@ function Server () {
}
logger.info(`Peforming updates...`);
return Promise.all([
[],
refreshBlockedList(),
db.Tor.refreshTable(),
])
.then(([updatedBlockedList, updatedTorList]) => {

View file

@ -0,0 +1,22 @@
const logger = require('winston');
const refreshBlockedList = require('../../../models/utils/refreshBlockedList.js');
const updateBlockedList = (req, res) => {
refreshBlockedList()
.then(data => {
logger.info('finished updating blocked content list');
res.status(200).json({
success: true,
data,
});
})
.catch(error => {
logger.error(error);
res.status(500).json({
success: false,
error,
});
});
};
module.exports = updateBlockedList;

View file

@ -1,8 +1,8 @@
const logger = require('winston');
const db = require('../../../../models');
const db = require('../index.js');
const updateBlockedList = (req, res) => {
return fetch('https://api.lbry.io/file/list_blocked')
const refreshBlockedList = () => {
return fetch('https://api.lbry.io/file/list_blocked')
.then(response => {
return response.json();
})
@ -16,7 +16,6 @@ const updateBlockedList = (req, res) => {
return jsonResponse.data.outpoints;
})
.then(outpoints => {
logger.info('number of blocked outpoints:', outpoints.length);
let updatePromises = [];
outpoints.forEach(outpoint => {
// logger.debug('outpoint:', outpoint);
@ -29,13 +28,12 @@ const updateBlockedList = (req, res) => {
.then(Claim => {
if (Claim) {
const { claimId, name } = Claim;
logger.debug(`creating record in Blocked for ${name}#${claimId}`);
const blocked = {
claimId,
name,
outpoint,
};
return db.upsert(db.Blocked, blocked, blocked, 'Blocked')
return db.upsert(db.Blocked, blocked, blocked, 'Blocked');
}
})
.catch(error => {
@ -45,12 +43,11 @@ const updateBlockedList = (req, res) => {
return Promise.all(updatePromises);
})
.then(() => {
logger.info('finished updating blocked content list');
res.status(200).json({success: true, message: 'finished updating blocked content list'});
return db.Blocked.findAll({raw: true});
})
.catch((error) => {
logger.error(error);
.catch(error => {
throw error;
});
};
module.exports = updateBlockedList;
module.exports = refreshBlockedList;

View file

@ -1,9 +1,12 @@
// middleware
const multipartMiddleware = require('../../middleware/multipartMiddleware');
const torCheckMiddleware = require('../../middleware/torCheckMiddleware');
// route handlers
const channelAvailability = require('../../controllers/api/channel/availability');
const channelClaims = require('../../controllers/api/channel/claims');
const channelData = require('../../controllers/api/channel/data');
const channelShortId = require('../../controllers/api/channel/shortId');
const claimAvailability = require('../../controllers/api/claim/availability');
const claimBlockedList = require('../../controllers/api/claim/blockedList');
const claimData = require('../../controllers/api/claim/data/');
const claimGet = require('../../controllers/api/claim/get');
const claimList = require('../../controllers/api/claim/list');
@ -15,9 +18,8 @@ const fileAvailability = require('../../controllers/api/file/availability');
const userPassword = require('../../controllers/api/user/password');
const publishingConfig = require('../../controllers/api/config/site/publishing');
const getTorList = require('../../controllers/api/tor');
const getBlockedList = require('../../controllers/api/blocked');
const multipartMiddleware = require('../../middleware/multipartMiddleware');
const torCheckMiddleware = require('../../middleware/torCheckMiddleware');
module.exports = (app) => {
// channel routes
@ -27,7 +29,6 @@ module.exports = (app) => {
app.get('/api/channel/claims/:channelName/:channelClaimId/:page', torCheckMiddleware, channelClaims);
// claim routes
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);
@ -43,4 +44,6 @@ module.exports = (app) => {
app.get('/api/config/site/publishing', torCheckMiddleware, publishingConfig);
// tor
app.get('/api/tor', torCheckMiddleware, getTorList);
// blocked
app.get('/api/blocked', torCheckMiddleware, getBlockedList);
};