Merge pull request #87 from lbryio/auto-fetch-images

auto-fetch image and text types
This commit is contained in:
Akinwale Ariwodola 2019-11-25 11:16:28 +01:00 committed by GitHub
commit 13fd9002fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -61,6 +61,7 @@ class FilePage extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
attemptAutoGet: false,
autoPlayMedia: false,
autoDownloadStarted: false,
downloadButtonShown: false,
@ -189,10 +190,12 @@ class FilePage extends React.PureComponent {
const {
claim,
contentType,
costInfo,
fileInfo,
isResolvingUri,
resolveUri,
navigation,
purchaseUri,
searchRecommended,
title,
} = this.props;
@ -214,6 +217,21 @@ class FilePage extends React.PureComponent {
uri: this.state.uri,
};
}
// attempt to retrieve images and html/text automatically once the claim is loaded, and it's free
const mediaType = Lbry.getMediaType(contentType);
const isViewable = mediaType === 'image' || mediaType === 'text';
if (claim && costInfo && costInfo.cost === 0 && !this.state.autoGetAttempted && isViewable) {
this.setState(
{
autoGetAttempted: true,
downloadPressed: true,
autoPlayMedia: true,
stopDownloadConfirmed: false,
},
() => purchaseUri(claim.permanent_url, costInfo, true)
);
}
}
fetchFileInfo(props) {