turned publish controller into promise
This commit is contained in:
parent
5c95b5c7ec
commit
edeb933f8a
1 changed files with 30 additions and 27 deletions
|
@ -26,33 +26,36 @@ function upsert (Model, values, condition) {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publish: (publishParams, fileName, fileType) => {
|
publish: (publishParams, fileName, fileType) => {
|
||||||
// 1. publish the file
|
const deferred = new Promise((resolve, reject) => {
|
||||||
lbryApi
|
// 1. publish the file
|
||||||
.publishClaim(publishParams)
|
lbryApi
|
||||||
.then(result => {
|
.publishClaim(publishParams)
|
||||||
logger.info(`Successfully published ${fileName}`, result);
|
.then(result => {
|
||||||
// 2. update old record of create new one (update is in case the claim has been published before by this daemon)
|
logger.info(`Successfully published ${fileName}`, result);
|
||||||
upsert(
|
// 2. update old record of create new one (update is in case the claim has been published before by this daemon)
|
||||||
db.File,
|
upsert(
|
||||||
{
|
db.File,
|
||||||
name : publishParams.name,
|
{
|
||||||
claimId : result.claim_id,
|
name : publishParams.name,
|
||||||
outpoint: `${result.txid}:${result.nout}`,
|
claimId : result.claim_id,
|
||||||
height : 0,
|
outpoint: `${result.txid}:${result.nout}`,
|
||||||
fileName,
|
height : 0,
|
||||||
filePath: publishParams.file_path,
|
fileName,
|
||||||
fileType,
|
filePath: publishParams.file_path,
|
||||||
nsfw : publishParams.metadata.nsfw,
|
fileType,
|
||||||
},
|
nsfw : publishParams.metadata.nsfw,
|
||||||
{ name: publishParams.name, claimId: result.claim_id }
|
},
|
||||||
).catch(error => {
|
{ name: publishParams.name, claimId: result.claim_id }
|
||||||
logger.error('Sequelize findOne error', error);
|
).catch(error => {
|
||||||
|
logger.error('Sequelize findOne error', error);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
logger.error(`Error publishing ${fileName}`, error);
|
||||||
|
// delete the local file
|
||||||
|
deleteTemporaryFile(publishParams.file_path);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
.catch(error => {
|
return deferred;
|
||||||
logger.error(`Error publishing ${fileName}`, error);
|
|
||||||
// delete the local file
|
|
||||||
deleteTemporaryFile(publishParams.file_path);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue