API: move /download API to where it should be

This commit is contained in:
Jesse Chan
2020-09-30 19:13:51 +08:00
parent 2e9fef29b0
commit 2443bc9303
5 changed files with 43 additions and 8 deletions
@@ -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();
@@ -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();
+1 -1
View File
@@ -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(',');
-5
View File
@@ -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));
});
+40
View File
@@ -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));