diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 2177543..568ff79 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -153,9 +153,6 @@ const PURCHASE_URI_STARTED = 'PURCHASE_URI_STARTED'; const PURCHASE_URI_COMPLETED = 'PURCHASE_URI_COMPLETED'; const PURCHASE_URI_FAILED = 'PURCHASE_URI_FAILED'; const DELETE_PURCHASED_URI = 'DELETE_PURCHASED_URI'; -const LOADING_FILE_STARTED = 'LOADING_FILE_STARTED'; -const LOADING_FILE_COMPLETED = 'LOADING_FILE_COMPLETED'; -const LOADING_FILE_FAILED = 'LOADING_FILE_FAILED'; // Search const SEARCH_START = 'SEARCH_START'; @@ -382,9 +379,6 @@ var action_types = /*#__PURE__*/Object.freeze({ PURCHASE_URI_COMPLETED: PURCHASE_URI_COMPLETED, PURCHASE_URI_FAILED: PURCHASE_URI_FAILED, DELETE_PURCHASED_URI: DELETE_PURCHASED_URI, - LOADING_FILE_STARTED: LOADING_FILE_STARTED, - LOADING_FILE_COMPLETED: LOADING_FILE_COMPLETED, - LOADING_FILE_FAILED: LOADING_FILE_FAILED, SEARCH_START: SEARCH_START, SEARCH_SUCCESS: SEARCH_SUCCESS, SEARCH_FAIL: SEARCH_FAIL, @@ -717,8 +711,10 @@ const Lbry = { // Get mediaType from contentType if (contentType) { - return (/^[^/]+/.exec(contentType)[0] - ); + const matches = /^[^/]+/.exec(contentType); + if (matches) { + return matches[0]; + } } return 'unknown'; @@ -2625,8 +2621,6 @@ const selectFailedPurchaseUris = reselect.createSelector(selectState$4, state => const selectPurchasedUris = reselect.createSelector(selectState$4, state => state.purchasedUris); -const selectPurchasedStreamingUrls = reselect.createSelector(selectState$4, state => state.purchasedStreamingUrls); - const selectLastPurchasedUri = reselect.createSelector(selectState$4, state => state.purchasedUris.length > 0 ? state.purchasedUris[state.purchasedUris.length - 1] : null); const makeSelectStreamingUrlForUri = uri => reselect.createSelector(makeSelectFileInfoForUri(uri), fileInfo => { @@ -2638,7 +2632,7 @@ const makeSelectStreamingUrlForUri = uri => reselect.createSelector(makeSelectFi function doFileGet(uri, saveFile = true, onSuccess) { return dispatch => { dispatch({ - type: LOADING_FILE_STARTED, + type: PURCHASE_URI_STARTED, data: { uri } @@ -2649,10 +2643,6 @@ function doFileGet(uri, saveFile = true, onSuccess) { const timeout = streamInfo === null || typeof streamInfo !== 'object' || streamInfo.error === 'Timeout'; if (timeout) { - dispatch({ - type: LOADING_FILE_FAILED, - data: { uri } - }); dispatch({ type: PURCHASE_URI_FAILED, data: { uri } @@ -2661,10 +2651,9 @@ function doFileGet(uri, saveFile = true, onSuccess) { dispatch(doToast({ message: `File timeout for uri ${uri}`, isError: true })); } else { // purchase was completed successfully - const { streaming_url: streamingUrl } = streamInfo; dispatch({ type: PURCHASE_URI_COMPLETED, - data: { uri, streamingUrl } + data: { uri } }); dispatch({ type: FETCH_FILE_INFO_COMPLETED, @@ -2679,10 +2668,6 @@ function doFileGet(uri, saveFile = true, onSuccess) { } } }).catch(() => { - dispatch({ - type: LOADING_FILE_FAILED, - data: { uri } - }); dispatch({ type: PURCHASE_URI_FAILED, data: { uri } @@ -4060,7 +4045,6 @@ const reducers$3 = {}; const defaultState$4 = { failedPurchaseUris: [], purchasedUris: [], - purchasedStreamingUrls: {}, purchaseUriErrorMessage: '' }; @@ -4078,10 +4062,9 @@ reducers$3[PURCHASE_URI_STARTED] = (state, action) => { }; reducers$3[PURCHASE_URI_COMPLETED] = (state, action) => { - const { uri, streamingUrl } = action.data; + const { uri } = action.data; const newPurchasedUris = state.purchasedUris.slice(); const newFailedPurchaseUris = state.failedPurchaseUris.slice(); - const newPurchasedStreamingUrls = Object.assign({}, state.purchasedStreamingUrls); if (!newPurchasedUris.includes(uri)) { newPurchasedUris.push(uri); @@ -4089,14 +4072,10 @@ reducers$3[PURCHASE_URI_COMPLETED] = (state, action) => { if (newFailedPurchaseUris.includes(uri)) { newFailedPurchaseUris.splice(newFailedPurchaseUris.indexOf(uri), 1); } - if (streamingUrl) { - newPurchasedStreamingUrls[uri] = streamingUrl; - } return _extends$9({}, state, { failedPurchaseUris: newFailedPurchaseUris, purchasedUris: newPurchasedUris, - purchasedStreamingUrls: newPurchasedStreamingUrls, purchaseUriErrorMessage: '' }); }; @@ -4976,7 +4955,6 @@ exports.selectPendingClaims = selectPendingClaims; exports.selectPlayingUri = selectPlayingUri; exports.selectPublishFormValues = selectPublishFormValues; exports.selectPurchaseUriErrorMessage = selectPurchaseUriErrorMessage; -exports.selectPurchasedStreamingUrls = selectPurchasedStreamingUrls; exports.selectPurchasedUris = selectPurchasedUris; exports.selectReceiveAddress = selectReceiveAddress; exports.selectRecentTransactions = selectRecentTransactions; diff --git a/dist/flow-typed/File.js b/dist/flow-typed/File.js index 42c9b16..c4c151c 100644 --- a/dist/flow-typed/File.js +++ b/dist/flow-typed/File.js @@ -38,7 +38,6 @@ declare type FileListItem = { declare type FileState = { failedPurchaseUris: Array, purchasedUris: Array, - purchasedStreamingUrls: {}, }; declare type PurchaseUriCompleted = { @@ -53,7 +52,7 @@ declare type PurchaseUriFailed = { type: ACTIONS.PURCHASE_URI_FAILED, data: { uri: string, - error: any + error: any, }, }; @@ -68,6 +67,6 @@ declare type PurchaseUriStarted = { declare type DeletePurchasedUri = { type: ACTIONS.DELETE_PURCHASED_URI, data: { - uri: string + uri: string, }, }; diff --git a/dist/flow-typed/mime.js b/dist/flow-typed/mime.js new file mode 100644 index 0000000..476b179 --- /dev/null +++ b/dist/flow-typed/mime.js @@ -0,0 +1,4 @@ +// @flow +declare module 'mime' { + declare module.exports: any; +} diff --git a/flow-typed/File.js b/flow-typed/File.js index 42c9b16..c4c151c 100644 --- a/flow-typed/File.js +++ b/flow-typed/File.js @@ -38,7 +38,6 @@ declare type FileListItem = { declare type FileState = { failedPurchaseUris: Array, purchasedUris: Array, - purchasedStreamingUrls: {}, }; declare type PurchaseUriCompleted = { @@ -53,7 +52,7 @@ declare type PurchaseUriFailed = { type: ACTIONS.PURCHASE_URI_FAILED, data: { uri: string, - error: any + error: any, }, }; @@ -68,6 +67,6 @@ declare type PurchaseUriStarted = { declare type DeletePurchasedUri = { type: ACTIONS.DELETE_PURCHASED_URI, data: { - uri: string + uri: string, }, }; diff --git a/flow-typed/mime.js b/flow-typed/mime.js new file mode 100644 index 0000000..476b179 --- /dev/null +++ b/flow-typed/mime.js @@ -0,0 +1,4 @@ +// @flow +declare module 'mime' { + declare module.exports: any; +} diff --git a/src/constants/action_types.js b/src/constants/action_types.js index b75997b..4b07603 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -127,9 +127,6 @@ export const PURCHASE_URI_STARTED = 'PURCHASE_URI_STARTED'; export const PURCHASE_URI_COMPLETED = 'PURCHASE_URI_COMPLETED'; export const PURCHASE_URI_FAILED = 'PURCHASE_URI_FAILED'; export const DELETE_PURCHASED_URI = 'DELETE_PURCHASED_URI'; -export const LOADING_FILE_STARTED = 'LOADING_FILE_STARTED'; -export const LOADING_FILE_COMPLETED = 'LOADING_FILE_COMPLETED'; -export const LOADING_FILE_FAILED = 'LOADING_FILE_FAILED'; // Search export const SEARCH_START = 'SEARCH_START'; diff --git a/src/index.js b/src/index.js index 9a5574e..2161100 100644 --- a/src/index.js +++ b/src/index.js @@ -140,7 +140,6 @@ export { selectToast, selectError } from 'redux/selectors/notifications'; export { selectFailedPurchaseUris, selectPurchasedUris, - selectPurchasedStreamingUrls, selectPurchaseUriErrorMessage, selectLastPurchasedUri, makeSelectStreamingUrlForUri, diff --git a/src/lbry.js b/src/lbry.js index 5ceb6dd..b87a8a2 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -61,7 +61,10 @@ const Lbry: LbryTypes = { // Get mediaType from contentType if (contentType) { - return /^[^/]+/.exec(contentType)[0]; + const matches = /^[^/]+/.exec(contentType); + if (matches) { + return matches[0]; + } } return 'unknown'; diff --git a/src/redux/actions/file.js b/src/redux/actions/file.js index 305ff4f..1697687 100644 --- a/src/redux/actions/file.js +++ b/src/redux/actions/file.js @@ -12,7 +12,7 @@ type GetState = () => { file: FileState }; export function doFileGet(uri: string, saveFile: boolean = true, onSuccess?: GetResponse => any) { return (dispatch: Dispatch) => { dispatch({ - type: ACTIONS.LOADING_FILE_STARTED, + type: ACTIONS.PURCHASE_URI_STARTED, data: { uri, }, @@ -25,10 +25,6 @@ export function doFileGet(uri: string, saveFile: boolean = true, onSuccess?: Get streamInfo === null || typeof streamInfo !== 'object' || streamInfo.error === 'Timeout'; if (timeout) { - dispatch({ - type: ACTIONS.LOADING_FILE_FAILED, - data: { uri }, - }); dispatch({ type: ACTIONS.PURCHASE_URI_FAILED, data: { uri }, @@ -37,10 +33,9 @@ export function doFileGet(uri: string, saveFile: boolean = true, onSuccess?: Get dispatch(doToast({ message: `File timeout for uri ${uri}`, isError: true })); } else { // purchase was completed successfully - const { streaming_url: streamingUrl } = streamInfo; dispatch({ type: ACTIONS.PURCHASE_URI_COMPLETED, - data: { uri, streamingUrl }, + data: { uri }, }); dispatch({ type: ACTIONS.FETCH_FILE_INFO_COMPLETED, @@ -56,10 +51,6 @@ export function doFileGet(uri: string, saveFile: boolean = true, onSuccess?: Get } }) .catch(() => { - dispatch({ - type: ACTIONS.LOADING_FILE_FAILED, - data: { uri }, - }); dispatch({ type: ACTIONS.PURCHASE_URI_FAILED, data: { uri }, diff --git a/src/redux/reducers/file.js b/src/redux/reducers/file.js index 95a3b7e..0e9a40e 100644 --- a/src/redux/reducers/file.js +++ b/src/redux/reducers/file.js @@ -5,7 +5,6 @@ const reducers = {}; const defaultState = { failedPurchaseUris: [], purchasedUris: [], - purchasedStreamingUrls: {}, purchaseUriErrorMessage: '', }; @@ -30,10 +29,9 @@ reducers[ACTIONS.PURCHASE_URI_COMPLETED] = ( state: FileState, action: PurchaseUriCompleted ): FileState => { - const { uri, streamingUrl } = action.data; + const { uri } = action.data; const newPurchasedUris = state.purchasedUris.slice(); const newFailedPurchaseUris = state.failedPurchaseUris.slice(); - const newPurchasedStreamingUrls = Object.assign({}, state.purchasedStreamingUrls); if (!newPurchasedUris.includes(uri)) { newPurchasedUris.push(uri); @@ -41,15 +39,11 @@ reducers[ACTIONS.PURCHASE_URI_COMPLETED] = ( if (newFailedPurchaseUris.includes(uri)) { newFailedPurchaseUris.splice(newFailedPurchaseUris.indexOf(uri), 1); } - if (streamingUrl) { - newPurchasedStreamingUrls[uri] = streamingUrl; - } return { ...state, failedPurchaseUris: newFailedPurchaseUris, purchasedUris: newPurchasedUris, - purchasedStreamingUrls: newPurchasedStreamingUrls, purchaseUriErrorMessage: '', }; }; diff --git a/src/redux/selectors/file.js b/src/redux/selectors/file.js index 3e5b4b8..dbdb0be 100644 --- a/src/redux/selectors/file.js +++ b/src/redux/selectors/file.js @@ -21,11 +21,6 @@ export const selectPurchasedUris: (state: State) => Array = createSelect state => state.purchasedUris ); -export const selectPurchasedStreamingUrls: (state: State) => {} = createSelector( - selectState, - state => state.purchasedStreamingUrls -); - export const selectLastPurchasedUri: (state: State) => string = createSelector( selectState, state =>