Block used claims #68
3 changed files with 88 additions and 73 deletions
|
@ -19,15 +19,53 @@ function upsert (Model, values, condition) {
|
|||
});
|
||||
}
|
||||
|
||||
function checkNameAvailability (name) {
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
// find any records where the name is used
|
||||
db.File
|
||||
.findAll({ where: { name } })
|
||||
.then(result => {
|
||||
if (result.length >= 1) {
|
||||
// filter out any results that were not published from a spee.ch wallet address
|
||||
lbryApi
|
||||
.getWalletList()
|
||||
.then((walletList) => {
|
||||
const filteredResult = result.filter((claim) => {
|
||||
return walletList.includes(claim.address);
|
||||
});
|
||||
if (filteredResult.length >= 1) {
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
return deferred;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
publish (publishParams, fileName, fileType) {
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
// 1. publish the file
|
||||
// 1. make sure the name is available
|
||||
checkNameAvailability(publishParams.name)
|
||||
.then(result => {
|
||||
if (result === true) {
|
||||
// 2. publish the file
|
||||
lbryApi
|
||||
.publishClaim(publishParams)
|
||||
.then(result => {
|
||||
logger.info(`Successfully published ${fileName}`, result);
|
||||
// 2. update old record or create new one (update is in case the claim has been published before by this daemon)
|
||||
// 3. update old record or create new one (update is in case the claim has been published before by this daemon)
|
||||
upsert(
|
||||
db.File,
|
||||
{
|
||||
|
@ -61,34 +99,9 @@ module.exports = {
|
|||
// reject the promise
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
return deferred;
|
||||
},
|
||||
checkNameAvailability (name) {
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
// find any records where the name is used
|
||||
db.File
|
||||
.findAll({ where: { name } })
|
||||
.then(result => {
|
||||
if (result.length >= 1) {
|
||||
// filter out any results that were not published from a spee.ch wallet address
|
||||
lbryApi
|
||||
.getWalletList()
|
||||
.then((walletList) => {
|
||||
const filteredResult = result.filter((claim) => {
|
||||
return walletList.includes(claim.address);
|
||||
});
|
||||
if (filteredResult.length >= 1) {
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
resolve(true);
|
||||
const err = new Error('That name has already been claimed by spee.ch. Please choose a new claim name.');
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
@ -97,4 +110,7 @@ module.exports = {
|
|||
});
|
||||
return deferred;
|
||||
},
|
||||
checkNameAvailability (name) {
|
||||
return checkNameAvailability(name);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ const { postToStats } = require('../../controllers/statsController.js');
|
|||
|
||||
module.exports = {
|
||||
handleRequestError (action, originalUrl, ip, error, res) {
|
||||
logger.error('Request Error >>', error);
|
||||
logger.error('Request Error >>', error.message);
|
||||
if (error.response) {
|
||||
postToStats(action, originalUrl, ip, error.response.data.error.messsage);
|
||||
res.status(error.response.status).send(error.response.data.error.message);
|
||||
|
@ -12,7 +12,7 @@ module.exports = {
|
|||
res.status(503).send('Connection refused. The daemon may not be running.');
|
||||
} else {
|
||||
postToStats(action, originalUrl, ip, error);
|
||||
res.status(400).send(JSON.stringify(error));
|
||||
res.status(400).send(error.message);
|
||||
}
|
||||
},
|
||||
handlePublishError (error) {
|
||||
|
|
|
@ -123,7 +123,6 @@ document.getElementById('publish-submit').addEventListener('click', function(eve
|
|||
} else {
|
||||
alert("That name has already been claimed by spee.ch. Please choose a different name.");
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("request to check claim name failed with status:", this.status);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue