add download link

This commit is contained in:
Daniel Cousens
2017-10-18 09:38:27 +11:00
parent afed82ceb7
commit fbf3541088
2 changed files with 32 additions and 2 deletions
@@ -6,6 +6,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import ContextMenu from '../general/ContextMenu';
import ConfigStore from '../../stores/ConfigStore';
import CustomScrollbars from '../general/CustomScrollbars';
import EventTypes from '../../constants/EventTypes';
import Files from '../icons/Files';
@@ -251,6 +252,15 @@ class TorrentListContainer extends React.Component {
id: 'torrents.list.context.details',
defaultMessage: 'Torrent Details'
})
}, {
action: 'torrent-download-tar',
clickHandler: (action, event) => {
clickHandler(action, event, torrent);
},
label: this.props.intl.formatMessage({
id: 'torrents.list.context.download',
defaultMessage: 'Download .tar'
})
}, {
action: 'set-priority',
clickHandler,
@@ -295,6 +305,9 @@ class TorrentListContainer extends React.Component {
case 'torrent-details':
this.handleDetailsClick(torrent, event);
break;
case 'torrent-download-tar':
this.handleTorrentDownload(torrent, event);
break;
case 'set-priority':
this.state.handleTorrentPriorityChange(event);
break;
@@ -313,6 +326,15 @@ class TorrentListContainer extends React.Component {
});
}
handleTorrentDownload(torrent, event) {
event.preventDefault();
const baseURI = ConfigStore.getBaseURI();
let link = document.createElement('a');
link.download = `${torrent.name}.tar`;
link.href = `${baseURI}api/download?hash=${torrent.hash}`;
link.click();
}
handleDoubleClick(torrent, event) {
this.handleDetailsClick(torrent, event);
}
+10 -2
View File
@@ -78,13 +78,21 @@ var client = {
request.send();
},
downloadFiles(hash, files, res) {
downloadFiles(hash, fileString, res) {
try {
const selectedTorrent = torrentService.getTorrent(hash);
if (!selectedTorrent) return res.status(404).json({error: 'Torrent not found.'});
this.getTorrentDetails(hash, (torrentDetails) => {
let files;
if (!fileString) {
files = torrentDetails.fileTree.files.map((x, i) => `${i}`);
} else {
files = fileString.split(',');
}
const filePathsToDownload = this.findFilesByIndicies(
files.split(','),
files,
torrentDetails.fileTree
).map((file) => {
return path.join(selectedTorrent.directory, file.path);