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 configureLogging = require('./server/utils/configureLogging.js');
|
||||||
const configureSlack = require('./server/utils/configureSlack.js');
|
const configureSlack = require('./server/utils/configureSlack.js');
|
||||||
const speechPassport = require('./server/speechPassport');
|
const speechPassport = require('./server/speechPassport');
|
||||||
|
const refreshBlockedList = require('./server/models/utils/refreshBlockedList.js');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
details: { port: PORT },
|
details: { port: PORT },
|
||||||
|
@ -135,7 +136,7 @@ function Server () {
|
||||||
}
|
}
|
||||||
logger.info(`Peforming updates...`);
|
logger.info(`Peforming updates...`);
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
[],
|
refreshBlockedList(),
|
||||||
db.Tor.refreshTable(),
|
db.Tor.refreshTable(),
|
||||||
])
|
])
|
||||||
.then(([updatedBlockedList, updatedTorList]) => {
|
.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,7 +1,7 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const db = require('../../../../models');
|
const db = require('../index.js');
|
||||||
|
|
||||||
const updateBlockedList = (req, res) => {
|
const refreshBlockedList = () => {
|
||||||
return fetch('https://api.lbry.io/file/list_blocked')
|
return fetch('https://api.lbry.io/file/list_blocked')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return response.json();
|
return response.json();
|
||||||
|
@ -16,7 +16,6 @@ const updateBlockedList = (req, res) => {
|
||||||
return jsonResponse.data.outpoints;
|
return jsonResponse.data.outpoints;
|
||||||
})
|
})
|
||||||
.then(outpoints => {
|
.then(outpoints => {
|
||||||
logger.info('number of blocked outpoints:', outpoints.length);
|
|
||||||
let updatePromises = [];
|
let updatePromises = [];
|
||||||
outpoints.forEach(outpoint => {
|
outpoints.forEach(outpoint => {
|
||||||
// logger.debug('outpoint:', outpoint);
|
// logger.debug('outpoint:', outpoint);
|
||||||
|
@ -29,13 +28,12 @@ const updateBlockedList = (req, res) => {
|
||||||
.then(Claim => {
|
.then(Claim => {
|
||||||
if (Claim) {
|
if (Claim) {
|
||||||
const { claimId, name } = Claim;
|
const { claimId, name } = Claim;
|
||||||
logger.debug(`creating record in Blocked for ${name}#${claimId}`);
|
|
||||||
const blocked = {
|
const blocked = {
|
||||||
claimId,
|
claimId,
|
||||||
name,
|
name,
|
||||||
outpoint,
|
outpoint,
|
||||||
};
|
};
|
||||||
return db.upsert(db.Blocked, blocked, blocked, 'Blocked')
|
return db.upsert(db.Blocked, blocked, blocked, 'Blocked');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -45,12 +43,11 @@ const updateBlockedList = (req, res) => {
|
||||||
return Promise.all(updatePromises);
|
return Promise.all(updatePromises);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
logger.info('finished updating blocked content list');
|
return db.Blocked.findAll({raw: true});
|
||||||
res.status(200).json({success: true, message: 'finished updating blocked content list'});
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch(error => {
|
||||||
logger.error(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 channelAvailability = require('../../controllers/api/channel/availability');
|
||||||
const channelClaims = require('../../controllers/api/channel/claims');
|
const channelClaims = require('../../controllers/api/channel/claims');
|
||||||
const channelData = require('../../controllers/api/channel/data');
|
const channelData = require('../../controllers/api/channel/data');
|
||||||
const channelShortId = require('../../controllers/api/channel/shortId');
|
const channelShortId = require('../../controllers/api/channel/shortId');
|
||||||
const claimAvailability = require('../../controllers/api/claim/availability');
|
const claimAvailability = require('../../controllers/api/claim/availability');
|
||||||
const claimBlockedList = require('../../controllers/api/claim/blockedList');
|
|
||||||
const claimData = require('../../controllers/api/claim/data/');
|
const claimData = require('../../controllers/api/claim/data/');
|
||||||
const claimGet = require('../../controllers/api/claim/get');
|
const claimGet = require('../../controllers/api/claim/get');
|
||||||
const claimList = require('../../controllers/api/claim/list');
|
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 userPassword = require('../../controllers/api/user/password');
|
||||||
const publishingConfig = require('../../controllers/api/config/site/publishing');
|
const publishingConfig = require('../../controllers/api/config/site/publishing');
|
||||||
const getTorList = require('../../controllers/api/tor');
|
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) => {
|
module.exports = (app) => {
|
||||||
// channel routes
|
// channel routes
|
||||||
|
@ -27,7 +29,6 @@ module.exports = (app) => {
|
||||||
app.get('/api/channel/claims/:channelName/:channelClaimId/:page', channelClaims);
|
app.get('/api/channel/claims/:channelName/:channelClaimId/:page', channelClaims);
|
||||||
// claim routes
|
// claim routes
|
||||||
app.get('/api/claim/availability/:name', claimAvailability);
|
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/data/:claimName/:claimId', claimData);
|
||||||
app.get('/api/claim/get/:name/:claimId', claimGet);
|
app.get('/api/claim/get/:name/:claimId', claimGet);
|
||||||
app.get('/api/claim/list/:name', claimList);
|
app.get('/api/claim/list/:name', claimList);
|
||||||
|
@ -43,4 +44,6 @@ module.exports = (app) => {
|
||||||
app.get('/api/config/site/publishing', publishingConfig);
|
app.get('/api/config/site/publishing', publishingConfig);
|
||||||
// tor
|
// tor
|
||||||
app.get('/api/tor', getTorList);
|
app.get('/api/tor', getTorList);
|
||||||
|
// blocked
|
||||||
|
app.get('/api/blocked', getBlockedList);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue