412 blocked content #428
2 changed files with 65 additions and 7 deletions
56
server/controllers/api/claim/blockedList/index.js
Normal file
56
server/controllers/api/claim/blockedList/index.js
Normal 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')
|
||||||
the second argument is the content to insert and the third argument is the conditional for the the second argument is the content to insert and the third argument is the conditional for the `upsert`. So in this case, update/insert the `blocked` record based on whether that exact `blocked` record already exists . In this call to `upsert` it is duplicative to have two separate arguments, but in other uses it is helpful to have search criteria that doesn't match the inserted criteria specifically. I.e. upsert `blocked` where `{claimId: 'abc123...xyz}`
|
|||||||
|
}
|
||||||
|
})
|
||||||
|
.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;
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue
This is probably because I don't understand
upsert
that well but whyblocked, blocked
?