From 24214bf660e291f33c1376c52c2396cb832e03f7 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Mon, 2 Apr 2018 09:30:48 -0400 Subject: [PATCH 01/24] add upload status constants --- src/renderer/constants/thumbnail_upload_statuses.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/renderer/constants/thumbnail_upload_statuses.js diff --git a/src/renderer/constants/thumbnail_upload_statuses.js b/src/renderer/constants/thumbnail_upload_statuses.js new file mode 100644 index 000000000..b09845d07 --- /dev/null +++ b/src/renderer/constants/thumbnail_upload_statuses.js @@ -0,0 +1,5 @@ +export const API_DOWN = 'apiDown'; +export const READY = 'ready'; +export const IN_PROGRESS = 'inProgress'; +export const COMPLETE = 'complete'; +export const MANUAL = 'manual'; -- 2.45.3 From e32a597c389d7462d81c4749a8d79d275d0aacfe Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Mon, 2 Apr 2018 09:35:52 -0400 Subject: [PATCH 02/24] add uploadStatus to PublishForm --- src/renderer/component/publishForm/view.jsx | 3 +++ src/renderer/redux/reducers/publish.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/renderer/component/publishForm/view.jsx b/src/renderer/component/publishForm/view.jsx index 0b4b5bfb2..bbe322e96 100644 --- a/src/renderer/component/publishForm/view.jsx +++ b/src/renderer/component/publishForm/view.jsx @@ -21,6 +21,7 @@ type Props = { editingURI: ?string, title: ?string, thumbnail: ?string, + uploadStatus: ?string, description: ?string, language: string, nsfw: boolean, @@ -267,6 +268,7 @@ class PublishForm extends React.PureComponent { editingURI, title, thumbnail, + uploadStatus, description, language, nsfw, @@ -360,6 +362,7 @@ class PublishForm extends React.PureComponent { disabled={formDisabled} onChange={e => updatePublishForm({ thumbnail: e.target.value })} /> +

status: {uploadStatus}

Date: Mon, 2 Apr 2018 09:38:06 -0400 Subject: [PATCH 03/24] add doResetThumbnailStatus and doUploadThumbnail actions --- src/renderer/redux/actions/publish.js | 84 ++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/src/renderer/redux/actions/publish.js b/src/renderer/redux/actions/publish.js index 5163af6fc..37c364e5d 100644 --- a/src/renderer/redux/actions/publish.js +++ b/src/renderer/redux/actions/publish.js @@ -6,6 +6,7 @@ import { doNotify, MODALS, selectMyChannelClaims, + STATUSES } from 'lbry-redux'; import { selectPendingPublishes } from 'redux/selectors/publish'; import type { @@ -13,6 +14,8 @@ import type { UpdatePublishFormAction, PublishParams, } from 'redux/reducers/publish'; +import fs from 'fs'; +import path from 'path'; type Action = UpdatePublishFormAction | { type: ACTIONS.CLEAR_PUBLISH }; type PromiseAction = Promise; @@ -30,15 +33,78 @@ export const doUpdatePublishForm = (publishFormValue: UpdatePublishFormData) => data: { ...publishFormValue }, }); -export const doPrepareEdit = (claim: any, uri: string) => (dispatch: Dispatch) => { - const { - name, - amount, - channel_name: channelName, - value: { - stream: { metadata }, - }, - } = claim; +export const doResetThumbnailStatus = () => (dispatch: Dispatch): Action => + fetch('https://spee.ch/api/channel/availability/@testing') + .then(() => + dispatch({ + type: ACTIONS.UPDATE_PUBLISH_FORM, + data: { thumbnailStatus: STATUSES.READY }, + }) + ) + .catch(() => + dispatch({ + type: ACTIONS.UPDATE_PUBLISH_FORM, + data: { thumbnailStatus: STATUSES.DOWN }, + }) + ); + +export const doUploadThumbnail = (filePath: string, nsfw: boolean) => (dispatch: Dispatch) => { + const thumbnail = fs.readFileSync(filePath); + const fileExt = path.extname(filePath); + + const makeid = () => { + let text = ''; + const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + for (let i = 0; i < 24; i += 1) text += possible.charAt(Math.floor(Math.random() * 62)); + return text; + }; + + const uploadError = (error: string = '') => + dispatch( + batchActions( + { + type: ACTIONS.UPDATE_PUBLISH_FORM, + data: { thumbnailStatus: STATUSES.DOWN }, + }, + doAlertError(error) + ) + ); + + dispatch({ + type: ACTIONS.UPDATE_PUBLISH_FORM, + data: { thumbnailStatus: STATUSES.IN_PROGRESS }, + }); + + const data = new FormData(); + const name = makeid(); + const blob = new Blob([thumbnail], { type: `image/${fileExt.slice(1)}` }); + data.append('name', name); + data.append('file', blob); + data.append('nsfw', nsfw.toString()); + return fetch('https://spee.ch/api/claim/publish', { + method: 'POST', + body: data, + }) + .then(response => response.json()) + .then( + json => + json.success + ? dispatch({ + type: ACTIONS.UPDATE_PUBLISH_FORM, + data: { + thumbnailStatus: STATUSES.COMPLETE, + thumbnailUrl: `${json.data.url}${fileExt}`, + }, + }) + : uploadError() + ) + .catch(() => uploadError()); +}; + +export const doPrepareEdit = (claim: any) => (dispatch: Dispatch) => { + const { name, amount, channel_name: channelName, value: { stream: { metadata } } } = claim; + + const { author, description, -- 2.45.3 From 75b540635bd6d14695141fdf7f49f8127dc21b78 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Mon, 2 Apr 2018 09:53:29 -0400 Subject: [PATCH 04/24] rename uploadStatus -> uploadThumbnailStatus; call doResetThumbnailStatus on componentWillMount --- src/renderer/component/publishForm/view.jsx | 14 +++++++++----- src/renderer/page/publish/index.js | 4 +++- src/renderer/redux/actions/publish.js | 4 ++-- src/renderer/redux/reducers/publish.js | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/renderer/component/publishForm/view.jsx b/src/renderer/component/publishForm/view.jsx index bbe322e96..b15e70d59 100644 --- a/src/renderer/component/publishForm/view.jsx +++ b/src/renderer/component/publishForm/view.jsx @@ -21,7 +21,7 @@ type Props = { editingURI: ?string, title: ?string, thumbnail: ?string, - uploadStatus: ?string, + uploadThumbnailStatus: ?string, description: ?string, language: string, nsfw: boolean, @@ -50,7 +50,8 @@ type Props = { clearPublish: () => void, resolveUri: string => void, scrollToTop: () => void, - prepareEdit: ({}, string) => void, + prepareEdit: ({}) => void, + resetThumbnailStatus: () => void, }; class PublishForm extends React.PureComponent { @@ -68,7 +69,10 @@ class PublishForm extends React.PureComponent { (this: any).getNewUri = this.getNewUri.bind(this); } - // Returns a new uri to be used in the form and begins to resolve that uri for bid help text + componentWillMount() { + this.props.resetThumbnailStatus(); + } + getNewUri(name: string, channel: string) { const { resolveUri } = this.props; // If they are midway through a channel creation, treat it as anonymous until it completes @@ -268,7 +272,7 @@ class PublishForm extends React.PureComponent { editingURI, title, thumbnail, - uploadStatus, + uploadThumbnailStatus, description, language, nsfw, @@ -362,7 +366,7 @@ class PublishForm extends React.PureComponent { disabled={formDisabled} onChange={e => updatePublishForm({ thumbnail: e.target.value })} /> -

status: {uploadStatus}

+

status: {uploadThumbnailStatus}

({ resolveUri: uri => dispatch(doResolveUri(uri)), publish: params => dispatch(doPublish(params)), navigate: path => dispatch(doNavigate(path)), - prepareEdit: (claim, uri) => dispatch(doPrepareEdit(claim, uri)), + prepareEdit: claim => dispatch(doPrepareEdit(claim)), + resetThumbnail: () => dispatch(doResetThumbnailStatus()), }); export default connect(select, perform)(PublishPage); diff --git a/src/renderer/redux/actions/publish.js b/src/renderer/redux/actions/publish.js index 37c364e5d..b733717e8 100644 --- a/src/renderer/redux/actions/publish.js +++ b/src/renderer/redux/actions/publish.js @@ -38,13 +38,13 @@ export const doResetThumbnailStatus = () => (dispatch: Dispatch): Action => .then(() => dispatch({ type: ACTIONS.UPDATE_PUBLISH_FORM, - data: { thumbnailStatus: STATUSES.READY }, + data: { uploadThumbnailStatus: STATUSES.READY }, }) ) .catch(() => dispatch({ type: ACTIONS.UPDATE_PUBLISH_FORM, - data: { thumbnailStatus: STATUSES.DOWN }, + data: { uploadThumbnailStatus: STATUSES.API_DOWN }, }) ); diff --git a/src/renderer/redux/reducers/publish.js b/src/renderer/redux/reducers/publish.js index c185fdd8e..d6e7c7757 100644 --- a/src/renderer/redux/reducers/publish.js +++ b/src/renderer/redux/reducers/publish.js @@ -15,7 +15,7 @@ type PublishState = { }, title: string, thumbnail: string, - uploadStatus: string, + uploadThumbnailStatus: string, description: string, language: string, tosAccepted: boolean, @@ -40,7 +40,7 @@ export type UpdatePublishFormData = { }, title?: string, thumbnail?: string, - uploadStatus?: string, + uploadThumbnailStatus?: string, description?: string, language?: string, tosAccepted?: boolean, @@ -99,7 +99,7 @@ const defaultState: PublishState = { }, title: '', thumbnail: '', - uploadStatus: STATUSES.API_DOWN, + uploadThumbnailStatus: STATUSES.API_DOWN, description: '', language: 'en', nsfw: false, -- 2.45.3 From c7a91340dc0e84e1466b6c0743e243a305721c95 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Mon, 2 Apr 2018 09:55:36 -0400 Subject: [PATCH 05/24] fix key name --- src/renderer/page/publish/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/page/publish/index.js b/src/renderer/page/publish/index.js index 8b738bdd4..5d57b8a30 100644 --- a/src/renderer/page/publish/index.js +++ b/src/renderer/page/publish/index.js @@ -57,7 +57,7 @@ const perform = dispatch => ({ publish: params => dispatch(doPublish(params)), navigate: path => dispatch(doNavigate(path)), prepareEdit: claim => dispatch(doPrepareEdit(claim)), - resetThumbnail: () => dispatch(doResetThumbnailStatus()), + resetThumbnailStatus: () => dispatch(doResetThumbnailStatus()), }); export default connect(select, perform)(PublishPage); -- 2.45.3 From de8f116709132f44d7cbf5d6f6f640c685597aa9 Mon Sep 17 00:00:00 2001 From: Travis Eden Date: Mon, 2 Apr 2018 09:59:23 -0400 Subject: [PATCH 06/24] allow custom labels in file-selector --- src/renderer/component/common/file-selector.jsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/renderer/component/common/file-selector.jsx b/src/renderer/component/common/file-selector.jsx index d5d12cfde..737c21a22 100644 --- a/src/renderer/component/common/file-selector.jsx +++ b/src/renderer/component/common/file-selector.jsx @@ -9,6 +9,8 @@ type Props = { type: string, currentPath: ?string, onFileChosen: (string, string) => void, + fileLabel: ?string, + directoryLabel: ?string, }; class FileSelector extends React.PureComponent { @@ -47,15 +49,14 @@ class FileSelector extends React.PureComponent { input: ?HTMLInputElement; render() { - const { type, currentPath } = this.props; + const { type, currentPath, fileLabel, directoryLabel } = this.props; + + const label = + type === 'file' ? fileLabel || __('Choose File') : directoryLabel || __('Choose Directory'); return ( -