From 235930815e46f1449b8dadd54a8cdb921191f577 Mon Sep 17 00:00:00 2001 From: jessopb <36554050+jessopb@users.noreply.github.com> Date: Thu, 21 May 2020 21:26:46 -0400 Subject: [PATCH] prevent paid content in embeds (#4230) --- ui/page/embedWrapper/index.js | 13 ++++++++++++- ui/page/embedWrapper/view.jsx | 27 +++++++++++++++++++-------- ui/scss/component/_embed-player.scss | 3 +++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/ui/page/embedWrapper/index.js b/ui/page/embedWrapper/index.js index 6df9fab66..2423e8021 100644 --- a/ui/page/embedWrapper/index.js +++ b/ui/page/embedWrapper/index.js @@ -1,7 +1,14 @@ import { connect } from 'react-redux'; import EmbedWrapperPage from './view'; -import { doResolveUri, makeSelectClaimForUri, buildURI } from 'lbry-redux'; +import { + doResolveUri, + makeSelectClaimForUri, + buildURI, + makeSelectStreamingUrlForUri, + makeSelectIsUriResolving, +} from 'lbry-redux'; import { doPlayUri } from 'redux/actions/content'; +import { makeSelectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc'; const select = (state, props) => { const { match } = props; @@ -11,6 +18,9 @@ const select = (state, props) => { return { uri, claim: makeSelectClaimForUri(uri)(state), + costInfo: makeSelectCostInfoForUri(uri)(state), + streamingUrl: makeSelectStreamingUrlForUri(uri)(state), + isResolvingUri: makeSelectIsUriResolving(uri)(state), }; }; @@ -18,6 +28,7 @@ const perform = dispatch => { return { resolveUri: uri => dispatch(doResolveUri(uri)), doPlayUri: uri => dispatch(doPlayUri(uri)), + doFetchCostInfoForUri: uri => dispatch(doFetchCostInfoForUri(uri)), }; }; diff --git a/ui/page/embedWrapper/view.jsx b/ui/page/embedWrapper/view.jsx index 4089e10d6..98115323a 100644 --- a/ui/page/embedWrapper/view.jsx +++ b/ui/page/embedWrapper/view.jsx @@ -7,29 +7,40 @@ type Props = { resolveUri: string => void, claim: Claim, doPlayUri: string => void, + costInfo: any, + streamingUrl: string, + doFetchCostInfoForUri: string => void, + isResolvingUri: boolean, }; // $FlowFixMe apparently flow thinks this is wrong. export const EmbedContext = React.createContext(); const EmbedWrapperPage = (props: Props) => { - const { resolveUri, claim, uri, doPlayUri } = props; + const { resolveUri, claim, uri, doPlayUri, costInfo, streamingUrl, doFetchCostInfoForUri, isResolvingUri } = props; const haveClaim = Boolean(claim); useEffect(() => { if (resolveUri && uri && !haveClaim) { resolveUri(uri); } - if (uri && haveClaim) { + if (uri && haveClaim && costInfo && costInfo.cost === 0) { doPlayUri(uri); } - }, [resolveUri, uri, doPlayUri, haveClaim]); + }, [resolveUri, uri, doPlayUri, haveClaim, costInfo]); + + useEffect(() => { + if (haveClaim && uri && doFetchCostInfoForUri) { + doFetchCostInfoForUri(uri); + } + }, [uri, haveClaim, doFetchCostInfoForUri]); return (
- {claim && ( - - - - )} + + {claim && streamingUrl && } + {!claim && isResolvingUri &&

Loading...

} + {!claim && !isResolvingUri &&

No content at this link.

} + {claim && costInfo && costInfo.cost > 0 &&

Paid content cannot be embedded.

} +
); }; diff --git a/ui/scss/component/_embed-player.scss b/ui/scss/component/_embed-player.scss index cee150ed8..c2cf7adb8 100644 --- a/ui/scss/component/_embed-player.scss +++ b/ui/scss/component/_embed-player.scss @@ -7,6 +7,9 @@ justify-content: space-between; align-items: center; background-color: var(--color-black); + h1 { + color: white; + } } .embed__inline-button {