added loop to check if asset is fully downloaded;
This commit is contained in:
parent
a98d541450
commit
4a4cdb23f7
2 changed files with 37 additions and 17 deletions
|
@ -72,12 +72,19 @@ module.exports = (app) => {
|
||||||
return Promise.all([fileData, getClaim(`${params.name}#${params.claimId}`)]);
|
return Promise.all([fileData, getClaim(`${params.name}#${params.claimId}`)]);
|
||||||
})
|
})
|
||||||
.then(([ fileData, getResult ]) => {
|
.then(([ fileData, getResult ]) => {
|
||||||
|
if (getResult.completed !== true) {
|
||||||
|
return Promise.all([null, getResult]); // pass get results to next function
|
||||||
|
}
|
||||||
fileData = addGetResultsToFileData(fileData, getResult);
|
fileData = addGetResultsToFileData(fileData, getResult);
|
||||||
return Promise.all([db.File.create(fileData), getResult]); // insert a record for the claim into the File table
|
return Promise.all([db.File.create(fileData), getResult]); // note: make this 'upsert' ?
|
||||||
})
|
})
|
||||||
.then(([ fileRecord, {message, completed} ]) => {
|
.then(([ fileRecord, {message, completed} ]) => {
|
||||||
res.status(200).json({ status: 'success', message, completed });
|
res.status(200).json({ status: 'success', message, completed });
|
||||||
logger.debug('File record successfully created');
|
if (fileRecord) {
|
||||||
|
logger.debug('File record successfully created');
|
||||||
|
} else {
|
||||||
|
logger.debug('No file record created');
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleApiError('get', originalUrl, ip, error, res);
|
errorHandlers.handleApiError('get', originalUrl, ip, error, res);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<div id="asset-display-component">
|
<div id="asset-display-component">
|
||||||
<div id="asset-status">
|
<div id="asset-status">
|
||||||
<p id="searching-message" hidden="true">Sit tight, we're combing the LBRY blockchain for your asset!</p>
|
<p id="searching-message" hidden="true">Sit tight, we're combing the LBRY blockchain for your asset!</p>
|
||||||
<p id="in-progress-message" hidden="true">Hooray! We found peers with copies of your asset and we are downloading it from the blockchain now.</p>
|
|
||||||
<div id="failure-message" hidden="true">
|
<div id="failure-message" hidden="true">
|
||||||
<p>Unfortunately, we couldn't download your asset from LBRY. You can help us out by sharing the below error message in the <a class="link--primary" href="https://discord.gg/YjYbwhS" target="_blank">LBRY discord</a>.</p>
|
<p>Unfortunately, we couldn't download your asset from LBRY. You can help us out by sharing the below error message in the <a class="link--primary" href="https://discord.gg/YjYbwhS" target="_blank">LBRY discord</a>.</p>
|
||||||
<i><p id="error-message"></p></i>
|
<i><p id="error-message"></p></i>
|
||||||
|
@ -57,12 +56,6 @@
|
||||||
const searchMessage = document.getElementById('searching-message');
|
const searchMessage = document.getElementById('searching-message');
|
||||||
searchMessage.hidden = false;
|
searchMessage.hidden = false;
|
||||||
},
|
},
|
||||||
showInProgressMessage: function () {
|
|
||||||
const searchMessage = document.getElementById('searching-message');
|
|
||||||
const inProgressMessage = document.getElementById('in-progress-message');
|
|
||||||
searchMessage.hidden = true;
|
|
||||||
inProgressMessage.hidden = false;
|
|
||||||
},
|
|
||||||
showFailureMessage: function (msg) {
|
showFailureMessage: function (msg) {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
const searchMessage = document.getElementById('searching-message');
|
const searchMessage = document.getElementById('searching-message');
|
||||||
|
@ -111,14 +104,7 @@
|
||||||
const response = JSON.parse(xhr.response);
|
const response = JSON.parse(xhr.response);
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
console.log('get returned successfully', response);
|
console.log('get returned successfully', response);
|
||||||
if (response.completed === true) {
|
that.showAsset();
|
||||||
console.log('lbrynet has finished downloading the asset');
|
|
||||||
that.showAsset();
|
|
||||||
} else {
|
|
||||||
console.log('lbrynet has not finished downloading the asset');
|
|
||||||
that.showInProgressMessage();
|
|
||||||
setTimeout(that.getAsset.bind(that, claimName, claimId), 5000);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
console.log('get failed:', response);
|
console.log('get failed:', response);
|
||||||
that.showFailureMessage(`${response.message}`);
|
that.showFailureMessage(`${response.message}`);
|
||||||
|
@ -130,6 +116,33 @@
|
||||||
// Initiate a multipart/form-data upload
|
// Initiate a multipart/form-data upload
|
||||||
xhr.send();
|
xhr.send();
|
||||||
},
|
},
|
||||||
|
checkIfAssetIsFullyDownloaded: function(claimName, claimId) {
|
||||||
|
// make a get request, and see fi the asset is fully downloaded.
|
||||||
|
console.log(`getting ${claimName}#${claimId}`)
|
||||||
|
var uri = `/api/get_claim/${claimName}/${claimId}`;
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
var that = this;
|
||||||
|
xhr.open("GET", uri, true);
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState == 4) {
|
||||||
|
const response = JSON.parse(xhr.response);
|
||||||
|
if (xhr.status == 200) {
|
||||||
|
console.log('get returned successfully', response);
|
||||||
|
if (response.completed === true) {
|
||||||
|
console.log('lbrynet has finished downloading the asset');
|
||||||
|
} else {
|
||||||
|
console.log('lbrynet has not finished downloading the asset');
|
||||||
|
setTimeout(that.checkIfAssetIsFullyDownloaded.bind(that, claimName, claimId), 5000);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('get failed:', response);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('xhr.readyState', xhr.readyState);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getAssetFunctions.checkClaimAvailability('{{claimInfo.name}}', '{{claimInfo.claimId}}');
|
getAssetFunctions.checkClaimAvailability('{{claimInfo.name}}', '{{claimInfo.claimId}}');
|
||||||
|
|
Loading…
Reference in a new issue