changed so completion of lbrynet download is not blocking play
This commit is contained in:
parent
4a4cdb23f7
commit
8bdbf05251
2 changed files with 2 additions and 36 deletions
|
@ -72,19 +72,12 @@ 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]); // note: make this 'upsert' ?
|
return Promise.all([db.File.create(fileData), getResult]); // insert a record for the claim into the File table
|
||||||
})
|
})
|
||||||
.then(([ fileRecord, {message, completed} ]) => {
|
.then(([ fileRecord, {message, completed} ]) => {
|
||||||
res.status(200).json({ status: 'success', message, completed });
|
res.status(200).json({ status: 'success', message, completed });
|
||||||
if (fileRecord) {
|
|
||||||
logger.debug('File record successfully created');
|
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);
|
||||||
|
|
|
@ -116,33 +116,6 @@
|
||||||
// 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