Merge pull request #1511 from lbryio/special-links

special links/invalid URIs
This commit is contained in:
Sean Yesmunt 2018-05-30 14:47:38 -04:00 committed by GitHub
commit 44cc987a14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 9 deletions

View file

@ -242,8 +242,11 @@ const isSecondInstance = app.makeSingleInstance(argv => {
// path, so we just strip it off.
// - In a URI with a claim ID, like lbry://channel#claimid, Windows interprets the hash mark as
// an anchor and converts it to lbry://channel/#claimid. We remove the slash here as well.
// - ? also interpreted as an anchor, remove slash also.
if (process.platform === 'win32') {
URI = URI.replace(/\/$/, '').replace('/#', '#');
URI = URI.replace(/\/$/, '')
.replace('/#', '#')
.replace('/?', '?');
}
rendererWindow.webContents.send('open-uri-requested', URI);

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { selectCurrentPage, selectCurrentParams } from 'lbry-redux';
import { selectCurrentPage, selectCurrentParams, doNotify } from 'lbry-redux';
import Router from './view';
const select = state => ({
@ -7,4 +7,4 @@ const select = state => ({
currentPage: selectCurrentPage(state),
});
export default connect(select, null)(Router);
export default connect(select, { doNotify })(Router);

View file

@ -18,16 +18,21 @@ import InvitePage from 'page/invite';
import BackupPage from 'page/backup';
import SubscriptionsPage from 'page/subscriptions';
const route = (page, routesMap) => {
const route = (props, page, routesMap) => {
const component = routesMap[page];
return component || DiscoverPage;
if (!component) {
props.doNotify({
message: __('Invalid page requested'),
displayType: ['snackbar'],
});
}
return component || routesMap.discover;
};
const Router = props => {
const { currentPage, params } = props;
return route(currentPage, {
return route(props, currentPage, {
auth: <AuthPage params={params} />,
backup: <BackupPage params={params} />,
channel: <ChannelPage params={params} />,

View file

@ -8,7 +8,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { doConditionalAuthNavigate, doDaemonReady, doAutoUpdate } from 'redux/actions/app';
import { doNotify, doBlackListedOutpointsSubscribe } from 'lbry-redux';
import { doNotify, doBlackListedOutpointsSubscribe, isURIValid } from 'lbry-redux';
import { doNavigate } from 'redux/actions/navigation';
import { doDownloadLanguages, doUpdateIsNightAsync } from 'redux/actions/settings';
import { doUserEmailVerify } from 'redux/actions/user';
@ -19,6 +19,7 @@ import analytics from './analytics';
import { initContextMenu } from './util/contextMenu';
const { autoUpdater } = remote.require('electron-updater');
const APPPAGEURL = 'lbry://?';
autoUpdater.logger = remote.require('electron-log');
@ -42,8 +43,18 @@ ipcRenderer.on('open-uri-requested', (event, uri, newSession) => {
})
);
}
} else {
} else if (uri.startsWith(APPPAGEURL)) {
const navpage = uri.replace(APPPAGEURL, '').toLowerCase();
app.store.dispatch(doNavigate(`/${navpage}`));
} else if (isURIValid(uri)) {
app.store.dispatch(doNavigate('/show', { uri }));
} else {
app.store.dispatch(
doNotify({
message: __('Invalid LBRY URL requested'),
displayType: ['snackbar'],
})
);
}
}
});