Merge pull request #476 from dcousens/downloadlink

add download link
This commit is contained in:
John Furrow
2017-10-17 21:31:38 -07:00
committed by GitHub
3 changed files with 35 additions and 5 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';
@@ -238,7 +239,7 @@ class TorrentListContainer extends React.Component {
clickHandler,
label: this.props.intl.formatMessage({
id: 'torrents.list.context.move',
defaultMessage: 'Set Download Location'
defaultMessage: 'Set Torrent Location'
})
}, {
type: 'separator'
@@ -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'
})
}, {
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.isMultiFile ? `${torrent.name}.tar` : torrent.name;
link.href = `${baseURI}api/download?hash=${torrent.hash}`;
link.click();
}
handleDoubleClick(torrent, event) {
this.handleDetailsClick(torrent, event);
}
+2 -2
View File
@@ -259,7 +259,7 @@ export default {
'torrents.list.clear.filters': 'Clear Filters',
'torrents.list.context.check.hash': 'Check Hash',
'torrents.list.context.details': 'Torrent Details',
'torrents.list.context.move': 'Set Download Location',
'torrents.list.context.move': 'Set Torrent Location',
'torrents.list.context.pause': 'Pause',
'torrents.list.context.priority': 'Priority',
'torrents.list.context.remove': 'Remove',
@@ -274,7 +274,7 @@ export default {
'torrents.move.button.set.location': 'Set Location',
'torrents.move.button.state.setting': 'Setting...',
'torrents.move.data.label': 'Move data',
'torrents.move.heading': 'Set Download Location',
'torrents.move.heading': 'Set Torrent Location',
'torrents.properties.date.added': 'Added',
'torrents.properties.base.path': 'Base Path',
+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);