Merge pull request #169 from lbryio/update-publish-poll

Update how Publish page polls for file appearing in file manager
This commit is contained in:
alexliebowitz 2017-02-17 15:45:33 -05:00 committed by GitHub
commit d904744a31
2 changed files with 16 additions and 15 deletions

View file

@ -1 +1 @@
lbrynet>=0.5.0 lbrynet>=0.8.4

View file

@ -245,8 +245,8 @@ lbry.getCostInfoForName = function(name, callback, errorCallback) {
}); });
} }
lbry.getFileStatus = function(name, callback) { lbry.getFileStatus = function(name, callback, errorCallback) {
lbry.call('get_lbry_file', { 'name': name }, callback); lbry.call('get_lbry_file', { 'name': name }, callback, errorCallback);
} }
lbry.getFilesInfo = function(callback) { lbry.getFilesInfo = function(callback) {
@ -296,22 +296,23 @@ lbry.revealFile = function(sdHash, callback) {
} }
lbry.getFileInfoWhenListed = function(name, callback, timeoutCallback, tryNum=0) { lbry.getFileInfoWhenListed = function(name, callback, timeoutCallback, tryNum=0) {
// Calls callback with file info when it appears in the list of files returned by lbry.getFilesInfo(). function scheduleNextCheckOrTimeout() {
// If timeoutCallback is provided, it will be called if the file fails to appear.
lbry.getFilesInfo(function(fileInfos) {
for (var fileInfo of fileInfos) {
if (fileInfo.lbry_uri == name) {
callback(fileInfo);
return;
}
}
if (timeoutCallback && tryNum > 200) { if (timeoutCallback && tryNum > 200) {
timeoutCallback(); timeoutCallback();
} else { } else {
setTimeout(function() { lbry.getFileInfoWhenListed(name, callback, timeoutCallback, tryNum + 1) }, 250); setTimeout(() => lbry.getFileInfoWhenListed(name, callback, timeoutCallback, tryNum + 1), 250);
} }
}); }
// Calls callback with file info when it appears in the lbrynet file manager.
// If timeoutCallback is provided, it will be called if the file fails to appear.
lbry.getFileStatus(name, (fileInfo) => {
if (fileInfo) {
callback(fileInfo);
} else {
scheduleNextCheckOrTimeout();
}
}, () => scheduleNextCheckOrTimeout());
} }
lbry.publish = function(params, fileListedCallback, publishedCallback, errorCallback) { lbry.publish = function(params, fileListedCallback, publishedCallback, errorCallback) {