// @flow import * as React from 'react'; import * as settings from 'constants/settings'; import { buildURI, normalizeURI, MODALS } from 'lbry-redux'; import FileViewer from 'component/fileViewer'; 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 ViewOnWebButton from 'component/viewOnWebButton'; import Page from 'component/page'; import type { Claim } from 'types/claim'; import type { Subscription } from 'types/subscription'; import FileDownloadLink from 'component/fileDownloadLink'; import classnames from 'classnames'; import getMediaType from 'util/getMediaType'; import RecommendedContent from 'component/recommendedContent'; import { FormField, FormRow } from 'component/common/form'; import ToolTip from 'component/common/tooltip'; type Props = { claim: Claim, fileInfo: {}, metadata: { title: string, thumbnail: string, file_name: string, nsfw: boolean, }, contentType: string, uri: string, rewardedContentClaimIds: Array, obscureNsfw: boolean, claimIsMine: boolean, costInfo: ?{}, navigate: (string, ?{}) => void, openModal: ({ id: string }, { uri: string }) => void, fetchFileInfo: string => void, fetchCostInfo: string => void, prepareEdit: ({}, string) => void, checkSubscription: (uri: string) => void, subscriptions: Array, setViewed: string => void, }; class FilePage extends React.Component { static PLAYABLE_MEDIA_TYPES = ['audio', 'video']; static PREVIEW_MEDIA_TYPES = [ 'text', 'model', 'image', 'script', 'document', '3D-file', // Bypass unplayable files // TODO: Find a better way to detect supported types 'application', ]; constructor(props: Props) { super(props); (this: any).onAutoplayChange = this.onAutoplayChange.bind(this); } componentDidMount() { const { uri, fileInfo, fetchFileInfo, fetchCostInfo, setViewed } = this.props; if (fileInfo === undefined) { fetchFileInfo(uri); } // See https://github.com/lbryio/lbry-desktop/pull/1563 for discussion fetchCostInfo(uri); this.checkSubscription(this.props); setViewed(uri); } componentWillReceiveProps(nextProps: Props) { const { fetchFileInfo, uri } = this.props; if (nextProps.fileInfo === undefined) { fetchFileInfo(uri); } } onAutoplayChange(event: SyntheticInputEvent<*>) { this.props.setClientSetting(settings.AUTOPLAY, event.target.checked); } checkSubscription = (props: Props) => { if (props.subscriptions.find(sub => sub.channelName === props.claim.channel_name)) { props.checkSubscription( buildURI( { contentName: props.claim.channel_name, claimId: props.claim.value.publisherSignature.certificateId, }, false ) ); } }; render() { const { claim, metadata, contentType, uri, rewardedContentClaimIds, obscureNsfw, openModal, claimIsMine, prepareEdit, navigate, costInfo, fileInfo, autoplay, } = this.props; // File info const { title, thumbnail } = metadata; const { height, channel_name: channelName, value } = claim; const { PLAYABLE_MEDIA_TYPES, PREVIEW_MEDIA_TYPES } = FilePage; const isRewardContent = (rewardedContentClaimIds || []).includes(claim.claim_id); const shouldObscureThumbnail = obscureNsfw && metadata.nsfw; const fileName = fileInfo ? fileInfo.file_name : null; const mediaType = getMediaType(contentType, fileName); const showFile = PLAYABLE_MEDIA_TYPES.includes(mediaType) || PREVIEW_MEDIA_TYPES.includes(mediaType); const channelClaimId = value && value.publisherSignature && value.publisherSignature.certificateId; let subscriptionUri; if (channelName && channelClaimId) { subscriptionUri = buildURI({ channelName, claimId: channelClaimId }, false); } const speechSharable = costInfo && costInfo.cost === 0 && contentType && ['video', 'image'].includes(contentType.split('/')[0]); // We want to use the short form uri for editing // This is what the user is used to seeing, they don't care about the claim id // We will select the claim id before they publish let editUri; if (claimIsMine) { const uriObject = { contentName: claim.name, claimId: claim.claim_id }; if (channelName) { uriObject.channelName = channelName; } editUri = buildURI(uriObject); } return (
{showFile && } {!showFile && (thumbnail ? ( ) : (
{__("Sorry, looks like we can't preview this file.")}
))}

{title}

{isRewardContent && }
{__('Published on')}  {metadata.nsfw &&
NSFW
}
{claimIsMine ? (
); } } export default FilePage;