Fix playing videos that were deleted and require no cost info

This commit is contained in:
6ea86b96 2017-05-26 22:36:18 +04:00
parent d878d3b693
commit 2bb5f9acc6
2 changed files with 12 additions and 13 deletions

View file

@ -214,22 +214,16 @@ export function doPurchaseUri(uri) {
const state = getState()
const balance = selectBalance(state)
const fileInfo = selectFileInfoForUri(state, { uri })
const costInfo = selectCostInfoForUri(state, { uri })
const downloadingByUri = selectUrisDownloading(state)
const alreadyDownloading = !!downloadingByUri[uri]
const { cost } = costInfo
// BUG if you delete a file from the file system system you're going to be
// asked to pay for it again. We need to check if the file is in the blobs
// here and then dispatch doLoadVideo() which will reconstruct it again from
// the blobs. Or perhaps there's another way to see if a file was already
// purchased?
// we already fully downloaded the file.
if (fileInfo && fileInfo.completed) {
// If written_bytes is false that means the user has deleted/moved the
// file manually on their file system, so we need to dispatch a
// doLoadVideo action to reconstruct the file from the blobs
if (!fileInfo.written_bytes) dispatch(doLoadVideo(uri))
// we already fully downloaded the file. If completed is true but
// writtenBytes is false then we downloaded it before but deleted it again,
// which means it needs to be reconstructed from the blobs by dispatching
// doLoadVideo.
if (fileInfo && fileInfo.completed && !!fileInfo.writtenBytes) {
return Promise.resolve()
}
@ -238,6 +232,9 @@ export function doPurchaseUri(uri) {
return Promise.resolve()
}
const costInfo = selectCostInfoForUri(state, { uri })
const { cost } = costInfo
// the file is free or we have partially downloaded it
if (cost <= 0.01 || (fileInfo && fileInfo.download_directory)) {
dispatch(doLoadVideo(uri))

View file

@ -43,9 +43,11 @@ class VideoPlayButton extends React.Component {
}
*/
const disabled = isLoading || fileInfo === undefined || (fileInfo === null && (!costInfo || costInfo.cost === undefined))
return (<div>
<Link button={ button ? button : null }
disabled={isLoading || fileInfo === undefined || (fileInfo === null && (!costInfo || costInfo.cost === undefined))}
disabled={disabled}
label={label ? label : ""}
className="video__play-button"
icon="icon-play"