From f23d654a6b6995ec8154fcaebf5433251e45838f Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 16 Sep 2016 11:17:12 -0400 Subject: [PATCH 01/10] Add support for running code at start of publication process - Add lbry.getFileInfoWhenListed() - Modify publish() to take an optional callback for when the file is listed. --- js/lbry.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/js/lbry.js b/js/lbry.js index 21071164c..78291e868 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -169,14 +169,42 @@ lbry.revealFile = function(path, callback) { lbry.call('reveal', { path: path }, callback); } -lbry.publish = function(params, callback, errorCallback) { +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(filesInfo) { + for (var fileInfo of filesInfo) { + if (fileInfo.lbry_uri == name) { + callback(fileInfo); + return; + } + } + + if (tryNum <= 200) { + setTimeout(function() { lbry.getFileInfoWhenListed(name, callback, timeoutCallback, tryNum + 1) }, 250); + } else if (timeoutCallback) { + timeoutCallback(); + } + }); +} + +lbry.publish = function(params, fileListedCallback, publishedCallback, errorCallback) { + // Publishes a file. + // The optional fileListedCallback is called when the file becomes available in + // lbry.getFilesInfo() during the publish process. + // Use ES6 named arguments instead of directly passing param dict? - lbry.call('publish', params, callback, (errorInfo) => { + lbry.call('publish', params, publishedCallback, (errorInfo) => { errorCallback({ name: fault.fault, message: fault.faultString, }); }); + if (fileListedCallback) { + lbry.getFileInfoWhenListed(params.name, function(fileInfo) { + fileListedCallback(fileInfo); + }); + } } lbry.getVersionInfo = function(callback) { From 09cd853bf2eeeba12c0af645348b8bcc57f2a2ec Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 16 Sep 2016 11:23:39 -0400 Subject: [PATCH 02/10] Make Publish page send user to My Files as soon as file is listed there --- js/page/publish.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/page/publish.js b/js/page/publish.js index 857fc1bb9..acb4f585b 100644 --- a/js/page/publish.js +++ b/js/page/publish.js @@ -86,11 +86,11 @@ var PublishPage = React.createClass({ console.log(publishArgs); lbry.publish(publishArgs, (message) => { - this.handlePublishSuccess(); + this.handlePublishStarted(); this.setState({ submitting: false, }); - }, (error) => { + }, null, (error) => { this.handlePublishError(error); this.setState({ submitting: false, @@ -131,7 +131,7 @@ var PublishPage = React.createClass({ submitting: false, }; }, - handlePublishSuccess: function() { + handlePublishStarted: function() { alert(`Your file ${this.refs.meta_title.getValue()} has been published to LBRY at the address lbry://${this.state.name}!\n\n` + `You will now be taken to your My Files page, where your newly published file will be listed. Your file will take a few minutes to appear for other LBRY users; until then it will be listed as "pending."`); window.location = "?files"; From 9315b617c191269cc8cac1b2191110167165b383 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 16 Sep 2016 12:46:15 -0400 Subject: [PATCH 03/10] Track file Reflector availability in MyFiles state --- js/page/my_files.js | 51 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/js/page/my_files.js b/js/page/my_files.js index 45798766e..66f7dd20c 100644 --- a/js/page/my_files.js +++ b/js/page/my_files.js @@ -110,6 +110,7 @@ var MyFilesRow = React.createClass({ {this.props.completed ? 'Download complete' : (parseInt(this.props.ratioLoaded * 100) + '%')}
{ pauseLink }
{ watchButton }
+ {this.props.available ? null :

This file is now uploading to Reflector. This service hosts a copy of the file on LBRY's servers so that it's available even if no one with the file is online.

} ) } @@ -131,10 +132,13 @@ var MyFilesRow = React.createClass({ }); var MyFilesPage = React.createClass({ - fileTimeout: null, + _fileTimeout: null, + _fileInfoCheckNum: 0, + getInitialState: function() { return { filesInfo: null, + filesAvailable: {}, }; }, componentDidMount: function() { @@ -144,17 +148,51 @@ var MyFilesPage = React.createClass({ this.updateFilesInfo(); }, componentWillUnmount: function() { - if (this.fileTimeout) + if (this._fileTimeout) { - clearTimeout(this.fileTimeout); + clearTimeout(this._fileTimeout); } }, updateFilesInfo: function() { lbry.getFilesInfo((filesInfo) => { + if (!filesInfo) { + filesInfo = []; + } + + if (!(this._fileInfoCheckNum % 5)) { + // Time to update file availability status + + for (let fileInfo of filesInfo) { + let name = fileInfo.lbry_uri; + + lbry.search(name, (results) => { + var result = results[0]; + + if (result.name != name) { + // File not listed in Lighthouse + var available = false; + } else { + var available = result.available; + } + + if (typeof this.state.filesAvailable[name] === 'undefined' || available != this.state.filesAvailable[name]) { + var newFilesAvailable = Object.assign({}, this.state.filesAvailable); + newFilesAvailable[name] = available; + this.setState({ + filesAvailable: newFilesAvailable, + }); + } + }); + } + } + + this._fileInfoCheckNum += 1; + this.setState({ - filesInfo: (filesInfo ? filesInfo : []), + filesInfo: filesInfo, }); - this.fileTimeout = setTimeout(() => { this.updateFilesInfo() }, 1000); + + this._fileTimeout = setTimeout(() => { this.updateFilesInfo() }, 1000); }); }, render: function() { @@ -201,7 +239,8 @@ var MyFilesPage = React.createClass({ content.push(); + showWatchButton={showWatchButton} pending={pending} + available={this.state.filesAvailable[lbry_uri]} />); } } return ( From b3218f13c907331b186de99e49b8930bc3d07120 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 16 Sep 2016 12:56:20 -0400 Subject: [PATCH 04/10] Show message on My Files page for files uploading to Reflector --- js/page/my_files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/page/my_files.js b/js/page/my_files.js index 66f7dd20c..895806e15 100644 --- a/js/page/my_files.js +++ b/js/page/my_files.js @@ -110,7 +110,7 @@ var MyFilesRow = React.createClass({ {this.props.completed ? 'Download complete' : (parseInt(this.props.ratioLoaded * 100) + '%')}
{ pauseLink }
{ watchButton }
- {this.props.available ? null :

This file is now uploading to Reflector. This service hosts a copy of the file on LBRY's servers so that it's available even if no one with the file is online.

} + {this.props.available ? null :

This file is uploading to Reflector. Reflector is a service that hosts a copy of the file on LBRY's servers so that it's available even if no one with the file is online.

} ) } From e1637d537ca6cc0f864eb51ff092e798cc22819b Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 16 Sep 2016 13:45:33 -0400 Subject: [PATCH 05/10] Add lbry.getMyClaim() --- js/lbry.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/js/lbry.js b/js/lbry.js index 78291e868..7476b38e2 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -138,6 +138,10 @@ lbry.getClaimInfo = function(name, callback) { lbry.call('get_claim_info', { name: name }, callback); } +lbry.getMyClaim = function(name, callback) { + lbry.call('get_my_claim', { name: name }, callback); +} + lbry.getCostEstimate = function(name, callback) { lbry.call('get_est_cost', { name: name }, callback); } From 4072c1cddace3dcf8079dce202a1d832b260ad64 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 23 Sep 2016 05:19:39 -0400 Subject: [PATCH 06/10] Add Downloaded and Published tabs to My Files page --- js/app.js | 12 ++++++++++-- js/component/drawer.js | 2 +- js/page/publish.js | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/js/app.js b/js/app.js index c2fc77148..964b71b78 100644 --- a/js/app.js +++ b/js/app.js @@ -87,6 +87,12 @@ var App = React.createClass({ '?receive' : 'Receive', '?claim' : 'Claim Beta Code' }; + case 'downloaded': + case 'published': + return { + '?downloaded': 'Downloaded', + '?published': 'Published', + }; default: return null; } @@ -103,8 +109,10 @@ var App = React.createClass({ return ; case 'report': return ; - case 'files': - return ; + case 'downloaded': + return ; + case 'published': + return ; case 'start': return ; case 'claim': diff --git a/js/component/drawer.js b/js/component/drawer.js index 509c95b09..a821c274f 100644 --- a/js/component/drawer.js +++ b/js/component/drawer.js @@ -32,7 +32,7 @@ var Drawer = React.createClass({ - + diff --git a/js/page/publish.js b/js/page/publish.js index acb4f585b..d334b006e 100644 --- a/js/page/publish.js +++ b/js/page/publish.js @@ -134,7 +134,7 @@ var PublishPage = React.createClass({ handlePublishStarted: function() { alert(`Your file ${this.refs.meta_title.getValue()} has been published to LBRY at the address lbry://${this.state.name}!\n\n` + `You will now be taken to your My Files page, where your newly published file will be listed. Your file will take a few minutes to appear for other LBRY users; until then it will be listed as "pending."`); - window.location = "?files"; + window.location = "?published"; }, handlePublishError: function(error) { alert(`The following error occurred when attempting to publish your file:\n\n` + From 8bc13fb8a573365d5aa1dfb52e1db885a6173e32 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Fri, 23 Sep 2016 05:56:01 -0400 Subject: [PATCH 07/10] Filter My Files results based on tab chosen --- js/page/my_files.js | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/js/page/my_files.js b/js/page/my_files.js index 895806e15..2c896cd61 100644 --- a/js/page/my_files.js +++ b/js/page/my_files.js @@ -134,6 +134,8 @@ var MyFilesRow = React.createClass({ var MyFilesPage = React.createClass({ _fileTimeout: null, _fileInfoCheckNum: 0, + _filesOwnership: {}, + _filesOwnershipLoaded: false, getInitialState: function() { return { @@ -141,10 +143,16 @@ var MyFilesPage = React.createClass({ filesAvailable: {}, }; }, + getDefaultProps: function() { + return { + show: null, + }; + }, componentDidMount: function() { document.title = "My Files"; }, componentWillMount: function() { + this.getFilesOwnership(); this.updateFilesInfo(); }, componentWillUnmount: function() { @@ -153,6 +161,27 @@ var MyFilesPage = React.createClass({ clearTimeout(this._fileTimeout); } }, + getFilesOwnership: function() { + lbry.getFilesInfo((filesInfo) => { + var ownershipLoadedCount = 0; + for (let i = 0; i < filesInfo.length; i++) { + let fileInfo = filesInfo[i]; + lbry.call('get_my_claim', {name: fileInfo.lbry_uri}, (claim) => { + this._filesOwnership[fileInfo.lbry_uri] = false; + ownershipLoadedCount++; + if (ownershipLoadedCount >= filesInfo.length) { + this._filesOwnershipLoaded = true; + } + }, (err) => { + this._filesOwnership[fileInfo.lbry_uri] = true; + ownershipLoadedCount++; + if (ownershipLoadedCount >= filesInfo.length) { + this._filesOwnershipLoaded = true; + } + }); + } + }); + }, updateFilesInfo: function() { lbry.getFilesInfo((filesInfo) => { if (!filesInfo) { @@ -196,7 +225,7 @@ var MyFilesPage = React.createClass({ }); }, render: function() { - if (this.state.filesInfo === null) { + if (this.state.filesInfo === null || !this._filesOwnershipLoaded) { return (
@@ -214,7 +243,8 @@ var MyFilesPage = React.createClass({ let {completed, written_bytes, total_bytes, lbry_uri, file_name, download_path, stopped, metadata} = fileInfo; - if (!metadata || seenUris[lbry_uri]) + if (!metadata || seenUris[lbry_uri] || (this.props.show == 'downloaded' && this._filesOwnership[lbry_uri]) || + (this.props.show == 'published' && !this._filesOwnership[lbry_uri])) { continue; } From e5e27444a5c10a63882245ffd6ce4e9f85acd921 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Sat, 24 Sep 2016 02:41:53 -0400 Subject: [PATCH 08/10] On My Files page, simplify check for file availability --- js/page/my_files.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/js/page/my_files.js b/js/page/my_files.js index 2c896cd61..b0b54545a 100644 --- a/js/page/my_files.js +++ b/js/page/my_files.js @@ -197,12 +197,7 @@ var MyFilesPage = React.createClass({ lbry.search(name, (results) => { var result = results[0]; - if (result.name != name) { - // File not listed in Lighthouse - var available = false; - } else { - var available = result.available; - } + var available = result.name == name && result.available; if (typeof this.state.filesAvailable[name] === 'undefined' || available != this.state.filesAvailable[name]) { var newFilesAvailable = Object.assign({}, this.state.filesAvailable); From 9e3dc5b5ce970e6a74d0c47f410f99c50163e043 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Sat, 24 Sep 2016 02:50:13 -0400 Subject: [PATCH 09/10] Convert MyFilesPage._filesOwnershipLoaded to state var --- js/page/my_files.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/js/page/my_files.js b/js/page/my_files.js index b0b54545a..bbf9dd7ea 100644 --- a/js/page/my_files.js +++ b/js/page/my_files.js @@ -135,11 +135,11 @@ var MyFilesPage = React.createClass({ _fileTimeout: null, _fileInfoCheckNum: 0, _filesOwnership: {}, - _filesOwnershipLoaded: false, getInitialState: function() { return { filesInfo: null, + filesOwnershipLoaded: false, filesAvailable: {}, }; }, @@ -170,13 +170,17 @@ var MyFilesPage = React.createClass({ this._filesOwnership[fileInfo.lbry_uri] = false; ownershipLoadedCount++; if (ownershipLoadedCount >= filesInfo.length) { - this._filesOwnershipLoaded = true; + this.setState({ + filesOwnershipLoaded: true, + }); } }, (err) => { this._filesOwnership[fileInfo.lbry_uri] = true; ownershipLoadedCount++; if (ownershipLoadedCount >= filesInfo.length) { - this._filesOwnershipLoaded = true; + this.setState({ + filesOwnershipLoaded: true, + }); } }); } @@ -220,7 +224,7 @@ var MyFilesPage = React.createClass({ }); }, render: function() { - if (this.state.filesInfo === null || !this._filesOwnershipLoaded) { + if (this.state.filesInfo === null || !this.state.filesOwnershipLoaded) { return (
From 89f87bb604aaa61b0ba8f009cc7e70959f9390dc Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Sat, 24 Sep 2016 02:59:46 -0400 Subject: [PATCH 10/10] Remove workaround for old get_my_claim() behavior --- js/page/my_files.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/js/page/my_files.js b/js/page/my_files.js index bbf9dd7ea..57a3fb209 100644 --- a/js/page/my_files.js +++ b/js/page/my_files.js @@ -166,16 +166,8 @@ var MyFilesPage = React.createClass({ var ownershipLoadedCount = 0; for (let i = 0; i < filesInfo.length; i++) { let fileInfo = filesInfo[i]; - lbry.call('get_my_claim', {name: fileInfo.lbry_uri}, (claim) => { - this._filesOwnership[fileInfo.lbry_uri] = false; - ownershipLoadedCount++; - if (ownershipLoadedCount >= filesInfo.length) { - this.setState({ - filesOwnershipLoaded: true, - }); - } - }, (err) => { - this._filesOwnership[fileInfo.lbry_uri] = true; + lbry.getMyClaim(fileInfo.lbry_uri, (claim) => { + this._filesOwnership[fileInfo.lbry_uri] = !!claim; ownershipLoadedCount++; if (ownershipLoadedCount >= filesInfo.length) { this.setState({