2017-04-28 17:14:44 +02:00
|
|
|
import * as types from 'constants/action_types'
|
|
|
|
import lbry from 'lbry'
|
2017-05-19 01:14:26 +02:00
|
|
|
import {
|
2017-05-28 15:01:11 +02:00
|
|
|
doFetchClaimListMine
|
2017-05-19 01:14:26 +02:00
|
|
|
} from 'actions/content'
|
2017-04-28 17:14:44 +02:00
|
|
|
import {
|
2017-05-15 05:50:59 +02:00
|
|
|
selectClaimsByUri,
|
2017-05-19 01:14:26 +02:00
|
|
|
selectClaimListMineIsPending,
|
2017-04-28 17:14:44 +02:00
|
|
|
} from 'selectors/claims'
|
2017-05-15 05:50:59 +02:00
|
|
|
import {
|
2017-05-19 01:14:26 +02:00
|
|
|
selectFileListIsPending,
|
2017-05-18 19:58:28 +02:00
|
|
|
selectAllFileInfos,
|
2017-05-19 01:14:26 +02:00
|
|
|
selectUrisLoading,
|
2017-05-15 05:50:59 +02:00
|
|
|
} from 'selectors/file_info'
|
2017-04-29 19:02:25 +02:00
|
|
|
import {
|
|
|
|
doCloseModal,
|
|
|
|
} from 'actions/app'
|
|
|
|
|
|
|
|
const {
|
|
|
|
shell,
|
|
|
|
} = require('electron')
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
export function doFetchFileInfo(uri) {
|
2017-04-28 17:14:44 +02:00
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState()
|
2017-05-15 05:50:59 +02:00
|
|
|
const claim = selectClaimsByUri(state)[uri]
|
|
|
|
const outpoint = claim ? `${claim.txid}:${claim.nout}` : null
|
2017-05-19 01:14:26 +02:00
|
|
|
const alreadyFetching = !!selectUrisLoading(state)[uri]
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
if (!alreadyFetching) {
|
2017-04-28 17:14:44 +02:00
|
|
|
dispatch({
|
2017-05-15 05:50:59 +02:00
|
|
|
type: types.FETCH_FILE_INFO_STARTED,
|
2017-04-28 17:14:44 +02:00
|
|
|
data: {
|
2017-05-15 05:50:59 +02:00
|
|
|
outpoint,
|
2017-04-28 17:14:44 +02:00
|
|
|
}
|
|
|
|
})
|
2017-05-15 05:50:59 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
lbry.file_list({outpoint: outpoint, full_status: true}).then(fileInfos => {
|
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_FILE_INFO_COMPLETED,
|
|
|
|
data: {
|
2017-05-18 19:58:28 +02:00
|
|
|
outpoint,
|
2017-05-19 01:14:26 +02:00
|
|
|
fileInfo: fileInfos && fileInfos.length ? fileInfos[0] : null,
|
2017-05-15 05:50:59 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2017-04-28 17:14:44 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export function doFileList() {
|
2017-05-18 19:58:28 +02:00
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState()
|
2017-05-19 01:14:26 +02:00
|
|
|
const isPending = selectFileListIsPending(state)
|
2017-05-18 19:58:28 +02:00
|
|
|
|
|
|
|
if (!isPending) {
|
|
|
|
dispatch({
|
|
|
|
type: types.FILE_LIST_STARTED,
|
|
|
|
})
|
|
|
|
|
|
|
|
lbry.file_list().then((fileInfos) => {
|
|
|
|
dispatch({
|
|
|
|
type: types.FILE_LIST_COMPLETED,
|
|
|
|
data: {
|
|
|
|
fileInfos,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-29 19:02:25 +02:00
|
|
|
export function doOpenFileInShell(fileInfo) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
shell.openItem(fileInfo.download_path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doOpenFileInFolder(fileInfo) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
shell.showItemInFolder(fileInfo.download_path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
export function doDeleteFile(outpoint, deleteFromComputer) {
|
2017-04-29 19:02:25 +02:00
|
|
|
return function(dispatch, getState) {
|
2017-05-19 01:14:26 +02:00
|
|
|
|
2017-04-29 19:02:25 +02:00
|
|
|
dispatch({
|
2017-05-19 01:14:26 +02:00
|
|
|
type: types.FILE_DELETE,
|
2017-04-29 19:02:25 +02:00
|
|
|
data: {
|
2017-05-19 01:14:26 +02:00
|
|
|
outpoint
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
lbry.file_delete({
|
|
|
|
outpoint: outpoint,
|
|
|
|
delete_target_file: deleteFromComputer,
|
2017-04-30 18:01:43 +02:00
|
|
|
})
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
dispatch(doCloseModal())
|
2017-04-30 18:01:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
|
|
|
|
export function doFetchFileInfosAndPublishedClaims() {
|
2017-05-18 19:58:28 +02:00
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState(),
|
2017-05-19 01:14:26 +02:00
|
|
|
isClaimListMinePending = selectClaimListMineIsPending(state),
|
|
|
|
isFileInfoListPending = selectFileListIsPending(state)
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
if (isClaimListMinePending === undefined) {
|
2017-05-28 15:01:11 +02:00
|
|
|
dispatch(doFetchClaimListMine())
|
2017-05-19 01:14:26 +02:00
|
|
|
}
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
if (isFileInfoListPending === undefined) {
|
|
|
|
dispatch(doFileList())
|
|
|
|
}
|
2017-05-18 19:58:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|