diff --git a/server/controllers/api/claim/blockedList/index.js b/server/controllers/api/claim/blockedList/index.js new file mode 100644 index 00000000..abc80d8e --- /dev/null +++ b/server/controllers/api/claim/blockedList/index.js @@ -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; diff --git a/server/routes/api/index.js b/server/routes/api/index.js index a1a46974..4eda3f2a 100644 --- a/server/routes/api/index.js +++ b/server/routes/api/index.js @@ -3,13 +3,14 @@ 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'); const claimLongId = require('../../controllers/api/claim/longId'); const claimPublish = require('../../controllers/api/claim/publish'); const claimResolve = require('../../controllers/api/claim/resolve'); const claimShortId = require('../../controllers/api/claim/shortId'); -const claimList = require('../../controllers/api/claim/list'); const fileAvailability = require('../../controllers/api/file/availability'); const multipartMiddleware = require('../utils/multipartMiddleware'); @@ -21,14 +22,15 @@ module.exports = (app) => { app.get('/api/channel/data/:channelName/:channelClaimId', channelData); app.get('/api/channel/claims/:channelName/:channelClaimId/:page', channelClaims); // 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/resolve/:name/:claimId', claimResolve); - 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/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); + 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 app.get('/api/file/availability/:name/:claimId', fileAvailability); };