updated startup to refresh blocked list
This commit is contained in:
parent
7a0a4820c9
commit
752d679d4f
4 changed files with 39 additions and 16 deletions
3
index.js
3
index.js
|
@ -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]) => {
|
||||
|
|
22
server/controllers/api/blocked/index.js
Normal file
22
server/controllers/api/blocked/index.js
Normal 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;
|
|
@ -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;
|
|
@ -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', 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);
|
||||
|
@ -43,4 +44,6 @@ module.exports = (app) => {
|
|||
app.get('/api/config/site/publishing', publishingConfig);
|
||||
// tor
|
||||
app.get('/api/tor', getTorList);
|
||||
// blocked
|
||||
app.get('/api/blocked', getBlockedList);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue