diff --git a/client/src/javascript/components/modals/torrent-details-modal/TorrentFiles.js b/client/src/javascript/components/modals/torrent-details-modal/TorrentFiles.js index 0fd4d99d..adf82577 100644 --- a/client/src/javascript/components/modals/torrent-details-modal/TorrentFiles.js +++ b/client/src/javascript/components/modals/torrent-details-modal/TorrentFiles.js @@ -92,7 +92,7 @@ class TorrentFiles extends React.Component { const baseURI = ConfigStore.getBaseURI(); const link = document.createElement('a'); link.download = `${this.props.torrent.name}.tar`; - link.href = `${baseURI}api/download?hash=${this.props.torrent.hash}&files=${this.state.selectedFiles.join(',')}`; + link.href = `${baseURI}api/torrents/${this.props.torrent.hash}/contents/${this.state.selectedFiles.join(',')}/data`; link.style.display = 'none'; document.body.appendChild(link); // Fix for Firefox 58+ link.click(); diff --git a/client/src/javascript/components/torrent-list/TorrentListContextMenu.js b/client/src/javascript/components/torrent-list/TorrentListContextMenu.js index 3e8cde5f..c9e2d09f 100644 --- a/client/src/javascript/components/torrent-list/TorrentListContextMenu.js +++ b/client/src/javascript/components/torrent-list/TorrentListContextMenu.js @@ -28,7 +28,7 @@ const handleTorrentDownload = (torrent, event) => { const baseURI = ConfigStore.getBaseURI(); const link = document.createElement('a'); link.download = torrent.isMultiFile ? `${torrent.name}.tar` : torrent.name; - link.href = `${baseURI}api/download?hash=${torrent.hash}`; + link.href = `${baseURI}api/torrents/${torrent.hash}/contents/all/data`; link.style.display = 'none'; document.body.appendChild(link); link.click(); diff --git a/server/models/client.js b/server/models/client.js index 8fc5e255..1be8c3f8 100644 --- a/server/models/client.js +++ b/server/models/client.js @@ -84,7 +84,7 @@ const client = { if (!torrentDetails) return res.status(404).json({error: 'Torrent details not found'}); let files; - if (!fileString) { + if (!fileString || fileString === 'all') { files = torrentDetails.fileTree.files.map((x, i) => `${i}`); } else { files = fileString.split(','); diff --git a/server/routes/api/index.ts b/server/routes/api/index.ts index 21110775..cf38517c 100644 --- a/server/routes/api/index.ts +++ b/server/routes/api/index.ts @@ -8,7 +8,6 @@ import type {NotificationFetchOptions} from '@shared/types/Notification'; import appendUserServices from '../../middleware/appendUserServices'; import ajaxUtil from '../../util/ajaxUtil'; -import client from '../../models/client'; import clientRoutes from './client'; import clientActivityStream from '../../middleware/clientActivityStream'; import eventStream from '../../middleware/eventStream'; @@ -29,10 +28,6 @@ router.use('/torrents', torrentsRoutes); router.get('/activity-stream', eventStream, clientActivityStream); -router.get('/download', (req, res) => { - client.downloadFiles(req.user, req.services, req.query.hash, req.query.files, res); -}); - router.get('/directory-list', (req, res) => { Filesystem.getDirectoryList(req.query, ajaxUtil.getResponseFn(res)); }); diff --git a/server/routes/api/torrents.ts b/server/routes/api/torrents.ts index e6e9e40d..da07be26 100644 --- a/server/routes/api/torrents.ts +++ b/server/routes/api/torrents.ts @@ -194,9 +194,43 @@ router.patch('/tracker', (req, res) => { */ /** + * TODO: API not yet implemented + * GET /api/torrents/{hash} + * @summary Gets information of a torrent. + * @tags Torrent + * @security AuthenticatedUser + * @param {string} hash.path - Hash of a torrent + */ + +/** + * TODO: API not yet implemented + * GET /api/torrents/{hash}/contents + * @summary Gets the list of contents of a torrent and their properties. + * @tags Torrent + * @security AuthenticatedUser + * @param {string} hash.path + */ + +/** + * GET /api/torrents/{hash}/contents/{indices}/data + * @summary Gets downloaded data of contents of a torrent. + * @tags Torrent + * @security AuthenticatedUser + * @param {string} hash.path + * @param {string} indices.path - 'all' or indices of selected contents separated by ',' + * @return {object} 200 - contents archived in .tar - application/x-tar + */ +router.get('/:hash/contents/:indices/data', (req, res) => { + client.downloadFiles(req.user, req.services, req.params.hash, req.params.indices, res); +}); + +/** + * TODO: Split to /peers, /trackers and /contents endpoints * GET /api/torrents/{hash}/details * @summary Gets details of a torrent. + * @tags Torrent * @security AuthenticatedUser + * @param {string} hash.path */ router.get('/:hash/details', (req, res) => { client.getTorrentDetails(req.user, req.services, req.params.hash, ajaxUtil.getResponseFn(res)); @@ -205,7 +239,9 @@ router.get('/:hash/details', (req, res) => { /** * GET /api/torrents/{hash}/mediainfo * @summary Gets mediainfo output of a torrent. + * @tags Torrent * @security AuthenticatedUser + * @param {string} hash.path */ router.get('/:hash/mediainfo', (req, res) => { mediainfo.getMediainfo(req.services, req.params.hash, ajaxUtil.getResponseFn(res)); @@ -214,7 +250,9 @@ router.get('/:hash/mediainfo', (req, res) => { /** * PATCH /api/torrents/{hash}/priority * @summary Sets priority of a torrent. + * @tags Torrent * @security AuthenticatedUser + * @param {string} hash.path */ router.patch('/:hash/priority', (req, res) => { client.setPriority(req.user, req.services, req.params.hash, req.body, ajaxUtil.getResponseFn(res)); @@ -223,7 +261,9 @@ router.patch('/:hash/priority', (req, res) => { /** * PATCH /api/torrents/{hash}/file-priority * @summary Sets priority of files of a torrent. + * @tags Torrent * @security AuthenticatedUser + * @param {string} hash.path */ router.patch('/:hash/file-priority', (req, res) => { client.setFilePriority(req.user, req.services, req.params.hash, req.body, ajaxUtil.getResponseFn(res));