2017-12-21 18:32:51 +01:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
|
|
|
import Lbry from 'lbry';
|
|
|
|
import { doFetchClaimListMine, doAbandonClaim } from 'redux/actions/content';
|
2017-04-28 17:14:44 +02:00
|
|
|
import {
|
2017-05-15 05:50:59 +02:00
|
|
|
selectClaimsByUri,
|
2017-07-04 13:05:35 +02:00
|
|
|
selectIsFetchingClaimListMine,
|
2017-06-29 09:44:34 +02:00
|
|
|
selectMyClaimsOutpoints,
|
2017-12-21 18:32:51 +01:00
|
|
|
} from 'redux/selectors/claims';
|
2017-05-15 05:50:59 +02:00
|
|
|
import {
|
2017-07-04 13:05:35 +02:00
|
|
|
selectIsFetchingFileList,
|
2017-06-29 09:44:34 +02:00
|
|
|
selectFileInfosByOutpoint,
|
2017-05-19 01:14:26 +02:00
|
|
|
selectUrisLoading,
|
2017-07-21 10:13:45 +02:00
|
|
|
selectTotalDownloadProgress,
|
2017-12-21 18:32:51 +01:00
|
|
|
} from 'redux/selectors/file_info';
|
|
|
|
import { doCloseModal } from 'redux/actions/app';
|
|
|
|
import { doHistoryBack } from 'redux/actions/navigation';
|
|
|
|
import setProgressBar from 'util/setProgressBar';
|
|
|
|
import batchActions from 'util/batchActions';
|
|
|
|
import { shell } from '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) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
|
|
|
const claim = selectClaimsByUri(state)[uri];
|
|
|
|
const outpoint = claim ? `${claim.txid}:${claim.nout}` : null;
|
|
|
|
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-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_FILE_INFO_STARTED,
|
2017-04-28 17:14:44 +02:00
|
|
|
data: {
|
2017-05-15 05:50:59 +02:00
|
|
|
outpoint,
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.file_list({ outpoint, full_status: true }).then(fileInfos => {
|
2017-12-13 22:36:30 +01:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FETCH_FILE_INFO_COMPLETED,
|
2017-12-13 22:36:30 +01:00
|
|
|
data: {
|
|
|
|
outpoint,
|
|
|
|
fileInfo: fileInfos && fileInfos.length ? fileInfos[0] : null,
|
|
|
|
},
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-12-13 22:36:30 +01:00
|
|
|
});
|
2017-05-15 05:50:59 +02:00
|
|
|
}
|
2017-06-06 23:19:12 +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) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
2017-07-04 13:05:35 +02:00
|
|
|
const isFetching = selectIsFetchingFileList(state);
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-07-04 13:05:35 +02:00
|
|
|
if (!isFetching) {
|
2017-05-18 19:58:28 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FILE_LIST_STARTED,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.file_list().then(fileInfos => {
|
2017-05-18 19:58:28 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FILE_LIST_SUCCEEDED,
|
2017-05-18 19:58:28 +02:00
|
|
|
data: {
|
|
|
|
fileInfos,
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2017-05-18 19:58:28 +02:00
|
|
|
}
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-05-18 19:58:28 +02:00
|
|
|
}
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export function doOpenFileInFolder(path) {
|
|
|
|
return function() {
|
|
|
|
shell.showItemInFolder(path);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-20 14:47:08 +02:00
|
|
|
export function doOpenFileInShell(path) {
|
2017-12-21 18:32:51 +01:00
|
|
|
return function(dispatch) {
|
2017-09-20 14:47:08 +02:00
|
|
|
const success = shell.openItem(path);
|
2017-08-07 01:18:38 +02:00
|
|
|
if (!success) {
|
2017-09-20 14:47:08 +02:00
|
|
|
dispatch(doOpenFileInFolder(path));
|
2017-08-07 01:18:38 +02:00
|
|
|
}
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-29 19:02:25 +02:00
|
|
|
}
|
|
|
|
|
2017-06-29 09:44:34 +02:00
|
|
|
export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim) {
|
2017-04-29 19:02:25 +02:00
|
|
|
return function(dispatch, getState) {
|
2017-06-29 09:44:34 +02:00
|
|
|
const state = getState();
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Lbry.file_delete({
|
2017-12-13 22:36:30 +01:00
|
|
|
outpoint,
|
2017-06-29 09:44:34 +02:00
|
|
|
delete_from_download_dir: deleteFromComputer,
|
|
|
|
});
|
|
|
|
|
|
|
|
// If the file is for a claim we published then also abandom the claim
|
|
|
|
const myClaimsOutpoints = selectMyClaimsOutpoints(state);
|
|
|
|
if (abandonClaim && myClaimsOutpoints.indexOf(outpoint) !== -1) {
|
|
|
|
const byOutpoint = selectFileInfosByOutpoint(state);
|
|
|
|
const fileInfo = byOutpoint[outpoint];
|
|
|
|
|
|
|
|
if (fileInfo) {
|
2017-12-05 15:45:35 +01:00
|
|
|
const txid = fileInfo.outpoint.slice(0, -2);
|
2017-12-11 08:21:18 +01:00
|
|
|
const nout = Number(fileInfo.outpoint.slice(-1));
|
2017-10-24 15:10:27 +02:00
|
|
|
|
2017-11-01 21:23:30 +01:00
|
|
|
dispatch(doAbandonClaim(txid, nout));
|
2017-06-29 09:44:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-29 19:02:25 +02:00
|
|
|
dispatch({
|
2017-12-21 18:32:51 +01:00
|
|
|
type: ACTIONS.FILE_DELETE,
|
2017-04-29 19:02:25 +02:00
|
|
|
data: {
|
2017-06-06 23:19:12 +02:00
|
|
|
outpoint,
|
|
|
|
},
|
|
|
|
});
|
2017-04-29 19:02:25 +02:00
|
|
|
|
2017-07-21 10:13:45 +02:00
|
|
|
const totalProgress = selectTotalDownloadProgress(getState());
|
|
|
|
setProgressBar(totalProgress);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export function doDeleteFileAndGoBack(fileInfo, deleteFromComputer, abandonClaim) {
|
|
|
|
return function(dispatch) {
|
2017-07-21 10:13:45 +02:00
|
|
|
const actions = [];
|
|
|
|
actions.push(doCloseModal());
|
|
|
|
actions.push(doHistoryBack());
|
|
|
|
actions.push(doDeleteFile(fileInfo, deleteFromComputer, abandonClaim));
|
|
|
|
dispatch(batchActions(...actions));
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
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) {
|
2017-12-21 18:32:51 +01:00
|
|
|
const state = getState();
|
|
|
|
const isFetchingClaimListMine = selectIsFetchingClaimListMine(state);
|
|
|
|
const isFetchingFileInfo = selectIsFetchingFileList(state);
|
2017-05-18 19:58:28 +02:00
|
|
|
|
2017-07-04 13:05:35 +02:00
|
|
|
if (!isFetchingClaimListMine) dispatch(doFetchClaimListMine());
|
|
|
|
if (!isFetchingFileInfo) dispatch(doFileList());
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-05-18 19:58:28 +02:00
|
|
|
}
|