From c9a171ae285d5957ba9bd3b1739e82cff42fe800 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Thu, 16 Feb 2017 20:50:09 -0500 Subject: [PATCH] Update how Publish page polls for file appearing in file manager Formerly polled the full list of files; now looks up the specific file by name. --- js/lbry.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/js/lbry.js b/js/lbry.js index 2800bac44..088bccf9a 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -245,8 +245,8 @@ lbry.getCostInfoForName = function(name, callback, errorCallback) { }); } -lbry.getFileStatus = function(name, callback) { - lbry.call('get_lbry_file', { 'name': name }, callback); +lbry.getFileStatus = function(name, callback, errorCallback) { + lbry.call('get_lbry_file', { 'name': name }, callback, errorCallback); } lbry.getFilesInfo = function(callback) { @@ -296,22 +296,23 @@ lbry.revealFile = function(sdHash, callback) { } 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(). - // 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; - } - } - + function scheduleNextCheckOrTimeout() { if (timeoutCallback && tryNum > 200) { timeoutCallback(); } 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) {