Add fileinfo to action data when download starts

This commit is contained in:
6ea86b96 2017-04-27 22:10:39 +07:00 committed by Jeremy Kauffman
parent 3981ca8381
commit 3fd48810f1
2 changed files with 19 additions and 8 deletions

View file

@ -223,11 +223,14 @@ export function doDownloadFile(uri, streamInfo) {
return function(dispatch, getState) {
const state = getState()
dispatch({
type: types.DOWNLOADING_STARTED,
data: {
uri,
}
lbry.file_list({ outpoint: streamInfo.outpoint, full_status: true }).then(([fileInfo]) => {
dispatch({
type: types.DOWNLOADING_STARTED,
data: {
uri,
fileInfo,
}
})
})
lbryio.call('file', 'view', {
@ -281,11 +284,13 @@ export function doWatchVideo() {
return Promise.resolve()
}
if (cost <= 0.01 || fileInfo.download_directory) {
dispatch(doLoadVideo())
return Promise.resolve()
}
if (cost > balance) {
dispatch(doOpenModal('notEnoughCredits'))
}
else if (cost <= 0.01 || fileInfo.written_bytes > 0) {
dispatch(doLoadVideo())
} else {
dispatch(doOpenModal('affirmPurchase'))
}

View file

@ -211,20 +211,26 @@ reducers[types.LOADING_VIDEO_FAILED] = function(state, action) {
reducers[types.DOWNLOADING_STARTED] = function(state, action) {
const {
uri,
fileInfo,
} = action.data
const newDownloading = Object.assign({}, state.downloading)
const newByUri = Object.assign({}, newDownloading.byUri)
const newLoading = Object.assign({}, state.loading)
const newLoadingByUri = Object.assign({}, newLoading.byUri)
const newFileInfos = Object.assign({}, state.fileInfos)
const newFileInfosByUri = Object.assign({}, newFileInfos.byUri)
newByUri[uri] = true
newDownloading.byUri = newByUri
delete newLoadingByUri[uri]
newLoading.byUri = newLoadingByUri
newFileInfosByUri[uri] = fileInfo
newFileInfos.byUri = newFileInfosByUri
return Object.assign({}, state, {
downloading: newDownloading,
loading: newLoading,
fileInfos: newFileInfos,
})
}