Allow only images in modal image uploader. #7672

Merged
6 changed files with 305 additions and 323 deletions
Showing only changes of commit d65d36fc30 - Show all commits

View file

@ -11,7 +11,7 @@ import Icon from 'component/common/icon';
type Props = { type Props = {
modal: { id: string, modalProps: {} }, modal: { id: string, modalProps: {} },
filePath: string | File, filePath: File,
clearPublish: () => void, clearPublish: () => void,
updatePublishForm: ({}) => void, updatePublishForm: ({}) => void,
openModal: (id: string, { files: Array<File> }) => void, openModal: (id: string, { files: Array<File> }) => void,

View file

@ -6,7 +6,7 @@ type Props = {
uri: ?string, uri: ?string,
label: ?string, label: ?string,
disabled: ?boolean, disabled: ?boolean,
filePath: string | File, filePath: File,
fileText: ?string, fileText: ?string,
fileMimeType: ?string, fileMimeType: ?string,
streamingUrl: ?string, streamingUrl: ?string,

View file

@ -19,7 +19,7 @@ type Props = {
mode: ?string, mode: ?string,
name: ?string, name: ?string,
title: ?string, title: ?string,
filePath: string | File, filePath: ?File,
fileMimeType: ?string, fileMimeType: ?string,
isStillEditing: boolean, isStillEditing: boolean,
balance: number, balance: number,
@ -86,16 +86,16 @@ function PublishFile(props: Props) {
useEffect(() => { useEffect(() => {
if (mode === PUBLISH_MODES.POST) { if (mode === PUBLISH_MODES.POST) {
if (currentFileType !== 'text/markdown' && !isStillEditing) { if (currentFileType !== 'text/markdown' && !isStillEditing) {
updatePublishForm({ filePath: '' }); updatePublishForm({ filePath: undefined });
} }
} }
}, [currentFileType, mode, isStillEditing, updatePublishForm]); }, [currentFileType, mode, isStillEditing, updatePublishForm]);
useEffect(() => { useEffect(() => {
if (!filePath || filePath === '') { if (!filePath) {
setCurrentFile(''); setCurrentFile('');
updateFileInfo(0, 0, false); updateFileInfo(0, 0, false);
} else if (typeof filePath !== 'string') { } else {
// Update currentFile file // Update currentFile file
if (filePath.name !== currentFile) { if (filePath.name !== currentFile) {
handleFileChange({ file: filePath, path: filePath.name }); handleFileChange({ file: filePath, path: filePath.name });
@ -215,9 +215,9 @@ function PublishFile(props: Props) {
// select file, start to select a new one, then cancel // select file, start to select a new one, then cancel
if (!fileWithPath) { if (!fileWithPath) {
if (isStillEditing || !clearName) { if (isStillEditing || !clearName) {
updatePublishForm({ filePath: '' }); updatePublishForm({ filePath: undefined });
} else { } else {
updatePublishForm({ filePath: '', name: '' }); updatePublishForm({ filePath: undefined, name: '' });
} }
return; return;
} }
@ -271,10 +271,8 @@ function PublishFile(props: Props) {
setPublishMode(PUBLISH_MODES.FILE); setPublishMode(PUBLISH_MODES.FILE);
} }
const publishFormParams: { filePath: string | File, name?: string, optimize?: boolean } = { const publishFormParams: { filePath: File, name?: string, optimize?: boolean } = {
// if electron, we'll set filePath to the path string because SDK is handling publishing. filePath: file,
// File.path will be undefined from web due to browser security, so it will default to the File Object.
filePath: fileWithPath.path || file,
}; };
// Strip off extention and replace invalid characters // Strip off extention and replace invalid characters
let fileName = name || (file.name && file.name.substring(0, file.name.lastIndexOf('.'))) || ''; let fileName = name || (file.name && file.name.substring(0, file.name.lastIndexOf('.'))) || '';

View file

@ -35,8 +35,8 @@ import tempy from 'tempy';
type Props = { type Props = {
disabled: boolean, disabled: boolean,
tags: Array<Tag>, tags: Array<Tag>,
publish: (source?: string | File, ?boolean) => void, publish: (source: ?File, ?boolean) => void,
filePath: string | File, filePath: ?File,
fileText: string, fileText: string,
bid: ?number, bid: ?number,
bidError: ?string, bidError: ?string,
@ -373,9 +373,6 @@ function PublishForm(props: Props) {
if (!output || output === '') { if (!output || output === '') {
// Generate a temporary file: // Generate a temporary file:
output = tempy.file({ name: 'post.md' }); output = tempy.file({ name: 'post.md' });
} else if (typeof filePath === 'string') {
// Use current file
output = filePath;
} }
// Create a temporary file and save file changes // Create a temporary file and save file changes
if (output && output !== '') { if (output && output !== '') {
@ -447,7 +444,7 @@ function PublishForm(props: Props) {
// with other properties such as name, title, etc.) for security reasons. // with other properties such as name, title, etc.) for security reasons.
useEffect(() => { useEffect(() => {
if (mode === PUBLISH_MODES.FILE) { if (mode === PUBLISH_MODES.FILE) {
updatePublishForm({ filePath: '', fileDur: 0, fileSize: 0 }); updatePublishForm({ filePath: undefined, fileDur: 0, fileSize: 0 });
} }
}, [mode, updatePublishForm]); }, [mode, updatePublishForm]);

View file

@ -15,7 +15,7 @@ import Icon from 'component/common/icon';
import { NO_FILE } from 'redux/actions/publish'; import { NO_FILE } from 'redux/actions/publish';
type Props = { type Props = {
filePath: string | File, filePath: ?File,
isMarkdownPost: boolean, isMarkdownPost: boolean,
optimize: boolean, optimize: boolean,
title: ?string, title: ?string,
@ -104,17 +104,12 @@ const ModalPublishPreview = (props: Props) => {
// @endif // @endif
} }
function getFilePathName(filePath: string | File) { function getFilePathName(filePath: ?File) {
if (!filePath) { if (!filePath) {
return NO_FILE; return NO_FILE;
} }
if (typeof filePath === 'string') {
return filePath;
} else {
return filePath.name; return filePath.name;
} }
}
function createRow(label: string, value: any) { function createRow(label: string, value: any) {
return ( return (
@ -127,7 +122,7 @@ const ModalPublishPreview = (props: Props) => {
const txFee = previewResponse ? previewResponse['total_fee'] : null; const txFee = previewResponse ? previewResponse['total_fee'] : null;
// $FlowFixMe add outputs[0] etc to PublishResponse type // $FlowFixMe add outputs[0] etc to PublishResponse type
const isOptimizeAvail = filePath && filePath !== '' && isVid && ffmpegStatus.available; const isOptimizeAvail = filePath && isVid && ffmpegStatus.available;
let modalTitle; let modalTitle;
if (isStillEditing) { if (isStillEditing) {
modalTitle = __('Confirm Edit'); modalTitle = __('Confirm Edit');

View file

@ -18,7 +18,7 @@ import Lbry from 'lbry';
import { isClaimNsfw } from 'util/claim'; import { isClaimNsfw } from 'util/claim';
export const NO_FILE = '---'; export const NO_FILE = '---';
export const doPublishDesktop = (filePath: string, preview?: boolean) => (dispatch: Dispatch, getState: () => {}) => { export const doPublishDesktop = (filePath: ?File, preview?: boolean) => (dispatch: Dispatch, getState: () => {}) => {
const publishPreview = (previewResponse) => { const publishPreview = (previewResponse) => {
dispatch( dispatch(
doOpenModal(MODALS.PUBLISH_PREVIEW, { doOpenModal(MODALS.PUBLISH_PREVIEW, {
@ -138,14 +138,9 @@ export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) =>
data: { ...publishFormValue }, data: { ...publishFormValue },
}); });
export const doUploadThumbnail = ( export const doUploadThumbnail =
filePath?: string, (filePath?: string, thumbnailBlob?: File, fsAdapter?: any, fs?: any, path?: any, cb?: (string) => void) =>
thumbnailBlob?: File, (dispatch: Dispatch) => {
fsAdapter?: any,
fs?: any,
path?: any,
cb?: (string) => void
) => (dispatch: Dispatch) => {
const downMessage = __('Thumbnail upload service may be down, try again later.'); const downMessage = __('Thumbnail upload service may be down, try again later.');
let thumbnail, fileExt, fileName, fileType; let thumbnail, fileExt, fileName, fileType;
@ -251,11 +246,10 @@ export const doUploadThumbnail = (
data.append('file', file); data.append('file', file);
return doUpload(data); return doUpload(data);
} }
}; };
export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileListItem, fs: any) => ( export const doPrepareEdit =
dispatch: Dispatch (claim: StreamClaim, uri: string, fileInfo: FileListItem, fs: any) => (dispatch: Dispatch) => {
) => {
const { name, amount, value = {} } = claim; const { name, amount, value = {} } = claim;
const channelName = (claim && claim.signing_channel && claim.signing_channel.name) || null; const channelName = (claim && claim.signing_channel && claim.signing_channel.name) || null;
const { const {
@ -315,12 +309,10 @@ export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileLis
} }
dispatch({ type: ACTIONS.DO_PREPARE_EDIT, data: publishData }); dispatch({ type: ACTIONS.DO_PREPARE_EDIT, data: publishData });
}; };
export const doPublish = (success: Function, fail: Function, preview: Function) => ( export const doPublish =
dispatch: Dispatch, (success: Function, fail: Function, preview: Function) => (dispatch: Dispatch, getState: () => {}) => {
getState: () => {}
) => {
if (!preview) { if (!preview) {
dispatch({ type: ACTIONS.PUBLISH_START }); dispatch({ type: ACTIONS.PUBLISH_START });
} }
@ -466,7 +458,7 @@ export const doPublish = (success: Function, fail: Function, preview: Function)
return Lbry.publish(publishPayload).then((response: PublishResponse) => { return Lbry.publish(publishPayload).then((response: PublishResponse) => {
return success(response); return success(response);
}, fail); }, fail);
}; };
// Calls file_list until any reflecting files are done // Calls file_list until any reflecting files are done
export const doCheckReflectingFiles = () => (dispatch: Dispatch, getState: GetState) => { export const doCheckReflectingFiles = () => (dispatch: Dispatch, getState: GetState) => {