quick fix to redirect old urls to vanity channels

This commit is contained in:
Sean Yesmunt 2019-08-26 18:42:16 -04:00
parent 385ed220a5
commit 1ac5059116
3 changed files with 28 additions and 2 deletions

View file

@ -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),

View file

@ -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<Props> {
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 <Redirect to={`/@${channelName}`} />;
}
let innerContent = '';
if (!claim || (claim && !claim.name)) {

View file

@ -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."
}