// @flow import * as React from 'react'; import lbry from 'lbry'; import { buildURI, normalizeURI } from 'lbryURI'; import Video from 'component/video'; import Thumbnail from 'component/common/thumbnail'; import FilePrice from 'component/filePrice'; import FileDetails from 'component/fileDetails'; import FileActions from 'component/fileActions'; import UriIndicator from 'component/uriIndicator'; import Icon from 'component/common/icon'; import DateTime from 'component/dateTime'; import * as icons from 'constants/icons'; import Button from 'component/button'; import SubscribeButton from 'component/subscribeButton'; import Page from 'component/page'; import player from 'render-media'; import * as modals from 'constants/modal_types'; type Props = { claim: { claim_id: string, height: number, channel_name: string, value: { publisherSignature: ?{ certificateId: ?string, }, }, }, fileInfo: {}, metadata: { title: string, thumbnail: string, nsfw: boolean, }, contentType: string, uri: string, rewardedContentClaimIds: Array, obscureNsfw: boolean, playingUri: ?string, isPaused: boolean, claimIsMine: boolean, costInfo: ?{}, navigate: (string, ?{}) => void, openModal: (string, any) => void, fetchFileInfo: string => void, fetchCostInfo: string => void, prepareEdit: ({}) => void, }; class FilePage extends React.Component { componentDidMount() { const { uri, fileInfo, fetchFileInfo, costInfo, fetchCostInfo } = this.props; if (fileInfo === undefined) { fetchFileInfo(uri); } if (costInfo === undefined) { fetchCostInfo(uri); } this.checkSubscription(this.props); } componentWillReceiveProps(nextProps: Props) { const { fetchFileInfo, uri } = this.props; if (nextProps.fileInfo === undefined) { fetchFileInfo(uri); } } checkSubscription = (props: Props) => { if ( props.subscriptions .map(subscription => subscription.channelName) .indexOf(props.claim.channel_name) !== -1 ) { props.checkSubscription({ channelName: props.claim.channel_name, uri: buildURI( { contentName: props.claim.channel_name, claimId: props.claim.value.publisherSignature.certificateId, }, false ), }); } }; render() { const { claim, metadata, contentType, uri, rewardedContentClaimIds, obscureNsfw, playingUri, isPaused, openModal, claimIsMine, prepareEdit, navigate, } = this.props; // File info const { title, thumbnail } = metadata; const isRewardContent = rewardedContentClaimIds.includes(claim.claim_id); const shouldObscureThumbnail = obscureNsfw && metadata.nsfw; const { height, channel_name: channelName, value } = claim; const mediaType = lbry.getMediaType(contentType); const isPlayable = Object.values(player.mime).indexOf(contentType) !== -1 || mediaType === 'audio'; const channelClaimId = value && value.publisherSignature && value.publisherSignature.certificateId; let subscriptionUri; if (channelName && channelClaimId) { subscriptionUri = buildURI({ channelName, claimId: channelClaimId }, false); } const isPlaying = playingUri === uri && !isPaused; return ( {!claim || !metadata ? (
{__('Empty claim or metadata info.')}
) : (
{isPlayable ? (
)}
); } } export default FilePage;