From d23d06646ef5b4e8eeacebf9735842a2f236f0cd Mon Sep 17 00:00:00 2001 From: zxawry Date: Thu, 4 Jul 2019 12:05:21 +0100 Subject: [PATCH 1/3] fix wunderbar search suggestions --- src/ui/component/wunderbar/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ui/component/wunderbar/index.js b/src/ui/component/wunderbar/index.js index c94b34381..9e4c9fc92 100644 --- a/src/ui/component/wunderbar/index.js +++ b/src/ui/component/wunderbar/index.js @@ -3,12 +3,10 @@ import { doFocusSearchInput, doBlurSearchInput, doUpdateSearchQuery, - doSearch, doToast, selectSearchValue, selectSearchSuggestions, selectSearchBarFocused, - parseURI, } from 'lbry-redux'; import analytics from 'analytics'; import Wunderbar from './view'; @@ -24,6 +22,7 @@ const select = state => ({ const perform = (dispatch, ownProps) => ({ onSearch: query => { ownProps.history.push({ pathname: `/$/search`, search: `?q=${encodeURIComponent(query)}` }); + dispatch(doUpdateSearchQuery(query)); analytics.apiLogSearch(); }, onSubmit: uri => { From e43ad2ce89c761e9d4e38077c36179f50af5955d Mon Sep 17 00:00:00 2001 From: zxawry Date: Thu, 4 Jul 2019 12:15:40 +0100 Subject: [PATCH 2/3] add method to format path for web to util --- .../modal/modalAutoGenerateThumbnail/view.jsx | 8 +-- .../modal/modalOpenExternalResource/view.jsx | 67 +++++++++---------- src/ui/util/uri.js | 33 +++++++++ 3 files changed, 68 insertions(+), 40 deletions(-) diff --git a/src/ui/modal/modalAutoGenerateThumbnail/view.jsx b/src/ui/modal/modalAutoGenerateThumbnail/view.jsx index b8e847177..b6279999f 100644 --- a/src/ui/modal/modalAutoGenerateThumbnail/view.jsx +++ b/src/ui/modal/modalAutoGenerateThumbnail/view.jsx @@ -1,6 +1,7 @@ // @flow import React, { useRef } from 'react'; import { Modal } from 'modal/modal'; +import { formatPathForWeb } from 'util/uri'; type Props = { upload: Buffer => void, @@ -12,10 +13,7 @@ type Props = { function ModalAutoGenerateThumbnail(props: Props) { const { closeModal, filePath, upload, showToast } = props; const playerRef = useRef(); - - let src = filePath.replace(/\\/g, '/'); - src = src[0] !== '/' ? `/${src}` : src; - src = encodeURI(`file://${src}`).replace(/[?#]/g, encodeURIComponent); + const videoSrc = formatPathForWeb(filePath); function uploadImage() { const imageBuffer = captureSnapshot(); @@ -73,7 +71,7 @@ function ModalAutoGenerateThumbnail(props: Props) { >

{__('Pause at any time to select a thumbnail from your video')}.

-
); diff --git a/src/ui/modal/modalOpenExternalResource/view.jsx b/src/ui/modal/modalOpenExternalResource/view.jsx index d1ba71ac0..a2438611d 100644 --- a/src/ui/modal/modalOpenExternalResource/view.jsx +++ b/src/ui/modal/modalOpenExternalResource/view.jsx @@ -1,20 +1,27 @@ // @flow import React from 'react'; import { Modal } from 'modal/modal'; -import { formatLbryUriForWeb } from 'util/uri'; +import { formatPathForWeb } from 'util/uri'; // @if TARGET='app' import { shell } from 'electron'; // @endif type Props = { uri: string, + isTrusted: boolean, path: string, + isMine: boolean, closeModal: () => void, }; -class ModalOpenExternalResource extends React.PureComponent { - openExternalResource() { - const { uri, path, closeModal } = this.props; +function ModalOpenExternalResource(props: Props) { + const { uri, isTrusted, path, isMine, closeModal } = props; + + if ((uri && isTrusted) || (path && isMine)) { + openResource(); + } + + function openResource() { // @if TARGET='app' const { openExternal, openItem, showItemInFolder } = shell; if (uri) { @@ -30,43 +37,33 @@ class ModalOpenExternalResource extends React.PureComponent { if (uri) { window.open(uri); } else if (path) { - // Converintg path into uri, like "file://path/to/file" - let _uri = path.replace(/\\/g, '/'); - // Windows drive letter must be prefixed with a slash - if (_uri[0] !== '/') { - _uri = `/${_uri}`; - } - _uri = encodeURI(`file://${_uri}`).replace(/[?#]/g, encodeURIComponent); - window.open(_uri); + window.open(formatPathForWeb(path)); } // @endif closeModal(); } - render() { - const { uri, path, closeModal } = this.props; - return ( - this.openExternalResource()} - onAborted={closeModal} - > -
-

- {(uri && __('This link leads to an external website.')) || - (path && __('This file has been shared with you by other people.'))} -

-
{uri || path}
-

{__('LBRY Inc is not responsible for its content, click continue to proceed at your own risk.')}

-
-
- ); - } + return ( + openResource()} + onAborted={closeModal} + > +
+

+ {(uri && __('This link leads to an external website.')) || + (path && __('This file has been shared with you by other people.'))} +

+
{uri || path}
+

{__('LBRY Inc is not responsible for its content, click continue to proceed at your own risk.')}

+
+
+ ); } export default ModalOpenExternalResource; diff --git a/src/ui/util/uri.js b/src/ui/util/uri.js index 6d8818e55..70d20d765 100644 --- a/src/ui/util/uri.js +++ b/src/ui/util/uri.js @@ -1,6 +1,8 @@ // @flow import { parseURI } from 'lbry-redux'; +const LBRY_INC_DOMAINS = ['lbry.io', 'lbry.com', 'lbry.tv', 'lbry.tech', 'lbry.fund', 'spee.ch']; + export const formatLbryUriForWeb = (uri: string) => { const { claimName, claimId } = parseURI(uri); @@ -11,3 +13,34 @@ export const formatLbryUriForWeb = (uri: string) => { return webUrl; }; + +export const formatPathForWeb = (path: string) => { + if (!path) { + return; + } + + let webUrl = path.replace(/\\/g, '/'); + + if (webUrl[0] !== '/') { + webUrl = `/${webUrl}`; + } + + return encodeURI(`file://${webUrl}`).replace(/[?#]/g, encodeURIComponent); +}; + +export const isLBRYDomain = (uri: string) => { + if (!uri) { + return; + } + + const myURL = new URL(uri); + const hostname = myURL.hostname; + + for (let domain of LBRY_INC_DOMAINS) { + if (hostname.endsWith(domain)) { + return true; + } + } + + return false; +}; From ca1c95b0936a7dff47c85ee1e466b3c748008dd6 Mon Sep 17 00:00:00 2001 From: zxawry Date: Thu, 4 Jul 2019 12:23:22 +0100 Subject: [PATCH 3/3] do not show warning on own claims and lbry related links --- src/ui/component/externalLink/view.jsx | 6 +++++- src/ui/component/fileDownloadLink/index.js | 2 ++ src/ui/component/fileDownloadLink/view.jsx | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ui/component/externalLink/view.jsx b/src/ui/component/externalLink/view.jsx index 23d34f90d..fcf5cbf4b 100644 --- a/src/ui/component/externalLink/view.jsx +++ b/src/ui/component/externalLink/view.jsx @@ -5,6 +5,7 @@ import * as React from 'react'; import { isURIValid } from 'lbry-redux'; import Button from 'component/button'; import ClaimLink from 'component/claimLink'; +import { isLBRYDomain } from 'util/uri'; type Props = { href: string, @@ -37,7 +38,10 @@ class ExternalLink extends React.PureComponent { title={title || href} label={children} className="button--external-link" - onClick={() => openModal(MODALS.CONFIRM_EXTERNAL_RESOURCE, { uri: href })} + onClick={() => { + const isTrusted = isLBRYDomain(href); + openModal(MODALS.CONFIRM_EXTERNAL_RESOURCE, { uri: href, isTrusted: isTrusted }); + }} /> ); } diff --git a/src/ui/component/fileDownloadLink/index.js b/src/ui/component/fileDownloadLink/index.js index b511885bc..719a6debd 100644 --- a/src/ui/component/fileDownloadLink/index.js +++ b/src/ui/component/fileDownloadLink/index.js @@ -4,6 +4,7 @@ import { makeSelectDownloadingForUri, makeSelectLoadingForUri, makeSelectClaimForUri, + makeSelectClaimIsMine, } from 'lbry-redux'; import { makeSelectCostInfoForUri } from 'lbryinc'; import { doOpenModal } from 'redux/actions/app'; @@ -17,6 +18,7 @@ const select = (state, props) => ({ costInfo: makeSelectCostInfoForUri(props.uri)(state), loading: makeSelectLoadingForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state), + claimIsMine: makeSelectClaimIsMine(props.uri)(state), }); const perform = dispatch => ({ diff --git a/src/ui/component/fileDownloadLink/view.jsx b/src/ui/component/fileDownloadLink/view.jsx index 307e6a5c7..35c1ab359 100644 --- a/src/ui/component/fileDownloadLink/view.jsx +++ b/src/ui/component/fileDownloadLink/view.jsx @@ -8,6 +8,7 @@ import analytics from 'analytics'; type Props = { claim: StreamClaim, + claimIsMine: boolean, uri: string, downloading: boolean, fileInfo: ?{ @@ -44,7 +45,18 @@ class FileDownloadLink extends React.PureComponent { uri: ?string; render() { - const { fileInfo, downloading, uri, openModal, purchaseUri, costInfo, loading, pause, claim } = this.props; + const { + fileInfo, + downloading, + uri, + openModal, + purchaseUri, + costInfo, + loading, + pause, + claim, + claimIsMine, + } = this.props; if (loading || downloading) { const progress = fileInfo && fileInfo.written_bytes ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0; @@ -81,7 +93,7 @@ class FileDownloadLink extends React.PureComponent { icon={ICONS.EXTERNAL} onClick={() => { pause(); - openModal(MODALS.CONFIRM_EXTERNAL_RESOURCE, { path: fileInfo.download_path }); + openModal(MODALS.CONFIRM_EXTERNAL_RESOURCE, { path: fileInfo.download_path, isMine: claimIsMine }); }} />