fix redirection and normalization of claim urls
This commit is contained in:
parent
68e4684ccd
commit
c85e448499
2 changed files with 19 additions and 17 deletions
|
@ -12,10 +12,13 @@ import Card from 'component/common/card';
|
||||||
import { formatLbryUrlForWeb } from 'util/url';
|
import { formatLbryUrlForWeb } from 'util/url';
|
||||||
import { parseURI, COLLECTIONS_CONSTS } from 'lbry-redux';
|
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 FilePage = lazyImport(() => import('page/file' /* webpackChunkName: "filePage" */));
|
||||||
const LivestreamPage = lazyImport(() => import('page/livestream' /* webpackChunkName: "livestream" */));
|
const LivestreamPage = lazyImport(() => import('page/livestream' /* webpackChunkName: "livestream" */));
|
||||||
const Yrbl = lazyImport(() => import('component/yrbl' /* webpackChunkName: "yrbl" */));
|
const Yrbl = lazyImport(() => import('component/yrbl' /* webpackChunkName: "yrbl" */));
|
||||||
|
const isDev = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
isResolvingUri: boolean,
|
isResolvingUri: boolean,
|
||||||
|
@ -85,7 +88,8 @@ function ShowPage(props: Props) {
|
||||||
const canonicalUrlPath = '/' + canonicalUrl.replace(/^lbry:\/\//, '').replace(/#/g, ':');
|
const canonicalUrlPath = '/' + canonicalUrl.replace(/^lbry:\/\//, '').replace(/#/g, ':');
|
||||||
// Only redirect if we are in lbry.tv land
|
// Only redirect if we are in lbry.tv land
|
||||||
// replaceState will fail if on a different domain (like webcache.googleusercontent.com)
|
// 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);
|
const urlParams = new URLSearchParams(search);
|
||||||
if (urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID)) {
|
if (urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID)) {
|
||||||
const listId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID) || '';
|
const listId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID) || '';
|
||||||
|
|
|
@ -16,7 +16,7 @@ const { Lbry } = require('lbry-redux');
|
||||||
const { generateEmbedUrl, generateStreamUrl, generateDirectUrl } = require('../../ui/util/web');
|
const { generateEmbedUrl, generateStreamUrl, generateDirectUrl } = require('../../ui/util/web');
|
||||||
const PAGES = require('../../ui/constants/pages');
|
const PAGES = require('../../ui/constants/pages');
|
||||||
const { CATEGORY_METADATA } = require('./category-metadata');
|
const { CATEGORY_METADATA } = require('./category-metadata');
|
||||||
const { parseURI, buildURI } = require('lbry-redux');
|
const { parseURI, normalizeURI } = require('lbry-redux');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
@ -45,6 +45,10 @@ function truncateDescription(description) {
|
||||||
return description.length > 200 ? description.substr(0, 200) + '...' : description;
|
return description.length > 200 ? description.substr(0, 200) + '...' : description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeClaimUrl(url) {
|
||||||
|
return normalizeURI(url.replace(/:/g, '#'));
|
||||||
|
}
|
||||||
|
|
||||||
function escapeHtmlProperty(property) {
|
function escapeHtmlProperty(property) {
|
||||||
return property
|
return property
|
||||||
? String(property)
|
? String(property)
|
||||||
|
@ -266,18 +270,14 @@ function buildGoogleVideoMetadata(uri, claim) {
|
||||||
|
|
||||||
async function resolveClaimOrRedirect(ctx, url, ignoreRedirect = false) {
|
async function resolveClaimOrRedirect(ctx, url, ignoreRedirect = false) {
|
||||||
let claim;
|
let claim;
|
||||||
const parsedURI = parseURI(url);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = buildURI(parsedURI);
|
|
||||||
const response = await Lbry.resolve({ urls: [url] });
|
const response = await Lbry.resolve({ urls: [url] });
|
||||||
if (response && response[url] && !response[url].error) {
|
if (response && response[url] && !response[url].error) {
|
||||||
claim = response && response[url];
|
claim = response && response[url];
|
||||||
if (claim.reposted_claim) {
|
const isRepost = claim.reposted_claim && claim.reposted_claim.name && claim.reposted_claim.claim_id;
|
||||||
if (claim.reposted_claim.name && claim.reposted_claim.claim_id && !ignoreRedirect) {
|
if (isRepost && !ignoreRedirect) {
|
||||||
ctx.redirect(`/${claim.reposted_claim.name}:${claim.reposted_claim.claim_id}`);
|
ctx.redirect(`/${claim.reposted_claim.name}:${claim.reposted_claim.claim_id}`);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
@ -300,11 +300,9 @@ async function getHtml(ctx) {
|
||||||
const embedPath = `/$/${PAGES.EMBED}/`;
|
const embedPath = `/$/${PAGES.EMBED}/`;
|
||||||
|
|
||||||
if (requestPath.includes(invitePath)) {
|
if (requestPath.includes(invitePath)) {
|
||||||
const inviteChannel = requestPath.slice(invitePath.length).replace(/:/g, '#');
|
|
||||||
const inviteChannelUrl = `lbry://${inviteChannel}`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parseURI(inviteChannelUrl);
|
const inviteChannel = requestPath.slice(invitePath.length);
|
||||||
|
const inviteChannelUrl = normalizeClaimUrl(inviteChannel);
|
||||||
const claim = await resolveClaimOrRedirect(ctx, inviteChannelUrl);
|
const claim = await resolveClaimOrRedirect(ctx, inviteChannelUrl);
|
||||||
const invitePageMetadata = buildClaimOgMetadata(inviteChannelUrl, claim, {
|
const invitePageMetadata = buildClaimOgMetadata(inviteChannelUrl, claim, {
|
||||||
title: `Join ${claim.name} on ${SITE_NAME}`,
|
title: `Join ${claim.name} on ${SITE_NAME}`,
|
||||||
|
@ -324,7 +322,7 @@ async function getHtml(ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestPath.includes(embedPath)) {
|
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);
|
const claim = await resolveClaimOrRedirect(ctx, claimUri, true);
|
||||||
|
|
||||||
if (claim) {
|
if (claim) {
|
||||||
|
@ -347,7 +345,7 @@ async function getHtml(ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!requestPath.includes('$')) {
|
if (!requestPath.includes('$')) {
|
||||||
const claimUri = requestPath.slice(1).replace(/:/g, '#');
|
const claimUri = normalizeClaimUrl(requestPath.slice(1));
|
||||||
const claim = await resolveClaimOrRedirect(ctx, claimUri);
|
const claim = await resolveClaimOrRedirect(ctx, claimUri);
|
||||||
|
|
||||||
if (claim) {
|
if (claim) {
|
||||||
|
|
Loading…
Reference in a new issue