added api endpoint to trigger blocked-list refresh

This commit is contained in:
bill bittner 2018-04-29 15:30:11 -07:00
parent bbd691018b
commit 6c97b40c32
2 changed files with 65 additions and 7 deletions

View file

@ -0,0 +1,56 @@
const logger = require('winston');
const db = require('../../../../models');
const updateBlockedList = (req, res) => {
return fetch('https://api.lbry.io/file/list_blocked')
.then(response => {
return response.json();
})
.then(jsonResponse => {
if (!jsonResponse.data) {
throw new Error('no data in list_blocked response');
}
if (!jsonResponse.data.outpoints) {
throw new Error('no outpoints in list_blocked response');
}
return jsonResponse.data.outpoints;
})
.then(outpoints => {
logger.info('number of blocked outpoints:', outpoints.length);
let updatePromises = [];
outpoints.forEach(outpoint => {
// logger.debug('outpoint:', outpoint);
updatePromises.push(db.Claim
.findOne({
where: {
outpoint,
},
})
.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')
}
})
.catch(error => {
logger.error(error);
}));
});
return Promise.all(updatePromises);
})
.then(() => {
logger.info('finished updating blocked content list');
res.status(200).json({success: true, message: 'finished updating blocked content list'});
})
.catch((error) => {
logger.error(error);
});
};
module.exports = updateBlockedList;

View file

@ -3,13 +3,14 @@ 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 claimLongId = require('../../controllers/api/claim/longId'); const claimLongId = require('../../controllers/api/claim/longId');
const claimPublish = require('../../controllers/api/claim/publish'); const claimPublish = require('../../controllers/api/claim/publish');
const claimResolve = require('../../controllers/api/claim/resolve'); const claimResolve = require('../../controllers/api/claim/resolve');
const claimShortId = require('../../controllers/api/claim/shortId'); const claimShortId = require('../../controllers/api/claim/shortId');
const claimList = require('../../controllers/api/claim/list');
const fileAvailability = require('../../controllers/api/file/availability'); const fileAvailability = require('../../controllers/api/file/availability');
const multipartMiddleware = require('../utils/multipartMiddleware'); const multipartMiddleware = require('../utils/multipartMiddleware');
@ -21,14 +22,15 @@ module.exports = (app) => {
app.get('/api/channel/data/:channelName/:channelClaimId', channelData); app.get('/api/channel/data/:channelName/:channelClaimId', channelData);
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/list/:name', claimList);
app.get('/api/claim/get/:name/:claimId', claimGet);
app.get('/api/claim/availability/:name', claimAvailability); app.get('/api/claim/availability/:name', claimAvailability);
app.get('/api/claim/resolve/:name/:claimId', claimResolve); app.get('/api/claim/blocked-list/', claimBlockedList);
app.post('/api/claim/publish', multipartMiddleware, claimPublish);
app.get('/api/claim/short-id/:longId/:name', claimShortId);
app.post('/api/claim/long-id', claimLongId);
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/list/:name', claimList);
app.post('/api/claim/long-id', claimLongId);
app.post('/api/claim/publish', multipartMiddleware, claimPublish);
app.get('/api/claim/resolve/:name/:claimId', claimResolve);
app.get('/api/claim/short-id/:longId/:name', claimShortId);
// file routes // file routes
app.get('/api/file/availability/:name/:claimId', fileAvailability); app.get('/api/file/availability/:name/:claimId', fileAvailability);
}; };