From fbf3541088fb2eb8267dee56a51efd8c46b5be2e Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 18 Oct 2017 09:38:27 +1100 Subject: [PATCH 1/4] add download link --- .../components/torrent-list/TorrentList.js | 22 +++++++++++++++++++ server/models/client.js | 12 ++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/client/src/javascript/components/torrent-list/TorrentList.js b/client/src/javascript/components/torrent-list/TorrentList.js index 20ddf13a..30dde26e 100644 --- a/client/src/javascript/components/torrent-list/TorrentList.js +++ b/client/src/javascript/components/torrent-list/TorrentList.js @@ -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); } diff --git a/server/models/client.js b/server/models/client.js index 1e73856e..f8e5af3d 100644 --- a/server/models/client.js +++ b/server/models/client.js @@ -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); From c3a54dade41eddbf080f7e88d6e6e3e382e71e32 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 18 Oct 2017 15:23:08 +1100 Subject: [PATCH 2/4] non-isMultiFile downloads are not .tar files --- client/src/javascript/components/torrent-list/TorrentList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/javascript/components/torrent-list/TorrentList.js b/client/src/javascript/components/torrent-list/TorrentList.js index 30dde26e..153632a2 100644 --- a/client/src/javascript/components/torrent-list/TorrentList.js +++ b/client/src/javascript/components/torrent-list/TorrentList.js @@ -330,7 +330,7 @@ class TorrentListContainer extends React.Component { event.preventDefault(); const baseURI = ConfigStore.getBaseURI(); let link = document.createElement('a'); - link.download = `${torrent.name}.tar`; + link.download = torrent.isMultiFile ? `${torrent.name}.tar` : torrent.name; link.href = `${baseURI}api/download?hash=${torrent.hash}`; link.click(); } From b2dddf6f6518fd0d22cce27d045d72d28f54d89f Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 18 Oct 2017 15:25:09 +1100 Subject: [PATCH 3/4] rename 'Set Download Location' to 'Set Torrent Location' --- client/src/javascript/components/torrent-list/TorrentList.js | 2 +- client/src/javascript/i18n/en.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/javascript/components/torrent-list/TorrentList.js b/client/src/javascript/components/torrent-list/TorrentList.js index 153632a2..f3015d19 100644 --- a/client/src/javascript/components/torrent-list/TorrentList.js +++ b/client/src/javascript/components/torrent-list/TorrentList.js @@ -239,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' diff --git a/client/src/javascript/i18n/en.js b/client/src/javascript/i18n/en.js index d6c1f939..68ff9fb2 100644 --- a/client/src/javascript/i18n/en.js +++ b/client/src/javascript/i18n/en.js @@ -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', From b86845beb32d174aa9fec240c72ffba01a3327a5 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 18 Oct 2017 15:25:40 +1100 Subject: [PATCH 4/4] no .tar in label --- client/src/javascript/components/torrent-list/TorrentList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/javascript/components/torrent-list/TorrentList.js b/client/src/javascript/components/torrent-list/TorrentList.js index f3015d19..636fd7dc 100644 --- a/client/src/javascript/components/torrent-list/TorrentList.js +++ b/client/src/javascript/components/torrent-list/TorrentList.js @@ -259,7 +259,7 @@ class TorrentListContainer extends React.Component { }, label: this.props.intl.formatMessage({ id: 'torrents.list.context.download', - defaultMessage: 'Download .tar' + defaultMessage: 'Download' }) }, { action: 'set-priority',