From 1ac5059116e5dd015925b2698157d2b443145b1a Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 26 Aug 2019 18:42:16 -0400 Subject: [PATCH] quick fix to redirect old urls to vanity channels --- src/ui/page/show/index.js | 14 +++++++++++++- src/ui/page/show/view.jsx | 11 +++++++++++ static/locales/en.json | 5 ++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ui/page/show/index.js b/src/ui/page/show/index.js index 25f19bf43..6f464f253 100644 --- a/src/ui/page/show/index.js +++ b/src/ui/page/show/index.js @@ -14,7 +14,19 @@ const select = (state, props) => { const { pathname } = props.location; // Remove the leading "/" added by the browser const path = pathname.slice(1).replace(/:/g, '#'); - const uri = normalizeURI(path); + + let uri; + try { + uri = normalizeURI(path); + } catch (e) { + // Probably an old channel url, redirect to the vanity channel + // @routinghax + const match = path.match(/[#/:]/); + if (match && match.index) { + uri = `lbry://${path.slice(0, match.index)}`; + props.history.replace(`/${path.slice(0, match.index)}`); + } + } return { claim: makeSelectClaimForUri(uri)(state), diff --git a/src/ui/page/show/view.jsx b/src/ui/page/show/view.jsx index 23d558a5c..5e5aa52e7 100644 --- a/src/ui/page/show/view.jsx +++ b/src/ui/page/show/view.jsx @@ -1,5 +1,7 @@ // @flow import React from 'react'; +import { parseURI } from 'lbry-redux'; +import { Redirect } from 'react-router'; import BusyIndicator from 'component/common/busy-indicator'; import ChannelPage from 'page/channel'; import FilePage from 'page/file'; @@ -39,6 +41,15 @@ class ShowPage extends React.PureComponent { render() { const { claim, isResolvingUri, uri, blackListedOutpoints, location } = this.props; + const { channelName, channelClaimId, streamName, streamClaimId } = parseURI(uri); + + // @routinghax + if (channelName && !channelClaimId && streamName && !streamClaimId && !isResolvingUri && !claim) { + // Kinda hacky, but this is probably an old url + // Just redirect to the vanity channel + return ; + } + let innerContent = ''; if (!claim || (claim && !claim.name)) { diff --git a/static/locales/en.json b/static/locales/en.json index f7f97da41..cf5c73c32 100644 --- a/static/locales/en.json +++ b/static/locales/en.json @@ -648,5 +648,8 @@ "Trending": "Trending", "Top": "Top", "New": "New", - "Loading": "Loading" + "Loading": "Loading", + "I feel woosy! Stop spinning!": "I feel woosy! Stop spinning!", + "URI does not include name.": "URI does not include name.", + "This file is in your library.": "This file is in your library." } \ No newline at end of file