diff --git a/ui/page/show/view.jsx b/ui/page/show/view.jsx index a1b807496..10fd38710 100644 --- a/ui/page/show/view.jsx +++ b/ui/page/show/view.jsx @@ -12,10 +12,13 @@ import Card from 'component/common/card'; import { formatLbryUrlForWeb } from 'util/url'; import { parseURI, COLLECTIONS_CONSTS } from 'lbry-redux'; -const AbandonedChannelPreview = lazyImport(() => import('component/abandonedChannelPreview' /* webpackChunkName: "abandonedChannelPreview" */)); +const AbandonedChannelPreview = lazyImport(() => + import('component/abandonedChannelPreview' /* webpackChunkName: "abandonedChannelPreview" */) +); const FilePage = lazyImport(() => import('page/file' /* webpackChunkName: "filePage" */)); const LivestreamPage = lazyImport(() => import('page/livestream' /* webpackChunkName: "livestream" */)); const Yrbl = lazyImport(() => import('component/yrbl' /* webpackChunkName: "yrbl" */)); +const isDev = process.env.NODE_ENV !== 'production'; type Props = { isResolvingUri: boolean, @@ -85,7 +88,8 @@ function ShowPage(props: Props) { const canonicalUrlPath = '/' + canonicalUrl.replace(/^lbry:\/\//, '').replace(/#/g, ':'); // 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) { + const hostname = isDev ? 'localhost' : DOMAIN; + if (canonicalUrlPath !== window.location.pathname && hostname === window.location.hostname) { const urlParams = new URLSearchParams(search); if (urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID)) { const listId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID) || ''; diff --git a/web/src/html.js b/web/src/html.js index 9070e9034..724bcc4f4 100644 --- a/web/src/html.js +++ b/web/src/html.js @@ -16,7 +16,7 @@ const { Lbry } = require('lbry-redux'); const { generateEmbedUrl, generateStreamUrl, generateDirectUrl } = require('../../ui/util/web'); const PAGES = require('../../ui/constants/pages'); const { CATEGORY_METADATA } = require('./category-metadata'); -const { parseURI, buildURI } = require('lbry-redux'); +const { parseURI, normalizeURI } = require('lbry-redux'); const fs = require('fs'); const path = require('path'); const moment = require('moment'); @@ -45,6 +45,10 @@ function truncateDescription(description) { return description.length > 200 ? description.substr(0, 200) + '...' : description; } +function normalizeClaimUrl(url) { + return normalizeURI(url.replace(/:/g, '#')); +} + function escapeHtmlProperty(property) { return property ? String(property) @@ -266,18 +270,14 @@ function buildGoogleVideoMetadata(uri, claim) { async function resolveClaimOrRedirect(ctx, url, ignoreRedirect = false) { let claim; - const parsedURI = parseURI(url); - try { - const url = buildURI(parsedURI); const response = await Lbry.resolve({ urls: [url] }); if (response && response[url] && !response[url].error) { claim = response && response[url]; - if (claim.reposted_claim) { - if (claim.reposted_claim.name && claim.reposted_claim.claim_id && !ignoreRedirect) { - ctx.redirect(`/${claim.reposted_claim.name}:${claim.reposted_claim.claim_id}`); - return; - } + const isRepost = claim.reposted_claim && claim.reposted_claim.name && claim.reposted_claim.claim_id; + if (isRepost && !ignoreRedirect) { + ctx.redirect(`/${claim.reposted_claim.name}:${claim.reposted_claim.claim_id}`); + return; } } } catch {} @@ -300,11 +300,9 @@ async function getHtml(ctx) { const embedPath = `/$/${PAGES.EMBED}/`; if (requestPath.includes(invitePath)) { - const inviteChannel = requestPath.slice(invitePath.length).replace(/:/g, '#'); - const inviteChannelUrl = `lbry://${inviteChannel}`; - try { - parseURI(inviteChannelUrl); + const inviteChannel = requestPath.slice(invitePath.length); + const inviteChannelUrl = normalizeClaimUrl(inviteChannel); const claim = await resolveClaimOrRedirect(ctx, inviteChannelUrl); const invitePageMetadata = buildClaimOgMetadata(inviteChannelUrl, claim, { title: `Join ${claim.name} on ${SITE_NAME}`, @@ -324,7 +322,7 @@ async function getHtml(ctx) { } if (requestPath.includes(embedPath)) { - const claimUri = requestPath.replace(embedPath, '').replace(/:/g, '#').replace('/', '#'); + const claimUri = normalizeClaimUrl(requestPath.replace(embedPath, '')); const claim = await resolveClaimOrRedirect(ctx, claimUri, true); if (claim) { @@ -347,7 +345,7 @@ async function getHtml(ctx) { } if (!requestPath.includes('$')) { - const claimUri = requestPath.slice(1).replace(/:/g, '#'); + const claimUri = normalizeClaimUrl(requestPath.slice(1)); const claim = await resolveClaimOrRedirect(ctx, claimUri); if (claim) {