2020-08-19 17:25:50 -04:00
|
|
|
import { DOMAIN } from 'config';
|
2017-12-21 18:08:54 -03:00
|
|
|
import { connect } from 'react-redux';
|
2019-02-18 12:33:02 -05:00
|
|
|
import { PAGE_SIZE } from 'constants/claim';
|
2021-03-10 13:34:21 -05:00
|
|
|
import { LIVE_STREAM_TAG } from 'constants/livestream';
|
2018-04-24 14:17:11 -04:00
|
|
|
import {
|
|
|
|
doResolveUri,
|
|
|
|
makeSelectClaimForUri,
|
|
|
|
makeSelectIsUriResolving,
|
2019-02-18 12:33:02 -05:00
|
|
|
makeSelectTotalPagesForChannel,
|
2019-10-17 15:09:03 -04:00
|
|
|
makeSelectTitleForUri,
|
2019-08-19 00:49:54 -04:00
|
|
|
normalizeURI,
|
2019-12-13 13:44:28 -05:00
|
|
|
makeSelectClaimIsMine,
|
2020-07-02 12:47:36 -04:00
|
|
|
makeSelectClaimIsPending,
|
2021-03-10 13:34:21 -05:00
|
|
|
makeSelectTagInClaimOrChannelForUri,
|
2018-04-24 14:17:11 -04:00
|
|
|
} from 'lbry-redux';
|
2020-02-05 01:14:37 -05:00
|
|
|
import { makeSelectChannelInSubscriptions } from 'redux/selectors/subscriptions';
|
2019-03-12 15:53:55 -04:00
|
|
|
import { selectBlackListedOutpoints } from 'lbryinc';
|
2017-12-21 18:08:54 -03:00
|
|
|
import ShowPage from './view';
|
2017-05-05 13:13:06 +07:00
|
|
|
|
2019-03-28 12:53:13 -04:00
|
|
|
const select = (state, props) => {
|
2020-08-19 17:25:50 -04:00
|
|
|
const { pathname, hash, search } = props.location;
|
2019-08-27 12:05:23 -04:00
|
|
|
const urlPath = pathname + hash;
|
2019-08-19 00:49:54 -04:00
|
|
|
// Remove the leading "/" added by the browser
|
2020-08-19 17:25:50 -04:00
|
|
|
let path = urlPath.slice(1).replace(/:/g, '#');
|
|
|
|
|
|
|
|
// Google cache url
|
|
|
|
// ex: webcache.googleusercontent.com/search?q=cache:MLwN3a8fCbYJ:https://lbry.tv/%40Bombards_Body_Language:f+&cd=12&hl=en&ct=clnk&gl=us
|
|
|
|
// Extract the lbry url and use that instead
|
|
|
|
// Without this it will try to render lbry://search
|
|
|
|
if (search && search.startsWith('?q=cache:')) {
|
|
|
|
const googleCacheRegex = new RegExp(`(https://${DOMAIN}/)([^+]*)`);
|
|
|
|
const [x, y, googleCachedUrl] = search.match(googleCacheRegex); // eslint-disable-line
|
|
|
|
if (googleCachedUrl) {
|
|
|
|
const actualUrl = decodeURIComponent(googleCachedUrl);
|
|
|
|
if (actualUrl) {
|
2020-08-19 17:40:12 -04:00
|
|
|
path = actualUrl.replace(/:/g, '#');
|
2020-08-19 17:25:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 18:42:16 -04:00
|
|
|
|
|
|
|
let uri;
|
|
|
|
try {
|
|
|
|
uri = normalizeURI(path);
|
|
|
|
} catch (e) {
|
|
|
|
const match = path.match(/[#/:]/);
|
2019-09-26 12:07:11 -04:00
|
|
|
|
|
|
|
if (path === '$/') {
|
|
|
|
props.history.replace(`/`);
|
|
|
|
} else if (!path.startsWith('$/') && match && match.index) {
|
2019-08-26 18:42:16 -04:00
|
|
|
uri = `lbry://${path.slice(0, match.index)}`;
|
|
|
|
props.history.replace(`/${path.slice(0, match.index)}`);
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 17:05:23 -04:00
|
|
|
|
2019-03-28 12:53:13 -04:00
|
|
|
return {
|
2020-10-20 13:10:02 -04:00
|
|
|
uri,
|
2019-03-28 12:53:13 -04:00
|
|
|
claim: makeSelectClaimForUri(uri)(state),
|
|
|
|
isResolvingUri: makeSelectIsUriResolving(uri)(state),
|
|
|
|
blackListedOutpoints: selectBlackListedOutpoints(state),
|
|
|
|
totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state),
|
2020-02-05 01:14:37 -05:00
|
|
|
isSubscribed: makeSelectChannelInSubscriptions(uri)(state),
|
2019-10-17 15:09:03 -04:00
|
|
|
title: makeSelectTitleForUri(uri)(state),
|
2019-12-13 13:44:28 -05:00
|
|
|
claimIsMine: makeSelectClaimIsMine(uri)(state),
|
2020-07-02 12:47:36 -04:00
|
|
|
claimIsPending: makeSelectClaimIsPending(uri)(state),
|
2021-03-10 13:34:21 -05:00
|
|
|
// Change to !makeSelectClaimHasSource()
|
|
|
|
isLivestream: makeSelectTagInClaimOrChannelForUri(uri, LIVE_STREAM_TAG)(state),
|
2019-03-28 12:53:13 -04:00
|
|
|
};
|
|
|
|
};
|
2017-05-05 13:13:06 +07:00
|
|
|
|
2021-03-10 13:34:21 -05:00
|
|
|
const perform = (dispatch) => ({
|
|
|
|
resolveUri: (uri) => dispatch(doResolveUri(uri)),
|
2017-06-05 21:21:55 -07:00
|
|
|
});
|
2017-05-05 13:13:06 +07:00
|
|
|
|
2020-05-21 11:38:28 -04:00
|
|
|
export default connect(select, perform)(ShowPage);
|