Use local file path for publishing instead of uploading

This commit is contained in:
jobevers 2017-02-08 13:11:58 -06:00
parent 3394f964dd
commit 06aba33300
2 changed files with 6 additions and 85 deletions

View file

@ -56,6 +56,9 @@ var FormField = React.createClass({
getValue: function() { getValue: function() {
if (this.props.type == 'checkbox') { if (this.props.type == 'checkbox') {
return this.refs.field.checked; return this.refs.field.checked;
}
else if (this.props.type == 'file') {
return this.refs.field.files[0].path;
} else { } else {
return this.refs.field.value; return this.refs.field.value;
} }

View file

@ -45,14 +45,7 @@ var PublishPage = React.createClass({
} }
} }
let fileProcessing = false; if (missingFieldFound) {
if (this.state.fileInfo && !this.state.tempFileReady) {
this.refs.file.showAdvice('Your file is still processing.');
this.refs.file.focus();
fileProcessing = true;
}
if (missingFieldFound || fileProcessing) {
this.setState({ this.setState({
submitting: false, submitting: false,
}); });
@ -89,7 +82,7 @@ var PublishPage = React.createClass({
}; };
if (this.refs.file.getValue() !== '') { if (this.refs.file.getValue() !== '') {
publishArgs.file_path = this._tempFilePath; publishArgs.file_path = this.refs.file.getValue();
} }
lbry.publish(publishArgs, (message) => { lbry.publish(publishArgs, (message) => {
@ -114,8 +107,6 @@ var PublishPage = React.createClass({
} }
}, },
getInitialState: function() { getInitialState: function() {
this._tempFilePath = null;
return { return {
rawName: '', rawName: '',
name: '', name: '',
@ -127,14 +118,12 @@ var PublishPage = React.createClass({
myClaimValue: 0.0, myClaimValue: 0.0,
myClaimMetadata: null, myClaimMetadata: null,
myClaimExists: null, myClaimExists: null,
fileInfo: null,
copyrightNotice: '', copyrightNotice: '',
otherLicenseDescription: '', otherLicenseDescription: '',
otherLicenseUrl: '', otherLicenseUrl: '',
uploadProgress: 0.0, uploadProgress: 0.0,
uploaded: false, uploaded: false,
errorMessage: null, errorMessage: null,
tempFileReady: false,
submitting: false, submitting: false,
modal: null, modal: null,
}; };
@ -236,56 +225,6 @@ var PublishPage = React.createClass({
feeCurrency: event.target.value, feeCurrency: event.target.value,
}); });
}, },
handleFileChange: function(event) {
event.preventDefault();
var fileInput = event.target;
this._tempFilePath = null;
if (fileInput.files.length == 0) {
// File was removed
this.setState({
fileInfo: null,
uploadProgress: 0.0,
uploaded: false,
tempFileReady: false,
});
} else {
var file = fileInput.files[0];
this.setState({
fileInfo: {
name: file.name,
size: file.size,
},
uploadProgress: 0.0,
uploaded: false,
tempFileReady: false,
});
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', (event) => {
this.setState({
uploadProgress: (event.loaded / event.total),
});
});
xhr.upload.addEventListener('load', (event) => {
this.setState({
uploaded: true,
});
});
xhr.addEventListener('load', (event) => {
this._tempFilePath = JSON.parse(xhr.responseText);
this.setState({
tempFileReady: true,
});
})
var formData = new FormData(fileInput.form);
formData.append('file', fileInput.files[0]);
xhr.open('POST', lbry.webUiUri + '/upload', true);
xhr.send(formData);
}
},
handleFeePrefChange: function(feeEnabled) { handleFeePrefChange: function(feeEnabled) {
this.setState({ this.setState({
isFee: feeEnabled isFee: feeEnabled
@ -333,21 +272,6 @@ var PublishPage = React.createClass({
document.title = "Publish"; document.title = "Publish";
}, },
componentDidUpdate: function() { componentDidUpdate: function() {
if (this.state.fileInfo && !this.state.tempFileReady) {
// A file was chosen but the daemon hasn't finished processing it yet, i.e. it's loading, so
// we're displaying a progress bar and need a value for it.
// React can't unset the "value" prop (to show an "indeterminate" bar) after it's already
// been set, so we have to manage it manually.
if (!this.state.uploaded) {
// Still uploading
this.refs.progress.setAttribute('value', this.state.uploadProgress);
} else {
// Fully uploaded and waiting for server to finish processing, so set progress bar to "indeterminite"
this.refs.progress.removeAttribute('value');
}
}
}, },
// Also getting a type warning here too // Also getting a type warning here too
render: function() { render: function() {
@ -370,13 +294,7 @@ var PublishPage = React.createClass({
<section className="card"> <section className="card">
<h4>Choose File</h4> <h4>Choose File</h4>
<FormField name="file" ref="file" type="file" onChange={this.handleFileChange} /> <FormField name="file" ref="file" type="file" />
{ !this.state.fileInfo ? '' :
(!this.state.tempFileReady ? <div>
<progress ref='progress'></progress>
{!this.state.uploaded ? <span> Importing file into LBRY...</span> : <span> Processing file...</span>}
</div>
: <div>File ready for publishing!</div>) }
{ this.state.myClaimExists ? <div className="help">If you don't choose a file, the file from your existing claim will be used.</div> : null } { this.state.myClaimExists ? <div className="help">If you don't choose a file, the file from your existing claim will be used.</div> : null }
</section> </section>