From 263c09500f62000312c42dcabc328e7755aff3e3 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Thu, 11 Nov 2021 07:59:37 +0800 Subject: [PATCH] -- Revert to allow restoring commits --- This reverts commit cb6a0445840dd3699741778145728fccfc0e434d. --- config.js | 1 - extras/lbryinc/constants/action_types.js | 3 + extras/lbryinc/index.js | 3 + extras/lbryinc/redux/actions/web.js | 12 + extras/lbryinc/redux/reducers/web.js | 62 +++ extras/lbryinc/redux/selectors/web.js | 10 + flow-typed/publish.js | 21 - package.json | 1 - static/app-strings.json | 11 +- ui/component/app/index.js | 2 +- ui/component/publishForm/view.jsx | 2 +- ui/component/webUploadList/index.js | 17 +- .../internal/web-upload-item.jsx | 159 ++------ ui/component/webUploadList/view.jsx | 25 +- ui/constants/action_types.js | 6 +- ui/index.jsx | 4 +- ui/page/fileListPublished/index.js | 2 +- ui/reducers.js | 3 +- ui/redux/actions/publish.js | 364 +++++++----------- ui/redux/reducers/publish.js | 74 ---- ui/redux/selectors/publish.js | 7 - ui/scss/component/_claim-list.scss | 19 - ui/util/file.js | 5 - web/setup/publish-v1.js | 70 ---- web/setup/publish-v2.js | 100 ----- web/setup/publish.js | 60 ++- yarn.lock | 96 +---- 27 files changed, 325 insertions(+), 814 deletions(-) create mode 100644 extras/lbryinc/redux/actions/web.js create mode 100644 extras/lbryinc/redux/reducers/web.js create mode 100644 extras/lbryinc/redux/selectors/web.js delete mode 100644 ui/util/file.js delete mode 100644 web/setup/publish-v1.js delete mode 100644 web/setup/publish-v2.js diff --git a/config.js b/config.js index 00d543226..a3f98d320 100644 --- a/config.js +++ b/config.js @@ -8,7 +8,6 @@ const config = { WEB_SERVER_PORT: process.env.WEB_SERVER_PORT, LBRY_WEB_API: process.env.LBRY_WEB_API, //api.na-backend.odysee.com', LBRY_WEB_PUBLISH_API: process.env.LBRY_WEB_PUBLISH_API, - LBRY_WEB_PUBLISH_API_V2: process.env.LBRY_WEB_PUBLISH_API_V2, LBRY_API_URL: process.env.LBRY_API_URL, //api.lbry.com', LBRY_WEB_STREAMING_API: process.env.LBRY_WEB_STREAMING_API, //cdn.lbryplayer.xyz', LBRY_WEB_BUFFER_API: process.env.LBRY_WEB_BUFFER_API, diff --git a/extras/lbryinc/constants/action_types.js b/extras/lbryinc/constants/action_types.js index b978223c7..82c3a819d 100644 --- a/extras/lbryinc/constants/action_types.js +++ b/extras/lbryinc/constants/action_types.js @@ -83,6 +83,9 @@ export const SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED'; export const SYNC_APPLY_BAD_PASSWORD = 'SYNC_APPLY_BAD_PASSWORD'; export const SYNC_RESET = 'SYNC_RESET'; +// Lbry.tv +export const UPDATE_UPLOAD_PROGRESS = 'UPDATE_UPLOAD_PROGRESS'; + // User export const GENERATE_AUTH_TOKEN_FAILURE = 'GENERATE_AUTH_TOKEN_FAILURE'; export const GENERATE_AUTH_TOKEN_STARTED = 'GENERATE_AUTH_TOKEN_STARTED'; diff --git a/extras/lbryinc/index.js b/extras/lbryinc/index.js index cd87cad0c..bb64484d7 100644 --- a/extras/lbryinc/index.js +++ b/extras/lbryinc/index.js @@ -27,6 +27,7 @@ export { doResetSync, doSyncEncryptAndDecrypt, } from 'redux/actions/sync'; +export { doUpdateUploadProgress } from './redux/actions/web'; // reducers export { authReducer } from './redux/reducers/auth'; @@ -36,6 +37,7 @@ export { filteredReducer } from './redux/reducers/filtered'; // export { homepageReducer } from './redux/reducers/homepage'; export { statsReducer } from './redux/reducers/stats'; export { syncReducer } from './redux/reducers/sync'; +export { webReducer } from './redux/reducers/web'; // selectors export { selectAuthToken, selectIsAuthenticating } from './redux/selectors/auth'; @@ -68,3 +70,4 @@ export { selectSyncApplyErrorMessage, selectSyncApplyPasswordError, } from './redux/selectors/sync'; +export { selectCurrentUploads, selectUploadCount } from './redux/selectors/web'; diff --git a/extras/lbryinc/redux/actions/web.js b/extras/lbryinc/redux/actions/web.js new file mode 100644 index 000000000..1bcce69a5 --- /dev/null +++ b/extras/lbryinc/redux/actions/web.js @@ -0,0 +1,12 @@ +// @flow +import * as ACTIONS from 'constants/action_types'; + +export const doUpdateUploadProgress = ( + progress: string, + params: { [key: string]: any }, + xhr: any +) => (dispatch: Dispatch) => + dispatch({ + type: ACTIONS.UPDATE_UPLOAD_PROGRESS, + data: { progress, params, xhr }, + }); diff --git a/extras/lbryinc/redux/reducers/web.js b/extras/lbryinc/redux/reducers/web.js new file mode 100644 index 000000000..7cb9f674d --- /dev/null +++ b/extras/lbryinc/redux/reducers/web.js @@ -0,0 +1,62 @@ +// @flow +import * as ACTIONS from 'constants/action_types'; + +/* +test mock: + currentUploads: { + 'test#upload': { + progress: 50, + params: { + name: 'steve', + thumbnail_url: 'https://dev2.spee.ch/4/KMNtoSZ009fawGz59VG8PrID.jpeg', + }, + }, + }, + */ + +export type Params = { + channel?: string, + name: string, + thumbnail_url: ?string, + title: ?string, +}; + +export type UploadItem = { + progess: string, + params: Params, + xhr?: any, +}; + +export type TvState = { + currentUploads: { [key: string]: UploadItem }, +}; + +const reducers = {}; + +const defaultState: TvState = { + currentUploads: {}, +}; + +reducers[ACTIONS.UPDATE_UPLOAD_PROGRESS] = (state: TvState, action) => { + const { progress, params, xhr } = action.data; + const key = params.channel ? `${params.name}#${params.channel}` : `${params.name}#anonymous`; + let currentUploads; + if (!progress) { + currentUploads = Object.assign({}, state.currentUploads); + Object.keys(currentUploads).forEach(k => { + if (k === key) { + delete currentUploads[key]; + } + }); + } else { + currentUploads = Object.assign({}, state.currentUploads); + currentUploads[key] = { progress, params, xhr }; + } + return { ...state, currentUploads }; +}; + +export function webReducer(state: TvState = defaultState, action: any) { + const handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} diff --git a/extras/lbryinc/redux/selectors/web.js b/extras/lbryinc/redux/selectors/web.js new file mode 100644 index 000000000..de676f837 --- /dev/null +++ b/extras/lbryinc/redux/selectors/web.js @@ -0,0 +1,10 @@ +import { createSelector } from 'reselect'; + +const selectState = (state) => state.web || {}; + +export const selectCurrentUploads = (state) => selectState(state).currentUploads; + +export const selectUploadCount = createSelector( + selectCurrentUploads, + (currentUploads) => currentUploads && Object.keys(currentUploads).length +); diff --git a/flow-typed/publish.js b/flow-typed/publish.js index 1ae871aac..f237b12c9 100644 --- a/flow-typed/publish.js +++ b/flow-typed/publish.js @@ -52,24 +52,3 @@ declare type PublishParams = { nsfw: boolean, tags: Array, }; - -declare type TusUploader = any; - -declare type FileUploadSdkParams = { - file_path: string, - name: ?string, - preview?: boolean, - remote_url?: string, - thumbnail_url?: string, - title?: string, -}; - -declare type FileUploadItem = { - params: FileUploadSdkParams, - file: File, - fileFingerprint: string, - progress: string, - status?: string, - uploader?: TusUploader | XMLHttpRequest, - resumable: boolean, -}; diff --git a/package.json b/package.json index 8b84fc9f7..24d772d98 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,6 @@ "rss": "^1.2.2", "source-map-explorer": "^2.5.2", "tempy": "^0.6.0", - "tus-js-client": "^2.3.0", "videojs-contrib-ads": "^6.9.0", "videojs-ima": "^1.11.0", "videojs-ima-player": "^0.5.6", diff --git a/static/app-strings.json b/static/app-strings.json index b195710c8..fe308ad0d 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -1291,16 +1291,6 @@ "Select a file to upload": "Select a file to upload", "Select file to upload": "Select file to upload", "Url copied.": "Url copied.", - "Failed to initiate upload (%err%)": "Failed to initiate upload (%err%)", - "Invalid file": "Invalid file", - "It appears to be a different or modified file.": "It appears to be a different or modified file.", - "Please select the same file from the initial upload.": "Please select the same file from the initial upload.", - "Cancel upload": "Cancel upload", - "Cancel and remove the selected upload?": "Cancel and remove the selected upload?", - "Select the file to resume upload...": "Select the file to resume upload...", - "Stopped.": "Stopped.", - "Resume": "Resume", - "Retrying...": "Retrying...", "Uploading...": "Uploading...", "Creating...": "Creating...", "Use a URL": "Use a URL", @@ -1440,6 +1430,7 @@ "Log in to %SITE_NAME%": "Log in to %SITE_NAME%", "Log in": "Log in", "Not Yet": "Not Yet", + "Preparing...": "Preparing...", "Confirm Upload": "Confirm Upload", "Confirm Edit": "Confirm Edit", "Create Livestream": "Create Livestream", diff --git a/ui/component/app/index.js b/ui/component/app/index.js index 9103a2e0b..3c3563506 100644 --- a/ui/component/app/index.js +++ b/ui/component/app/index.js @@ -1,5 +1,6 @@ import { hot } from 'react-hot-loader/root'; import { connect } from 'react-redux'; +import { selectUploadCount } from 'lbryinc'; import { selectGetSyncErrorMessage, selectSyncFatalError } from 'redux/selectors/sync'; import { doFetchAccessToken, doUserSetReferrer } from 'redux/actions/user'; import { selectUser, selectAccessToken, selectUserVerifiedEmail } from 'redux/selectors/user'; @@ -21,7 +22,6 @@ import { selectActiveChannelClaim, selectIsReloadRequired, } from 'redux/selectors/app'; -import { selectUploadCount } from 'redux/selectors/publish'; import { doGetWalletSyncPreference, doSetLanguage } from 'redux/actions/settings'; import { doSyncLoop } from 'redux/actions/sync'; import { diff --git a/ui/component/publishForm/view.jsx b/ui/component/publishForm/view.jsx index f4e6896d7..0143a12f5 100644 --- a/ui/component/publishForm/view.jsx +++ b/ui/component/publishForm/view.jsx @@ -325,7 +325,7 @@ function PublishForm(props: Props) { submitLabel = __('Uploading...'); } } else if (previewing) { - submitLabel = ; + submitLabel = __('Preparing...'); } else { if (isStillEditing) { submitLabel = __('Save'); diff --git a/ui/component/webUploadList/index.js b/ui/component/webUploadList/index.js index 2c546f202..73023158e 100644 --- a/ui/component/webUploadList/index.js +++ b/ui/component/webUploadList/index.js @@ -1,18 +1,13 @@ import { connect } from 'react-redux'; -import { doOpenModal } from 'redux/actions/app'; -import { doPublishResume, doUpdateUploadRemove } from 'redux/actions/publish'; -import { selectCurrentUploads, selectUploadCount } from 'redux/selectors/publish'; +import { selectCurrentUploads, selectUploadCount } from 'lbryinc'; import WebUploadList from './view'; -const select = (state) => ({ +const select = state => ({ currentUploads: selectCurrentUploads(state), uploadCount: selectUploadCount(state), }); -const perform = { - doPublishResume, - doUpdateUploadRemove, - doOpenModal, -}; - -export default connect(select, perform)(WebUploadList); +export default connect( + select, + null +)(WebUploadList); diff --git a/ui/component/webUploadList/internal/web-upload-item.jsx b/ui/component/webUploadList/internal/web-upload-item.jsx index 9c8489d96..39177746d 100644 --- a/ui/component/webUploadList/internal/web-upload-item.jsx +++ b/ui/component/webUploadList/internal/web-upload-item.jsx @@ -1,155 +1,40 @@ // @flow -import React, { useState } from 'react'; -import FileSelector from 'component/common/file-selector'; +import React from 'react'; import Button from 'component/button'; import FileThumbnail from 'component/fileThumbnail'; -import * as MODALS from 'constants/modal_types'; -import { serializeFileObj } from 'util/file'; - type Props = { - uploadItem: FileUploadItem, - doPublishResume: (any) => void, - doUpdateUploadRemove: (any) => void, - doOpenModal: (string, {}) => void, + params: UpdatePublishFormData, + progress: string, + xhr?: () => void, }; export default function WebUploadItem(props: Props) { - const { uploadItem, doPublishResume, doUpdateUploadRemove, doOpenModal } = props; - const { params, file, fileFingerprint, progress, status, resumable, uploader } = uploadItem; - - const [showFileSelector, setShowFileSelector] = useState(false); - - function handleFileChange(newFile: WebFile, clearName = true) { - if (serializeFileObj(newFile) === fileFingerprint) { - setShowFileSelector(false); - doPublishResume({ ...params, file_path: newFile }); - } else { - doOpenModal(MODALS.CONFIRM, { - title: __('Invalid file'), - subtitle: __('It appears to be a different or modified file.'), - body:

{__('Please select the same file from the initial upload.')}

, - onConfirm: (closeModal) => closeModal(), - hideCancel: true, - }); - } - } - - function handleCancel() { - doOpenModal(MODALS.CONFIRM, { - title: __('Cancel upload'), - subtitle: __('Cancel and remove the selected upload?'), - body: params.name ?

{`lbry://${params.name}`}

: undefined, - onConfirm: (closeModal) => { - if (uploader) { - if (resumable) { - // $FlowFixMe - couldn't resolve to TusUploader manually. - uploader.abort(true); // TUS - } else { - uploader.abort(); // XHR - } - } - doUpdateUploadRemove(params); - closeModal(); - }, - }); - } - - function resolveProgressStr() { - if (!uploader) { - return __('Stopped.'); - } - - if (resumable) { - if (status) { - switch (status) { - case 'retry': - return __('Retrying...'); - case 'error': - return __('Failed.'); - default: - return status; - } - } else { - const progressInt = parseInt(progress); - return progressInt === 100 ? __('Processing...') : __('Uploading...'); - } - } else { - return __('Uploading...'); - } - } - - function getRetryButton() { - if (!resumable) { - return null; - } - - if (uploader) { - // Should still be uploading. Don't show. - return null; - } else { - // Refreshed or connection broken. - const isFileActive = file instanceof File; - return ( -