From 2bb5f9acc6dcf22db820812bcd8c239584362c7d Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Fri, 26 May 2017 22:36:18 +0400 Subject: [PATCH] Fix playing videos that were deleted and require no cost info --- ui/js/actions/content.js | 21 +++++++++------------ ui/js/component/video/view.jsx | 4 +++- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index 023a3c65a..e09bd5ea1 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -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)) diff --git a/ui/js/component/video/view.jsx b/ui/js/component/video/view.jsx index 081396cab..0bf7dc0bb 100644 --- a/ui/js/component/video/view.jsx +++ b/ui/js/component/video/view.jsx @@ -43,9 +43,11 @@ class VideoPlayButton extends React.Component { } */ + const disabled = isLoading || fileInfo === undefined || (fileInfo === null && (!costInfo || costInfo.cost === undefined)) + return (