2017-12-21 18:32:51 +01:00
|
|
|
import * as ACTIONS from 'constants/action_types';
|
2019-03-05 05:46:57 +01:00
|
|
|
// @if TARGET='app'
|
2017-12-28 00:48:11 +01:00
|
|
|
import { shell } from 'electron';
|
2019-03-05 05:46:57 +01:00
|
|
|
// @endif
|
2019-10-01 15:44:37 +02:00
|
|
|
import {
|
|
|
|
Lbry,
|
|
|
|
batchActions,
|
|
|
|
doAbandonClaim,
|
|
|
|
selectMyClaimsOutpoints,
|
|
|
|
makeSelectFileInfoForUri,
|
|
|
|
makeSelectClaimForUri,
|
|
|
|
} from 'lbry-redux';
|
2018-10-29 18:23:53 +01:00
|
|
|
import { doHideModal } from 'redux/actions/app';
|
2019-04-19 18:55:21 +02:00
|
|
|
import { goBack } from 'connected-react-router';
|
2019-08-14 05:56:11 +02:00
|
|
|
import { doSetPlayingUri } from 'redux/actions/content';
|
2019-08-15 04:50:41 +02:00
|
|
|
import { selectPlayingUri } from 'redux/selectors/content';
|
2017-04-28 17:14:44 +02:00
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
export function doOpenFileInFolder(path) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return () => {
|
2017-12-21 18:32:51 +01:00
|
|
|
shell.showItemInFolder(path);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-20 14:47:08 +02:00
|
|
|
export function doOpenFileInShell(path) {
|
2017-12-28 00:48:11 +01:00
|
|
|
return 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-12-28 00:48:11 +01:00
|
|
|
return (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,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
// If the file is for a claim we published then also abandon the claim
|
2017-06-29 09:44:34 +02:00
|
|
|
const myClaimsOutpoints = selectMyClaimsOutpoints(state);
|
2019-10-10 07:23:42 +02:00
|
|
|
if (abandonClaim && myClaimsOutpoints.includes(outpoint)) {
|
2019-05-10 08:27:51 +02:00
|
|
|
const [txid, nout] = outpoint.split(':');
|
2017-06-29 09:44:34 +02:00
|
|
|
|
2019-05-11 00:27:07 +02:00
|
|
|
dispatch(doAbandonClaim(txid, Number(nout)));
|
2017-06-29 09:44:34 +02:00
|
|
|
}
|
2020-03-27 17:49:41 +01:00
|
|
|
// @if TARGET='app'
|
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,
|
|
|
|
},
|
|
|
|
});
|
2020-03-27 17:49:41 +01:00
|
|
|
// @endif
|
2017-07-21 10:13:45 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-15 04:50:41 +02:00
|
|
|
export function doDeleteFileAndMaybeGoBack(uri, deleteFromComputer, abandonClaim) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const playingUri = selectPlayingUri(state);
|
2019-08-15 13:36:03 +02:00
|
|
|
const { outpoint } = makeSelectFileInfoForUri(uri)(state) || '';
|
2019-10-01 15:44:37 +02:00
|
|
|
const { nout, txid } = makeSelectClaimForUri(uri)(state);
|
|
|
|
const claimOutpoint = `${txid}:${nout}`;
|
2017-07-21 10:13:45 +02:00
|
|
|
const actions = [];
|
2018-10-29 18:23:53 +01:00
|
|
|
actions.push(doHideModal());
|
2019-10-01 15:44:37 +02:00
|
|
|
actions.push(doDeleteFile(outpoint || claimOutpoint, deleteFromComputer, abandonClaim));
|
2019-08-15 04:50:41 +02:00
|
|
|
|
|
|
|
if (playingUri === uri) {
|
|
|
|
actions.push(doSetPlayingUri(null));
|
|
|
|
}
|
2019-08-30 16:01:39 +02:00
|
|
|
// it would be nice to stay on the claim if you just want to delete it
|
|
|
|
// we need to alter autoplay to not start downloading again after you delete it
|
2019-08-15 04:50:41 +02:00
|
|
|
|
|
|
|
dispatch(batchActions(...actions));
|
2020-02-05 21:54:41 +01:00
|
|
|
if (abandonClaim) {
|
|
|
|
dispatch(goBack());
|
|
|
|
}
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-30 18:01:43 +02:00
|
|
|
}
|