2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2020-08-18 05:41:28 +02:00
|
|
|
import { DOMAIN } from 'config';
|
2019-10-17 21:09:03 +02:00
|
|
|
import React, { useEffect } from 'react';
|
2020-02-14 17:42:38 +01:00
|
|
|
import { Redirect } from 'react-router-dom';
|
2020-09-02 22:08:37 +02:00
|
|
|
import Spinner from 'component/spinner';
|
2017-12-21 22:08:54 +01:00
|
|
|
import ChannelPage from 'page/channel';
|
|
|
|
import FilePage from 'page/file';
|
2021-03-15 21:50:54 +01:00
|
|
|
import LivestreamPage from 'page/livestream';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Page from 'component/page';
|
2018-04-24 20:17:11 +02:00
|
|
|
import Button from 'component/button';
|
2019-12-13 22:46:28 +01:00
|
|
|
import Card from 'component/common/card';
|
2020-02-05 07:14:37 +01:00
|
|
|
import AbandonedChannelPreview from 'component/abandonedChannelPreview';
|
2021-03-03 20:23:42 +01:00
|
|
|
import Yrbl from 'component/yrbl';
|
2020-02-14 17:42:38 +01:00
|
|
|
import { formatLbryUrlForWeb } from 'util/url';
|
2021-03-03 20:23:42 +01:00
|
|
|
import { parseURI } from 'lbry-redux';
|
2017-05-05 08:13:06 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
|
|
|
isResolvingUri: boolean,
|
2021-02-25 20:14:21 +01:00
|
|
|
resolveUri: (string) => void,
|
2020-02-05 07:14:37 +01:00
|
|
|
isSubscribed: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
uri: string,
|
2019-04-24 16:02:08 +02:00
|
|
|
claim: StreamClaim,
|
2019-03-28 17:53:13 +01:00
|
|
|
location: UrlLocation,
|
2018-04-24 20:17:11 +02:00
|
|
|
blackListedOutpoints: Array<{
|
|
|
|
txid: string,
|
|
|
|
nout: number,
|
|
|
|
}>,
|
2019-10-17 21:09:03 +02:00
|
|
|
title: string,
|
2020-07-02 18:47:36 +02:00
|
|
|
claimIsMine: boolean,
|
|
|
|
claimIsPending: boolean,
|
2021-03-10 19:34:21 +01:00
|
|
|
isLivestream: boolean,
|
2021-03-03 20:23:42 +01:00
|
|
|
claimIsMine: Boolean,
|
|
|
|
beginPublish: (string) => void,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2019-10-17 21:09:03 +02:00
|
|
|
function ShowPage(props: Props) {
|
2020-07-02 18:47:36 +02:00
|
|
|
const {
|
|
|
|
isResolvingUri,
|
|
|
|
resolveUri,
|
|
|
|
uri,
|
|
|
|
claim,
|
|
|
|
blackListedOutpoints,
|
|
|
|
location,
|
|
|
|
claimIsMine,
|
|
|
|
isSubscribed,
|
|
|
|
claimIsPending,
|
2021-03-10 19:34:21 +01:00
|
|
|
isLivestream,
|
2021-03-03 20:23:42 +01:00
|
|
|
beginPublish,
|
2020-07-02 18:47:36 +02:00
|
|
|
} = props;
|
2021-02-25 20:14:21 +01:00
|
|
|
|
2019-10-17 21:09:03 +02:00
|
|
|
const signingChannel = claim && claim.signing_channel;
|
2019-11-15 16:13:19 +01:00
|
|
|
const canonicalUrl = claim && claim.canonical_url;
|
2019-11-19 18:41:31 +01:00
|
|
|
const claimExists = claim !== null && claim !== undefined;
|
|
|
|
const haventFetchedYet = claim === undefined;
|
2020-05-01 23:08:57 +02:00
|
|
|
const isMine = claim && claim.is_my_output;
|
2021-03-03 20:23:42 +01:00
|
|
|
const { contentName } = parseURI(uri);
|
2017-05-12 01:28:43 +02:00
|
|
|
|
2019-10-17 21:09:03 +02:00
|
|
|
useEffect(() => {
|
2019-10-13 19:19:39 +02:00
|
|
|
// @if TARGET='web'
|
2019-11-15 16:13:19 +01:00
|
|
|
if (canonicalUrl) {
|
|
|
|
const canonicalUrlPath = '/' + canonicalUrl.replace(/^lbry:\/\//, '').replace(/#/g, ':');
|
2020-08-18 05:41:28 +02:00
|
|
|
// Only redirect if we are in lbry.tv land
|
|
|
|
// replaceState will fail if on a different domain (like webcache.googleusercontent.com)
|
|
|
|
if (canonicalUrlPath !== window.location.pathname && DOMAIN === window.location.hostname) {
|
2019-10-13 19:19:39 +02:00
|
|
|
history.replaceState(history.state, '', canonicalUrlPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// @endif
|
2019-11-15 16:13:19 +01:00
|
|
|
|
2020-05-01 23:08:57 +02:00
|
|
|
if (
|
|
|
|
(resolveUri && !isResolvingUri && uri && haventFetchedYet) ||
|
2020-07-02 18:47:36 +02:00
|
|
|
(claimExists && !claimIsPending && (!canonicalUrl || isMine === undefined))
|
2020-05-01 23:08:57 +02:00
|
|
|
) {
|
2017-10-12 16:05:18 +02:00
|
|
|
resolveUri(uri);
|
|
|
|
}
|
2020-07-02 18:47:36 +02:00
|
|
|
}, [resolveUri, isResolvingUri, canonicalUrl, uri, claimExists, haventFetchedYet, history, isMine, claimIsPending]);
|
2020-02-03 18:23:21 +01:00
|
|
|
|
2020-02-14 17:42:38 +01:00
|
|
|
// Don't navigate directly to repost urls
|
|
|
|
// Always redirect to the actual content
|
|
|
|
// Also need to add repost_url to the Claim type for flow
|
|
|
|
// $FlowFixMe
|
|
|
|
if (claim && claim.repost_url === uri) {
|
|
|
|
const newUrl = formatLbryUrlForWeb(claim.canonical_url);
|
|
|
|
return <Redirect to={newUrl} />;
|
|
|
|
}
|
2019-08-27 00:42:16 +02:00
|
|
|
|
2020-02-14 17:42:38 +01:00
|
|
|
let innerContent = '';
|
2019-10-17 21:09:03 +02:00
|
|
|
if (!claim || (claim && !claim.name)) {
|
|
|
|
innerContent = (
|
|
|
|
<Page>
|
2020-09-02 22:08:37 +02:00
|
|
|
{(claim === undefined || isResolvingUri) && (
|
|
|
|
<div className="main--empty">
|
2021-03-03 20:23:42 +01:00
|
|
|
<Spinner delayed />
|
2020-09-02 22:08:37 +02:00
|
|
|
</div>
|
|
|
|
)}
|
2020-02-05 07:14:37 +01:00
|
|
|
{!isResolvingUri && !isSubscribed && (
|
2021-03-03 20:23:42 +01:00
|
|
|
<div className="main--empty">
|
|
|
|
<Yrbl
|
|
|
|
title={__('No Content Found')}
|
|
|
|
subtitle={
|
|
|
|
<div className="section__actions">
|
|
|
|
<Button button="primary" label={__('Publish Something')} onClick={() => beginPublish(contentName)} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-02-05 07:14:37 +01:00
|
|
|
)}
|
2020-02-06 19:27:48 +01:00
|
|
|
{!isResolvingUri && isSubscribed && claim === null && <AbandonedChannelPreview uri={uri} type={'large'} />}
|
2019-10-17 21:09:03 +02:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
} else if (claim.name.length && claim.name[0] === '@') {
|
|
|
|
innerContent = <ChannelPage uri={uri} location={location} />;
|
2021-02-25 20:14:21 +01:00
|
|
|
} else if (claim) {
|
2019-10-17 21:09:03 +02:00
|
|
|
let isClaimBlackListed = false;
|
2017-05-05 08:13:06 +02:00
|
|
|
|
2021-02-25 20:14:21 +01:00
|
|
|
isClaimBlackListed =
|
|
|
|
blackListedOutpoints &&
|
|
|
|
blackListedOutpoints.some(
|
|
|
|
(outpoint) =>
|
|
|
|
(signingChannel && outpoint.txid === signingChannel.txid && outpoint.nout === signingChannel.nout) ||
|
|
|
|
(outpoint.txid === claim.txid && outpoint.nout === claim.nout)
|
|
|
|
);
|
2019-03-04 17:57:07 +01:00
|
|
|
|
2019-12-13 19:44:28 +01:00
|
|
|
if (isClaimBlackListed && !claimIsMine) {
|
2019-12-13 22:46:28 +01:00
|
|
|
innerContent = (
|
|
|
|
<Page>
|
|
|
|
<Card
|
|
|
|
title={uri}
|
|
|
|
subtitle={__(
|
|
|
|
'In response to a complaint we received under the US Digital Millennium Copyright Act, we have blocked access to this content from our applications.'
|
|
|
|
)}
|
|
|
|
actions={
|
2020-05-01 19:55:42 +02:00
|
|
|
<div className="section__actions">
|
2019-12-13 22:46:28 +01:00
|
|
|
<Button button="link" href="https://lbry.com/faq/dmca" label={__('Read More')} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Page>
|
|
|
|
);
|
2021-03-23 01:57:46 +01:00
|
|
|
} else if (isLivestream) {
|
2021-03-10 19:34:21 +01:00
|
|
|
innerContent = <LivestreamPage uri={uri} />;
|
2019-10-17 21:09:03 +02:00
|
|
|
} else {
|
2019-12-13 22:46:28 +01:00
|
|
|
innerContent = <FilePage uri={uri} location={location} />;
|
2017-05-05 08:13:06 +02:00
|
|
|
}
|
2017-05-10 05:06:48 +02:00
|
|
|
}
|
2019-10-17 21:09:03 +02:00
|
|
|
|
|
|
|
return innerContent;
|
2017-05-05 08:13:06 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default ShowPage;
|