2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
2017-04-24 09:25:27 +02:00
|
|
|
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';
|
2017-04-07 07:15:22 +02:00
|
|
|
import Link from 'component/link';
|
2017-04-24 09:25:27 +02:00
|
|
|
import UriIndicator from 'component/channel-indicator.js';
|
2016-07-16 04:58:24 +02:00
|
|
|
|
|
|
|
var FormatItem = React.createClass({
|
|
|
|
propTypes: {
|
2017-04-11 03:29:07 +02:00
|
|
|
metadata: React.PropTypes.object,
|
|
|
|
contentType: React.PropTypes.string,
|
|
|
|
uri: React.PropTypes.string,
|
2017-03-08 08:17:16 +01:00
|
|
|
outpoint: React.PropTypes.string,
|
2016-07-16 04:58:24 +02:00
|
|
|
},
|
|
|
|
render: function() {
|
2017-04-24 09:25:27 +02:00
|
|
|
const {thumbnail, author, title, description, language, license} = this.props.metadata;
|
|
|
|
const mediaType = lbry.getMediaType(this.props.contentType);
|
2017-05-01 05:38:14 +02:00
|
|
|
|
2016-07-16 04:58:24 +02:00
|
|
|
return (
|
2017-04-13 20:52:26 +02:00
|
|
|
<table className="table-standard">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>Content-Type</td><td>{this.props.contentType}</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Author</td><td>{author}</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Language</td><td>{language}</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>License</td><td>{license}</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
);
|
2016-07-16 04:58:24 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-05-01 21:59:40 +02:00
|
|
|
let ChannelPage = React.createClass({
|
|
|
|
render: function() {
|
|
|
|
return <main className="main--single-column">
|
|
|
|
<section className="card">
|
|
|
|
<div className="card__inner">
|
|
|
|
<div className="card__title-identity"><h1>{this.props.title}</h1></div>
|
|
|
|
</div>
|
|
|
|
<div className="card__content">
|
|
|
|
<p>
|
|
|
|
This channel page is a stub.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
}
|
2017-05-01 22:50:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
let FilePage = React.createClass({
|
|
|
|
_isMounted: false,
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
uri: React.PropTypes.string,
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
cost: null,
|
|
|
|
costIncludesData: null,
|
|
|
|
isDownloaded: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._isMounted = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillReceiveProps: function(nextProps) {
|
|
|
|
if (nextProps.outpoint != this.props.outpoint || nextProps.uri != this.props.uri) {
|
|
|
|
this.loadCostAndFileState(nextProps.uri, nextProps.outpoint);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
|
|
|
this._isMounted = true;
|
|
|
|
this.loadCostAndFileState(this.props.uri, this.props.outpoint);
|
|
|
|
},
|
|
|
|
|
|
|
|
loadCostAndFileState: function(uri, outpoint) {
|
|
|
|
lbry.file_list({outpoint: outpoint}).then((fileInfo) => {
|
|
|
|
if (this._isMounted) {
|
|
|
|
this.setState({
|
|
|
|
isDownloaded: fileInfo.length > 0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
lbry.getCostInfo(uri).then(({cost, includesData}) => {
|
|
|
|
if (this._isMounted) {
|
|
|
|
this.setState({
|
|
|
|
cost: cost,
|
|
|
|
costIncludesData: includesData,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
const metadata = this.props.metadata,
|
|
|
|
title = metadata ? this.props.metadata.title : this.props.uri,
|
|
|
|
uriIndicator = <UriIndicator uri={this.props.uri} hasSignature={this.props.hasSignature} signatureIsValid={this.props.signatureIsValid} />;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<main className="main--single-column">
|
|
|
|
<section className="show-page-media">
|
|
|
|
{ this.props.contentType && this.props.contentType.startsWith('video/') ?
|
|
|
|
<Video className="video-embedded" uri={this.props.uri} metadata={metadata} outpoint={this.props.outpoint} /> :
|
|
|
|
(metadata ? <Thumbnail src={metadata.thumbnail} /> : <Thumbnail />) }
|
|
|
|
</section>
|
|
|
|
<section className="card">
|
|
|
|
<div className="card__inner">
|
|
|
|
<div className="card__title-identity">
|
|
|
|
{this.state.isDownloaded === false
|
|
|
|
? <span style={{float: "right"}}><FilePrice uri={this.props.uri} metadata={metadata} /></span>
|
|
|
|
: null}
|
|
|
|
<h1>{title}</h1>
|
|
|
|
<div className="card__subtitle">
|
|
|
|
{ this.props.channelUri ?
|
|
|
|
<Link href={"?show=" + this.props.channelUri }>{uriIndicator}</Link> :
|
|
|
|
uriIndicator}
|
|
|
|
</div>
|
|
|
|
<div className="card__actions">
|
|
|
|
<FileActions uri={this.props.uri} outpoint={this.props.outpoint} metadata={metadata} contentType={this.props.contentType} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="card__content card__subtext card__subtext card__subtext--allow-newlines">
|
|
|
|
{metadata.description}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{ metadata ?
|
|
|
|
<div className="card__content">
|
|
|
|
<FormatItem metadata={metadata} contentType={this.state.contentType} cost={this.state.cost} uri={this.props.uri} outpoint={this.props.outpoint} costIncludesData={this.state.costIncludesData} />
|
|
|
|
</div> : '' }
|
|
|
|
<div className="card__content">
|
|
|
|
<Link href="https://lbry.io/dmca" label="report" className="button-text-help" />
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2017-05-01 21:59:40 +02:00
|
|
|
|
2017-04-13 20:52:26 +02:00
|
|
|
let ShowPage = React.createClass({
|
2017-04-11 03:29:07 +02:00
|
|
|
_uri: null,
|
2017-05-01 05:38:14 +02:00
|
|
|
_isMounted: false,
|
2017-04-11 03:29:07 +02:00
|
|
|
|
2016-07-16 04:58:24 +02:00
|
|
|
propTypes: {
|
2017-04-11 03:29:07 +02:00
|
|
|
uri: React.PropTypes.string,
|
2016-07-16 04:58:24 +02:00
|
|
|
},
|
2017-05-01 05:38:14 +02:00
|
|
|
|
2016-07-16 19:14:06 +02:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2017-05-01 05:38:14 +02:00
|
|
|
outpoint: null,
|
2016-12-08 00:45:18 +01:00
|
|
|
metadata: null,
|
2017-04-11 03:29:07 +02:00
|
|
|
contentType: null,
|
2017-04-13 20:52:26 +02:00
|
|
|
hasSignature: false,
|
2017-05-01 21:59:40 +02:00
|
|
|
claimType: null,
|
2017-04-13 20:52:26 +02:00
|
|
|
signatureIsValid: false,
|
2016-12-08 00:45:18 +01:00
|
|
|
cost: null,
|
2016-12-08 01:38:52 +01:00
|
|
|
costIncludesData: null,
|
2017-04-11 03:29:07 +02:00
|
|
|
uriLookupComplete: null,
|
2017-05-01 05:38:14 +02:00
|
|
|
isFailed: false,
|
2016-07-16 19:14:06 +02:00
|
|
|
};
|
|
|
|
},
|
2017-05-01 05:38:14 +02:00
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._isMounted = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillReceiveProps: function(nextProps) {
|
|
|
|
if (nextProps.uri != this.props.uri) {
|
2017-05-01 22:50:07 +02:00
|
|
|
this.setState(this.getInitialState());
|
2017-05-01 05:38:14 +02:00
|
|
|
this.loadUri(nextProps.uri);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-16 19:14:06 +02:00
|
|
|
componentWillMount: function() {
|
2017-05-01 21:59:40 +02:00
|
|
|
this._isMounted = true;
|
2017-05-01 05:38:14 +02:00
|
|
|
this.loadUri(this.props.uri);
|
|
|
|
},
|
|
|
|
|
|
|
|
loadUri: function(uri) {
|
|
|
|
this._uri = lbryuri.normalize(uri);
|
2016-08-08 06:47:48 +02:00
|
|
|
|
2017-05-01 05:38:14 +02:00
|
|
|
lbry.resolve({uri: this._uri}).then((resolveData) => {
|
2017-05-01 21:59:40 +02:00
|
|
|
const isChannel = resolveData && resolveData.claims_in_channel;
|
|
|
|
if (!this._isMounted) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-01 05:38:14 +02:00
|
|
|
if (resolveData) {
|
2017-05-01 21:59:40 +02:00
|
|
|
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;
|
2017-05-01 05:38:14 +02:00
|
|
|
|
2017-05-01 21:59:40 +02:00
|
|
|
Object.assign(newState, {
|
|
|
|
claimType: "file",
|
2017-05-01 05:38:14 +02:00
|
|
|
metadata: metadata,
|
2017-05-01 21:59:40 +02:00
|
|
|
outpoint: txid + ':' + nout,
|
2017-05-01 05:38:14 +02:00
|
|
|
hasSignature: has_signature,
|
|
|
|
signatureIsValid: signature_is_valid,
|
2017-05-01 21:59:40 +02:00
|
|
|
contentType: contentType
|
2017-05-01 05:38:14 +02:00
|
|
|
});
|
|
|
|
|
2017-05-01 21:59:40 +02:00
|
|
|
|
|
|
|
lbry.setTitle(metadata.title ? metadata.title : this._uri)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
let {certificate: {txid: txid, nout: nout, has_signature: has_signature}} = resolveData;
|
|
|
|
Object.assign(newState, {
|
|
|
|
claimType: "channel",
|
|
|
|
outpoint: txid + ':' + nout,
|
|
|
|
txid: txid,
|
|
|
|
metadata: {
|
|
|
|
title:resolveData.certificate.name
|
|
|
|
}
|
|
|
|
});
|
2017-05-01 05:38:14 +02:00
|
|
|
}
|
2017-05-01 21:59:40 +02:00
|
|
|
|
|
|
|
this.setState(newState);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.setState(Object.assign({}, this.getInitialState(), {
|
|
|
|
uriLookupComplete: true,
|
|
|
|
isFailed: true
|
|
|
|
}));
|
2017-05-01 05:38:14 +02:00
|
|
|
}
|
2016-07-16 19:14:06 +02:00
|
|
|
});
|
|
|
|
},
|
2017-05-01 05:38:14 +02:00
|
|
|
|
2016-07-16 04:58:24 +02:00
|
|
|
render: function() {
|
2017-05-01 21:59:40 +02:00
|
|
|
const metadata = this.state.metadata,
|
2017-04-24 09:25:27 +02:00
|
|
|
title = metadata ? this.state.metadata.title : this._uri;
|
2017-05-01 21:59:40 +02:00
|
|
|
|
2017-05-01 22:50:07 +02:00
|
|
|
let innerContent = "";
|
2017-04-27 05:54:53 +02:00
|
|
|
|
2017-05-01 22:50:07 +02:00
|
|
|
if (!this.state.uriLookupComplete || this.state.isFailed) {
|
|
|
|
innerContent = <section className="card">
|
2017-04-24 09:25:27 +02:00
|
|
|
<div className="card__inner">
|
|
|
|
<div className="card__title-identity"><h1>{title}</h1></div>
|
|
|
|
</div>
|
|
|
|
<div className="card__content">
|
|
|
|
{ this.state.uriLookupComplete ?
|
|
|
|
<p>This location is not yet in use. { ' ' }<Link href="?publish" label="Put something here" />.</p> :
|
|
|
|
<BusyMessage message="Loading magic decentralized data..." />
|
|
|
|
}
|
|
|
|
</div>
|
2017-05-01 22:50:07 +02:00
|
|
|
</section>;
|
|
|
|
} else if (this.state.claimType == "channel") {
|
|
|
|
innerContent = <ChannelPage title={this._uri} />
|
|
|
|
} else {
|
|
|
|
let channelUriObj = lbryuri.parse(this._uri)
|
|
|
|
delete channelUriObj.path;
|
|
|
|
delete channelUriObj.contentName;
|
|
|
|
const channelUri = this.state.signatureIsValid && this.state.hasSignature && channelUriObj.isChannel ? lbryuri.build(channelUriObj, false) : null;
|
|
|
|
innerContent = <FilePage
|
|
|
|
uri={this._uri}
|
|
|
|
channelUri={channelUri}
|
|
|
|
outpoint={this.state.outpoint}
|
|
|
|
metadata={metadata}
|
|
|
|
contentType={this.state.contentType}
|
|
|
|
hasSignature={this.state.hasSignature}
|
|
|
|
signatureIsValid={this.state.signatureIsValid}
|
|
|
|
/>;
|
2017-05-01 05:38:14 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 22:50:07 +02:00
|
|
|
return <main className="main--single-column">{innerContent}</main>;
|
2016-07-16 04:58:24 +02:00
|
|
|
}
|
2016-11-22 21:19:08 +01:00
|
|
|
});
|
|
|
|
|
2017-04-11 03:29:07 +02:00
|
|
|
export default ShowPage;
|
2017-04-24 09:25:27 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// const ShowPage = (props) => {
|
|
|
|
// const {
|
|
|
|
// claim,
|
|
|
|
// uri,
|
|
|
|
// isDownloaded,
|
|
|
|
// fileInfo,
|
|
|
|
// costInfo,
|
|
|
|
// } = props
|
|
|
|
// const {
|
|
|
|
// txid,
|
|
|
|
// nout,
|
|
|
|
// has_signature,
|
|
|
|
// signature_is_valid,
|
|
|
|
// value,
|
|
|
|
// } = claim
|
|
|
|
// const {
|
|
|
|
// stream,
|
|
|
|
// } = value
|
|
|
|
// const {
|
|
|
|
// metadata,
|
|
|
|
// source,
|
|
|
|
// } = stream
|
|
|
|
// const {
|
|
|
|
// title,
|
|
|
|
// } = metadata
|
|
|
|
// const {
|
|
|
|
// contentType,
|
|
|
|
// } = source
|
|
|
|
// const {
|
|
|
|
// cost,
|
|
|
|
// includesData,
|
|
|
|
// } = costInfo
|
|
|
|
// const costIncludesData = includesData
|
|
|
|
//
|
|
|
|
// const outpoint = txid + ':' + nout;
|
|
|
|
// const uriLookupComplete = !!claim
|
|
|
|
// const hasSignature = has_signature
|
|
|
|
// const signatureIsValid = signature_is_valid
|
|
|
|
//
|
|
|
|
// return (
|
|
|
|
// <main className="main--single-column">
|
|
|
|
// <section className="show-page-media">
|
|
|
|
// { contentType && contentType.startsWith('video/') ?
|
|
|
|
// <Video className="video-embedded" uri={uri} metadata={metadata} outpoint={outpoint} /> :
|
|
|
|
// (metadata ? <Thumbnail src={metadata.thumbnail} /> : <Thumbnail />) }
|
|
|
|
// </section>
|
|
|
|
// <section className="card">
|
|
|
|
// <div className="card__inner">
|
|
|
|
// <div className="card__title-identity">
|
|
|
|
// {isDownloaded === false
|
|
|
|
// ? <span style={{float: "right"}}><FilePrice uri={uri} metadata={metadata} /></span>
|
|
|
|
// : null}
|
|
|
|
// <h1>{title}</h1>
|
|
|
|
// { uriLookupComplete ?
|
|
|
|
// <div>
|
|
|
|
// <div className="card__subtitle">
|
|
|
|
// <UriIndicator uri={uri} hasSignature={hasSignature} signatureIsValid={signatureIsValid} />
|
|
|
|
// </div>
|
|
|
|
// <div className="card__actions">
|
|
|
|
// <FileActions uri={uri} outpoint={outpoint} metadata={metadata} contentType={contentType} />
|
|
|
|
// </div>
|
|
|
|
// </div> : '' }
|
|
|
|
// </div>
|
|
|
|
// { uriLookupComplete ?
|
|
|
|
// <div>
|
|
|
|
// <div className="card__content card__subtext card__subtext card__subtext--allow-newlines">
|
|
|
|
// {metadata.description}
|
|
|
|
// </div>
|
|
|
|
// </div>
|
|
|
|
// : <div className="card__content"><BusyMessage message="Loading magic decentralized data..." /></div> }
|
|
|
|
// </div>
|
|
|
|
// { metadata ?
|
|
|
|
// <div className="card__content">
|
|
|
|
// <FormatItem metadata={metadata} contentType={contentType} cost={cost} uri={uri} outpoint={outpoint} costIncludesData={costIncludesData} />
|
|
|
|
// </div> : '' }
|
|
|
|
// <div className="card__content">
|
|
|
|
// <Link href="https://lbry.io/dmca" label="report" className="button-text-help" />
|
|
|
|
// </div>
|
|
|
|
// </section>
|
|
|
|
// </main>
|
|
|
|
// )
|
|
|
|
// }
|