fix: startup blocked list refresh
This commit is contained in:
parent
05802aa950
commit
f760346265
3 changed files with 2 additions and 62 deletions
3
index.js
3
index.js
|
@ -31,7 +31,6 @@ 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 },
|
||||
|
@ -136,7 +135,7 @@ function Server () {
|
|||
}
|
||||
logger.info(`Peforming updates...`);
|
||||
return Promise.all([
|
||||
refreshBlockedList(),
|
||||
db.Blocked.refreshTable(),
|
||||
db.Tor.refreshTable(),
|
||||
])
|
||||
.then(([updatedBlockedList, updatedTorList]) => {
|
||||
|
|
|
@ -20,7 +20,7 @@ const torCheck = (req, res, next) => {
|
|||
};
|
||||
res.status(403).json(failureResponse);
|
||||
} else {
|
||||
next();
|
||||
return next();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
const logger = require('winston');
|
||||
const db = require('../index.js');
|
||||
|
||||
const refreshBlockedList = () => {
|
||||
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 => {
|
||||
db.Claim.findAll({
|
||||
where: {
|
||||
outpoint: outpoints,
|
||||
},
|
||||
});
|
||||
|
||||
let updatePromises = [];
|
||||
outpoints.forEach(outpoint => {
|
||||
logger.debug('blocked outpoint:', outpoint);
|
||||
updatePromises.push(db.Claim
|
||||
.findOne({
|
||||
where: {
|
||||
outpoint,
|
||||
},
|
||||
})
|
||||
.then(Claim => {
|
||||
if (Claim) {
|
||||
const { claimId, name } = Claim;
|
||||
const blocked = {
|
||||
claimId,
|
||||
name,
|
||||
outpoint,
|
||||
};
|
||||
return db.upsert(db.Blocked, blocked, blocked, 'Blocked');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
logger.error(error);
|
||||
}));
|
||||
});
|
||||
return Promise.all(updatePromises);
|
||||
})
|
||||
.then(() => {
|
||||
return db.Blocked.findAll({raw: true});
|
||||
})
|
||||
.catch(error => {
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = refreshBlockedList;
|
Loading…
Add table
Reference in a new issue