mirror of
https://github.com/zoriya/flood.git
synced 2026-05-28 09:27:35 +00:00
add download link
This commit is contained in:
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user