import React from 'react'; import lbry from '../lbry.js'; import lighthouse from '../lighthouse.js'; import lbryuri from '../lbryuri.js'; import {Video} from '../page/watch.js' import {TruncatedText, Thumbnail, FilePrice, BusyMessage} from '../component/common.js'; import {FileActions} from '../component/file-actions.js'; import {Link} from '../component/link.js'; import UriIndicator from '../component/channel-indicator.js'; var FormatItem = React.createClass({ propTypes: { metadata: React.PropTypes.object, contentType: React.PropTypes.string, uri: React.PropTypes.string, outpoint: React.PropTypes.string, }, render: function() { const {thumbnail, author, title, description, language, license} = this.props.metadata; const mediaType = lbry.getMediaType(this.props.contentType); if (!this.props.contentType && [author, language, license].filter().length === 0) { return null; } return (
Content-Type{this.props.contentType}
Author{author}
Language{language}
License{license}
); } }); let ChannelPage = React.createClass({ render: function() { return

{this.props.title}

This channel page is a stub.

} }) let ShowPage = React.createClass({ _uri: null, _isMounted: false, propTypes: { uri: React.PropTypes.string, }, getInitialState: function() { return { outpoint: null, metadata: null, contentType: null, hasSignature: false, claimType: null, signatureIsValid: false, cost: null, costIncludesData: null, uriLookupComplete: null, isDownloaded: null, isFailed: false, }; }, componentWillUnmount: function() { this._isMounted = false; }, componentWillReceiveProps: function(nextProps) { if (nextProps.uri != this.props.uri) { this.loadUri(nextProps.uri); } }, componentWillMount: function() { this._isMounted = true; this.loadUri(this.props.uri); }, loadUri: function(uri) { this._uri = lbryuri.normalize(uri); lbry.resolve({uri: this._uri}).then((resolveData) => { const isChannel = resolveData && resolveData.claims_in_channel; if (!this._isMounted) { return; } if (resolveData) { let newState = { uriLookupComplete: true } if (!isChannel) { let {claim: {txid: txid, nout: nout, has_signature: has_signature, signature_is_valid: signature_is_valid, value: {stream: {metadata: metadata, source: {contentType: contentType}}}}} = resolveData; Object.assign(newState, { claimType: "file", metadata: metadata, outpoint: txid + ':' + nout, hasSignature: has_signature, signatureIsValid: signature_is_valid, contentType: contentType }); lbry.file_list({outpoint: newState.outpoint}).then((fileInfo) => { this.setState({ isDownloaded: fileInfo.length > 0, }); }); lbry.setTitle(metadata.title ? metadata.title : this._uri) lbry.getCostInfo(this._uri).then(({cost, includesData}) => { if (this._isMounted) { this.setState({ cost: cost, costIncludesData: includesData, }); } }); } else { console.log('channel'); let {certificate: {txid: txid, nout: nout, has_signature: has_signature}} = resolveData; console.log(txid); Object.assign(newState, { claimType: "channel", outpoint: txid + ':' + nout, txid: txid, metadata: { title:resolveData.certificate.name } }); } this.setState(newState); } else { this.setState(Object.assign({}, this.getInitialState(), { uriLookupComplete: true, isFailed: true })); } }); }, render: function() { const metadata = this.state.metadata, title = metadata ? this.state.metadata.title : this._uri, channelUriObj = lbryuri.parse(this._uri); delete channelUriObj.path; delete channelUriObj.contentName; const channelUri = this.props.hasSignature && channelUriObj.isChannel ? lbryuri.build(channelUriObj, false) : null; if (this.state.isFailed) { return

{this._uri}

This location is not yet in use. { ' ' } .

} if (this.state.claimType == "channel") { return } const uriIndicator = ; return (
{ this.state.contentType && this.state.contentType.startsWith('video/') ?
{this.state.isDownloaded === false ? : null}

{title}

{ this.state.uriLookupComplete && this.state.outpoint ?
{ this.state.signatureIsValid ? {uriIndicator} : uriIndicator}
: '' }
{ this.state.uriLookupComplete ?
{metadata.description}
:
}
{ metadata ?
: '' }
); } }); export default ShowPage;