prevent paid content in embeds #4230

Merged
jessopb merged 1 commit from fix-embedsPaid into master 2020-05-22 03:26:47 +02:00
3 changed files with 34 additions and 9 deletions

View file

@ -1,7 +1,14 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import EmbedWrapperPage from './view'; 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 { doPlayUri } from 'redux/actions/content';
import { makeSelectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc';
const select = (state, props) => { const select = (state, props) => {
const { match } = props; const { match } = props;
@ -11,6 +18,9 @@ const select = (state, props) => {
return { return {
uri, uri,
claim: makeSelectClaimForUri(uri)(state), claim: makeSelectClaimForUri(uri)(state),
costInfo: makeSelectCostInfoForUri(uri)(state),
streamingUrl: makeSelectStreamingUrlForUri(uri)(state),
isResolvingUri: makeSelectIsUriResolving(uri)(state),
}; };
}; };
@ -18,6 +28,7 @@ const perform = dispatch => {
return { return {
resolveUri: uri => dispatch(doResolveUri(uri)), resolveUri: uri => dispatch(doResolveUri(uri)),
doPlayUri: uri => dispatch(doPlayUri(uri)), doPlayUri: uri => dispatch(doPlayUri(uri)),
doFetchCostInfoForUri: uri => dispatch(doFetchCostInfoForUri(uri)),
}; };
}; };

View file

@ -7,29 +7,40 @@ type Props = {
resolveUri: string => void, resolveUri: string => void,
claim: Claim, claim: Claim,
doPlayUri: string => void, doPlayUri: string => void,
costInfo: any,
streamingUrl: string,
doFetchCostInfoForUri: string => void,
isResolvingUri: boolean,
}; };
// $FlowFixMe apparently flow thinks this is wrong. // $FlowFixMe apparently flow thinks this is wrong.
export const EmbedContext = React.createContext(); export const EmbedContext = React.createContext();
const EmbedWrapperPage = (props: Props) => { const EmbedWrapperPage = (props: Props) => {
const { resolveUri, claim, uri, doPlayUri } = props; const { resolveUri, claim, uri, doPlayUri, costInfo, streamingUrl, doFetchCostInfoForUri, isResolvingUri } = props;
const haveClaim = Boolean(claim); const haveClaim = Boolean(claim);
useEffect(() => { useEffect(() => {
if (resolveUri && uri && !haveClaim) { if (resolveUri && uri && !haveClaim) {
resolveUri(uri); resolveUri(uri);
} }
if (uri && haveClaim) { if (uri && haveClaim && costInfo && costInfo.cost === 0) {
doPlayUri(uri); doPlayUri(uri);
} }
}, [resolveUri, uri, doPlayUri, haveClaim]); }, [resolveUri, uri, doPlayUri, haveClaim, costInfo]);
useEffect(() => {
if (haveClaim && uri && doFetchCostInfoForUri) {
doFetchCostInfoForUri(uri);
}
}, [uri, haveClaim, doFetchCostInfoForUri]);
return ( return (
<div className={'embed__wrapper'}> <div className={'embed__wrapper'}>
{claim && ( <EmbedContext.Provider value>
<EmbedContext.Provider value> {claim && streamingUrl && <FileRender uri={uri} embedded />}
<FileRender uri={uri} embedded /> {!claim && isResolvingUri && <h1>Loading...</h1>}
</EmbedContext.Provider> {!claim && !isResolvingUri && <h1>No content at this link.</h1>}
)} {claim && costInfo && costInfo.cost > 0 && <h1>Paid content cannot be embedded.</h1>}
</EmbedContext.Provider>
</div> </div>
); );
}; };

View file

@ -7,6 +7,9 @@
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
background-color: var(--color-black); background-color: var(--color-black);
h1 {
color: white;
}
} }
.embed__inline-button { .embed__inline-button {