fix file upload limit error

This commit is contained in:
Sean Yesmunt 2019-12-09 13:51:00 -05:00
parent 21b712f786
commit ef27683726
3 changed files with 17 additions and 16 deletions
ui/component

View file

@ -51,9 +51,9 @@ class FileSelector extends React.PureComponent<Props> {
render() { render() {
const { type, currentPath, label, fileLabel, directoryLabel, placeholder, accept, error, disabled } = this.props; const { type, currentPath, label, fileLabel, directoryLabel, placeholder, accept, error, disabled } = this.props;
const buttonLabel = type === 'file' ? fileLabel || __('Choose File') : directoryLabel || __('Choose Directory'); const buttonLabel = type === 'file' ? fileLabel || __('Choose File') : directoryLabel || __('Choose Directory');
const placeHolder = currentPath || placeholder; const placeHolder = currentPath || placeholder;
return ( return (
<React.Fragment> <React.Fragment>
<FormField <FormField

View file

@ -1,6 +1,11 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import {
import { selectBalance, selectIsStillEditing, makeSelectPublishFormValue, doUpdatePublishForm } from 'lbry-redux'; selectBalance,
selectIsStillEditing,
makeSelectPublishFormValue,
doUpdatePublishForm,
doToast,
} from 'lbry-redux';
import PublishPage from './view'; import PublishPage from './view';
const select = state => ({ const select = state => ({
@ -13,6 +18,7 @@ const select = state => ({
const perform = dispatch => ({ const perform = dispatch => ({
updatePublishForm: value => dispatch(doUpdatePublishForm(value)), updatePublishForm: value => dispatch(doUpdatePublishForm(value)),
showToast: message => dispatch(doToast({ message, isError: true })),
}); });
export default connect( export default connect(

View file

@ -1,6 +1,6 @@
// @flow // @flow
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import React, { useState } from 'react'; import React from 'react';
import { regexInvalidURI } from 'lbry-redux'; import { regexInvalidURI } from 'lbry-redux';
import FileSelector from 'component/common/file-selector'; import FileSelector from 'component/common/file-selector';
import Button from 'component/button'; import Button from 'component/button';
@ -15,14 +15,12 @@ type Props = {
updatePublishForm: ({}) => void, updatePublishForm: ({}) => void,
disabled: boolean, disabled: boolean,
publishing: boolean, publishing: boolean,
showToast: string => void,
}; };
function PublishFile(props: Props) { function PublishFile(props: Props) {
const { name, balance, filePath, isStillEditing, updatePublishForm, disabled, publishing } = props; const { name, balance, filePath, isStillEditing, updatePublishForm, disabled, publishing } = props;
// This is basically for displaying the 500mb limit
const [fileError, setFileError] = useState('');
let currentFile = ''; let currentFile = '';
if (filePath) { if (filePath) {
if (typeof filePath === 'string') { if (typeof filePath === 'string') {
@ -33,6 +31,8 @@ function PublishFile(props: Props) {
} }
function handleFileChange(file: WebFile) { function handleFileChange(file: WebFile) {
const { showToast } = props;
// if electron, we'll set filePath to the path string because SDK is handling publishing. // if electron, we'll set filePath to the path string because SDK is handling publishing.
// if web, we set the filePath (dumb name) to the File() object // if web, we set the filePath (dumb name) to the File() object
// File.path will be undefined from web due to browser security, so it will default to the File Object. // File.path will be undefined from web due to browser security, so it will default to the File Object.
@ -42,14 +42,13 @@ function PublishFile(props: Props) {
const PUBLISH_SIZE_LIMIT: number = 512000000; const PUBLISH_SIZE_LIMIT: number = 512000000;
if (typeof file !== 'string') { if (typeof file !== 'string') {
if (file && file.size && Number(file.size) > PUBLISH_SIZE_LIMIT) { if (file && file.size && Number(file.size) > PUBLISH_SIZE_LIMIT) {
setFileError('File uploads currently limited to 500MB. Download the app for unlimited publishing.'); showToast(__('File uploads currently limited to 500MB. Download the app for unlimited publishing.'));
updatePublishForm({ filePath: '', name: '' }); updatePublishForm({ filePath: '', name: '' });
return; return;
} else {
setFileError('');
} }
} }
// @endif // @endif
const publishFormParams: { filePath: string | WebFile, name?: string } = { const publishFormParams: { filePath: string | WebFile, name?: string } = {
filePath: file.path || file, filePath: file.path || file,
}; };
@ -72,6 +71,7 @@ function PublishFile(props: Props) {
} else { } else {
title = isStillEditing ? __('Edit') : __('Publish'); title = isStillEditing ? __('Edit') : __('Publish');
} }
return ( return (
<Card <Card
actionIconPadding={false} actionIconPadding={false}
@ -83,12 +83,7 @@ function PublishFile(props: Props) {
} }
actions={ actions={
<React.Fragment> <React.Fragment>
<FileSelector <FileSelector disabled={disabled} currentPath={currentFile} onFileChosen={handleFileChange} />
disabled={disabled}
currentPath={currentFile}
onFileChosen={handleFileChange}
error={fileError}
/>
{!isStillEditing && ( {!isStillEditing && (
<p className="help"> <p className="help">
{__('For video content, use MP4s in H264/AAC format for best compatibility.')}{' '} {__('For video content, use MP4s in H264/AAC format for best compatibility.')}{' '}