lbry-desktop/src/renderer/redux/actions/file.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

import * as ACTIONS from 'constants/action_types';
import { shell } from 'electron';
2017-04-28 22:14:44 +07:00
import {
2018-04-18 00:03:01 -04:00
Lbry,
batchActions,
doAbandonClaim,
selectMyClaimsOutpoints,
selectFileInfosByOutpoint,
selectTotalDownloadProgress,
2018-04-18 00:03:01 -04:00
} from 'lbry-redux';
import { doCloseModal } from 'redux/actions/app';
import { doHistoryBack } from 'redux/actions/navigation';
import setProgressBar from 'util/setProgressBar';
2017-04-28 22:14:44 +07:00
export function doOpenFileInFolder(path) {
return () => {
shell.showItemInFolder(path);
};
}
export function doOpenFileInShell(path) {
return dispatch => {
const success = shell.openItem(path);
if (!success) {
dispatch(doOpenFileInFolder(path));
}
2017-06-06 17:19:12 -04:00
};
}
export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim) {
return (dispatch, getState) => {
const state = getState();
Lbry.file_delete({
2017-12-13 18:36:30 -03:00
outpoint,
delete_from_download_dir: deleteFromComputer,
});
// If the file is for a claim we published then also abandon 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 20:15:35 +05:30
const txid = fileInfo.outpoint.slice(0, -2);
2017-12-11 12:51:18 +05:30
const nout = Number(fileInfo.outpoint.slice(-1));
2017-10-24 18:40:27 +05:30
2017-11-02 01:53:30 +05:30
dispatch(doAbandonClaim(txid, nout));
}
}
dispatch({
type: ACTIONS.FILE_DELETE,
data: {
2017-06-06 17:19:12 -04:00
outpoint,
},
});
const totalProgress = selectTotalDownloadProgress(getState());
setProgressBar(totalProgress);
};
}
export function doDeleteFileAndGoBack(fileInfo, deleteFromComputer, abandonClaim) {
return dispatch => {
const actions = [];
actions.push(doCloseModal());
actions.push(doHistoryBack());
actions.push(doDeleteFile(fileInfo, deleteFromComputer, abandonClaim));
dispatch(batchActions(...actions));
2017-06-06 17:19:12 -04:00
};
}