fix paid content - thanks tom
This commit is contained in:
parent
f25559adfb
commit
cd3edca074
9 changed files with 56 additions and 101 deletions
|
@ -125,7 +125,7 @@
|
|||
"jsmediatags": "^3.8.1",
|
||||
"json-loader": "^0.5.4",
|
||||
"lbry-format": "https://github.com/lbryio/lbry-format.git",
|
||||
"lbry-redux": "lbryio/lbry-redux#1b7bb1cc9f2cb6a8efcce1869031d4da8ddbf4ca",
|
||||
"lbry-redux": "lbryio/lbry-redux#66f70c7745d23e79f9e8ec9ca32ef9d3a576688e",
|
||||
"lbryinc": "lbryio/lbryinc#a93596c51c8fb0a226cb84df04c26a6bb60a45fb",
|
||||
"lint-staged": "^7.0.2",
|
||||
"localforage": "^1.7.1",
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
// @flow
|
||||
import type { ElementRef } from 'react';
|
||||
import * as MODALS from 'constants/modal_types';
|
||||
import * as ICONS from 'constants/icons';
|
||||
import React from 'react';
|
||||
import Button from 'component/button';
|
||||
import Tooltip from 'component/common/tooltip';
|
||||
import { requestFullscreen, fullscreenElement } from 'util/full-screen';
|
||||
|
||||
type FileInfo = {
|
||||
claim_id: string,
|
||||
|
@ -17,37 +15,17 @@ type Props = {
|
|||
openModal: (id: string, { uri: string }) => void,
|
||||
claimIsMine: boolean,
|
||||
fileInfo: FileInfo,
|
||||
viewerContainer: { current: ElementRef<any> },
|
||||
showFullscreen: boolean,
|
||||
};
|
||||
|
||||
class FileActions extends React.PureComponent<Props> {
|
||||
maximizeViewer = () => {
|
||||
const { viewerContainer } = this.props;
|
||||
const isFullscreen = fullscreenElement();
|
||||
// Request fullscreen if viewer is ready
|
||||
// And if there is no fullscreen element active
|
||||
if (!isFullscreen && viewerContainer && viewerContainer.current !== null) {
|
||||
requestFullscreen(viewerContainer.current);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { fileInfo, uri, openModal, claimIsMine, claimId, showFullscreen } = this.props;
|
||||
const { fileInfo, uri, openModal, claimIsMine, claimId } = this.props;
|
||||
const showDelete = claimIsMine || (fileInfo && Object.keys(fileInfo).length > 0);
|
||||
// fix me
|
||||
// const showDelete = claimIsMine || (fileInfo && fileInfo.writtenBytes > 0 || fileInfo.blobs_completed;
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
{showFullscreen && (
|
||||
<Tooltip label={__('Full screen (f)')}>
|
||||
<Button
|
||||
button="link"
|
||||
description={__('Fullscreen')}
|
||||
icon={ICONS.FULLSCREEN}
|
||||
onClick={this.maximizeViewer}
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
{showDelete && (
|
||||
<Tooltip label={__('Remove from your library')}>
|
||||
<Button
|
||||
|
|
|
@ -21,7 +21,7 @@ const select = (state, props) => ({
|
|||
});
|
||||
|
||||
const perform = dispatch => ({
|
||||
play: (uri, saveFile) => dispatch(doPlayUri(uri, saveFile)),
|
||||
play: uri => dispatch(doPlayUri(uri)),
|
||||
});
|
||||
|
||||
export default connect(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { doSetPlayingUri } from 'redux/actions/content';
|
||||
import { doSetPlayingUri, doPlayUri } from 'redux/actions/content';
|
||||
import { doHideModal } from 'redux/actions/app';
|
||||
import { makeSelectMetadataForUri } from 'lbry-redux';
|
||||
import ModalAffirmPurchase from './view';
|
||||
|
@ -14,9 +14,7 @@ const perform = dispatch => ({
|
|||
dispatch(doHideModal());
|
||||
},
|
||||
closeModal: () => dispatch(doHideModal()),
|
||||
loadVideo: uri => {
|
||||
throw Error('sean you need to fix this');
|
||||
},
|
||||
loadVideo: uri => dispatch(doPlayUri(uri, true)),
|
||||
});
|
||||
|
||||
export default connect(
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import * as MODALS from 'constants/modal_types';
|
||||
import * as icons from 'constants/icons';
|
||||
import * as React from 'react';
|
||||
import { Lbry, buildURI, normalizeURI } from 'lbry-redux';
|
||||
import { buildURI, normalizeURI } from 'lbry-redux';
|
||||
import FileViewer from 'component/fileViewer';
|
||||
import FilePrice from 'component/filePrice';
|
||||
import FileDetails from 'component/fileDetails';
|
||||
|
@ -35,7 +35,7 @@ type Props = {
|
|||
channelUri: string,
|
||||
viewCount: number,
|
||||
prepareEdit: ({}, string, {}) => void,
|
||||
openModal: (id: string, { [key: string]: any }) => void,
|
||||
openModal: (id: string, { uri: string, claimIsMine?: boolean, isSupport?: boolean }) => void,
|
||||
markSubscriptionRead: (string, string) => void,
|
||||
fetchViewCount: string => void,
|
||||
balance: number,
|
||||
|
@ -45,15 +45,6 @@ type Props = {
|
|||
};
|
||||
|
||||
class FilePage extends React.Component<Props> {
|
||||
static PREVIEW_MEDIA_TYPES = ['text', 'model', 'image', 'script', 'document', '3D-file', 'comic-book'];
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
(this: any).viewerContainer = React.createRef();
|
||||
}
|
||||
|
||||
viewerContainer: { current: React.ElementRef<any> };
|
||||
|
||||
componentDidMount() {
|
||||
const {
|
||||
uri,
|
||||
|
@ -135,12 +126,7 @@ class FilePage extends React.Component<Props> {
|
|||
// File info
|
||||
const { signing_channel: signingChannel } = claim;
|
||||
const channelName = signingChannel && signingChannel.name;
|
||||
const { PREVIEW_MEDIA_TYPES } = FilePage;
|
||||
const isRewardContent = (rewardedContentClaimIds || []).includes(claim.claim_id);
|
||||
const fileName = fileInfo ? fileInfo.file_name : null;
|
||||
const mediaType = Lbry.getMediaType(contentType, fileName);
|
||||
const isPreviewType = PREVIEW_MEDIA_TYPES.includes(mediaType);
|
||||
|
||||
const speechShareable =
|
||||
costInfo && costInfo.cost === 0 && contentType && ['video', 'image', 'audio'].includes(contentType.split('/')[0]);
|
||||
// We want to use the short form uri for editing
|
||||
|
@ -173,7 +159,7 @@ class FilePage extends React.Component<Props> {
|
|||
{__('or send more LBC to your wallet.')}
|
||||
</div>
|
||||
)}
|
||||
<FileViewer uri={uri} viewerContainer={this.viewerContainer} insufficientCredits={insufficientCredits} />
|
||||
<FileViewer uri={uri} insufficientCredits={insufficientCredits} />
|
||||
</div>
|
||||
|
||||
<div className="columns">
|
||||
|
@ -231,12 +217,7 @@ class FilePage extends React.Component<Props> {
|
|||
|
||||
<div className="media__action-group--large">
|
||||
<FileDownloadLink uri={uri} />
|
||||
<FileActions
|
||||
uri={uri}
|
||||
claimId={claim.claim_id}
|
||||
showFullscreen={isPreviewType}
|
||||
viewerContainer={this.viewerContainer}
|
||||
/>
|
||||
<FileActions uri={uri} claimId={claim.claim_id} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -28,7 +28,6 @@ const select = state => ({
|
|||
supportOption: makeSelectClientSetting(settings.SUPPORT_OPTION)(state),
|
||||
userBlockedChannelsCount: selectBlockedChannelsCount(state),
|
||||
hideBalance: makeSelectClientSetting(settings.HIDE_BALANCE)(state),
|
||||
maxConnections: makeSelectClientSetting(settings.MAX_CONNECTIONS)(state),
|
||||
});
|
||||
|
||||
const perform = dispatch => ({
|
||||
|
|
|
@ -78,9 +78,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
|||
componentDidMount() {
|
||||
this.props.getThemes();
|
||||
this.props.updateWalletStatus();
|
||||
|
||||
const { daemonSettings } = this.props;
|
||||
this.props.setClientSetting(SETTINGS.MAX_CONNECTIONS, daemonSettings.max_connections_per_download);
|
||||
}
|
||||
|
||||
onKeyFeeChange(newValue: Price) {
|
||||
|
@ -90,7 +87,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
|||
onMaxConnectionsChange(event: SyntheticInputEvent<*>) {
|
||||
const { value } = event.target;
|
||||
this.setDaemonSetting('max_connections_per_download', value);
|
||||
this.props.setClientSetting(SETTINGS.MAX_CONNECTIONS, value);
|
||||
}
|
||||
|
||||
onKeyFeeDisableChange(isDisabled: boolean) {
|
||||
|
@ -214,7 +210,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
|||
onChange={() => setDaemonSetting('save_files', !daemonSettings.save_files)}
|
||||
checked={daemonSettings.save_files}
|
||||
label={__(
|
||||
'Enables saving of all viewed content to your downloads directory. Some file types are saved by default.'
|
||||
'Enables saving of all viewed content to your downloads directory. Paid content and some file types are saved by default.'
|
||||
)}
|
||||
helper={__('This is not retroactive, only works from the time it was changed.')}
|
||||
/>
|
||||
|
|
|
@ -21,9 +21,10 @@ import {
|
|||
parseURI,
|
||||
doPurchaseUri,
|
||||
makeSelectUriIsStreamable,
|
||||
selectDownloadingByOutpoint,
|
||||
} from 'lbry-redux';
|
||||
import { makeSelectCostInfoForUri } from 'lbryinc';
|
||||
import { makeSelectClientSetting, selectosNotificationsEnabled } from 'redux/selectors/settings';
|
||||
import { makeSelectClientSetting, selectosNotificationsEnabled, selectDaemonSettings } from 'redux/selectors/settings';
|
||||
import { formatLbryUriForWeb } from 'util/uri';
|
||||
|
||||
const DOWNLOAD_POLL_INTERVAL = 250;
|
||||
|
@ -179,64 +180,66 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1, pageSize:
|
|||
};
|
||||
}
|
||||
|
||||
export function doPurchaseUriWrapper(uri: string, costInfo: {}, saveFile: boolean) {
|
||||
export function doPurchaseUriWrapper(uri: string, cost: number, saveFile: boolean) {
|
||||
return (dispatch: Dispatch, getState: () => any) => {
|
||||
const state = getState();
|
||||
const isUriStreamable = makeSelectUriIsStreamable(uri)(state);
|
||||
|
||||
function onSuccess(fileInfo) {
|
||||
dispatch(doUpdateLoadStatus(uri, fileInfo.outpoint));
|
||||
}
|
||||
|
||||
// Only pass the sucess callback for non streamable files because we don't show the download percentage while streaming
|
||||
const successCallBack = isUriStreamable ? undefined : onSuccess;
|
||||
dispatch(doPurchaseUri(uri, costInfo, saveFile, successCallBack));
|
||||
// Only pass the sucess callback if we are saving the file, otherwise we don't show the download percentage
|
||||
const successCallBack = saveFile ? onSuccess : undefined;
|
||||
dispatch(doPurchaseUri(uri, { costInfo: cost }, saveFile, successCallBack));
|
||||
};
|
||||
}
|
||||
|
||||
export function doPlayUri(uri: string, saveFile: boolean) {
|
||||
export function doPlayUri(uri: string, skipCostCheck: boolean = false, saveFileOverride: boolean = false) {
|
||||
return (dispatch: Dispatch, getState: () => any) => {
|
||||
function attemptPlay(cost, instantPurchaseMax = null) {
|
||||
// If you have a file entry with correct manifest, you won't pay for the key fee again
|
||||
if (cost > 0 && (!instantPurchaseMax || cost > instantPurchaseMax) && !fileInfo) {
|
||||
dispatch(doOpenModal(MODALS.AFFIRM_PURCHASE, { uri }));
|
||||
} else {
|
||||
dispatch(doPurchaseUriWrapper(uri, { costInfo: cost }, saveFile));
|
||||
}
|
||||
}
|
||||
|
||||
// Set the active playing uri so we can avoid showing error notifications if a previously started download fails
|
||||
dispatch(doSetPlayingUri(uri));
|
||||
|
||||
const state = getState();
|
||||
const fileInfo = makeSelectFileInfoForUri(uri)(state);
|
||||
const { cost } = makeSelectCostInfoForUri(uri)(state);
|
||||
|
||||
// we already fully downloaded the file.
|
||||
if (fileInfo && fileInfo.completed && (fileInfo.status === 'stopped' || fileInfo.status === 'finished')) {
|
||||
// If path is null or bytes written is 0 means the user has deleted/moved the
|
||||
// file manually on their file system, so we need to dispatch a
|
||||
// doPurchaseUri action to reconstruct the file from the blobs
|
||||
if (!fileInfo.download_path || !fileInfo.written_bytes) {
|
||||
dispatch(doPurchaseUriWrapper(uri, { costInfo: cost }, saveFile));
|
||||
}
|
||||
|
||||
const uriIsStreamable = makeSelectUriIsStreamable(uri)(state);
|
||||
const downloadingByOutpoint = selectDownloadingByOutpoint(state);
|
||||
const alreadyDownloaded = fileInfo && (fileInfo.completed || (fileInfo.blobs_remaining === 0 && uriIsStreamable));
|
||||
const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint];
|
||||
if (alreadyDownloading || alreadyDownloaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cost === 0 || !makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state)) {
|
||||
attemptPlay(cost);
|
||||
} else {
|
||||
const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state);
|
||||
if (instantPurchaseMax.currency === 'LBC') {
|
||||
attemptPlay(cost, instantPurchaseMax.amount);
|
||||
const daemonSettings = selectDaemonSettings(state);
|
||||
const costInfo = makeSelectCostInfoForUri(uri)(state);
|
||||
const cost = Number(costInfo.cost);
|
||||
const saveFile = !uriIsStreamable ? true : daemonSettings.save_files || saveFileOverride || cost > 0;
|
||||
const instantPurchaseEnabled = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state);
|
||||
const instantPurchaseMax = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state);
|
||||
|
||||
function beginGetFile() {
|
||||
dispatch(doPurchaseUriWrapper(uri, cost, saveFile));
|
||||
}
|
||||
|
||||
function attemptPlay(instantPurchaseMax = null) {
|
||||
// If you have a file_list entry, you have already purchased the file
|
||||
if (!fileInfo && (!instantPurchaseMax || cost > instantPurchaseMax)) {
|
||||
dispatch(doOpenModal(MODALS.AFFIRM_PURCHASE, { uri }));
|
||||
} else {
|
||||
// Need to convert currency of instant purchase maximum before trying to play
|
||||
Lbryapi.getExchangeRates().then(({ LBC_USD }) => {
|
||||
attemptPlay(cost, instantPurchaseMax.amount / LBC_USD);
|
||||
});
|
||||
beginGetFile();
|
||||
}
|
||||
}
|
||||
|
||||
if (cost === 0 || skipCostCheck) {
|
||||
beginGetFile();
|
||||
return;
|
||||
}
|
||||
|
||||
if (instantPurchaseEnabled || instantPurchaseMax.currency === 'LBC') {
|
||||
attemptPlay(instantPurchaseMax.amount);
|
||||
} else {
|
||||
// Need to convert currency of instant purchase maximum before trying to play
|
||||
Lbryapi.getExchangeRates().then(({ LBC_USD }) => {
|
||||
attemptPlay(instantPurchaseMax.amount / LBC_USD);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6762,9 +6762,9 @@ lazy-val@^1.0.3, lazy-val@^1.0.4:
|
|||
yargs "^13.2.2"
|
||||
zstd-codec "^0.1.1"
|
||||
|
||||
lbry-redux@lbryio/lbry-redux#1b7bb1cc9f2cb6a8efcce1869031d4da8ddbf4ca:
|
||||
lbry-redux@lbryio/lbry-redux#66f70c7745d23e79f9e8ec9ca32ef9d3a576688e:
|
||||
version "0.0.1"
|
||||
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/1b7bb1cc9f2cb6a8efcce1869031d4da8ddbf4ca"
|
||||
resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/66f70c7745d23e79f9e8ec9ca32ef9d3a576688e"
|
||||
dependencies:
|
||||
mime "^2.4.4"
|
||||
proxy-polyfill "0.1.6"
|
||||
|
|
Loading…
Add table
Reference in a new issue