From 9bcf1d8e0736a780dafcb04f0b4364b25dcda083 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Wed, 30 Sep 2020 20:29:15 +0800 Subject: [PATCH] API: rename /file-priority API --- .../src/javascript/actions/TorrentActions.ts | 9 ++++---- server/models/ClientRequest.js | 6 ++--- server/models/client.js | 5 ++--- server/routes/api/torrents.ts | 22 +++++++++---------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/client/src/javascript/actions/TorrentActions.ts b/client/src/javascript/actions/TorrentActions.ts index 81f14836..b81aff8c 100644 --- a/client/src/javascript/actions/TorrentActions.ts +++ b/client/src/javascript/actions/TorrentActions.ts @@ -242,11 +242,10 @@ const TorrentActions = { }, ), - setFilePriority: (hash: TorrentProperties['hash'], fileIndices: Array, priority: number) => + setFilePriority: (hash: TorrentProperties['hash'], indices: Array, priority: number) => axios - .patch(`${baseURI}api/torrents/${hash}/file-priority`, { - hash, - fileIndices, + .patch(`${baseURI}api/torrents/${hash}/contents`, { + indices, priority, }) .then((json) => json.data) @@ -257,7 +256,7 @@ const TorrentActions = { data: { ...data, hash, - fileIndices, + indices, priority, }, }); diff --git a/server/models/ClientRequest.js b/server/models/ClientRequest.js index 8fd72b08..07772075 100644 --- a/server/models/ClientRequest.js +++ b/server/models/ClientRequest.js @@ -227,12 +227,12 @@ class ClientRequest { } setFilePriority(options) { - const fileIndices = getEnsuredArray(options.fileIndices); + const indices = getEnsuredArray(options.indices); const hashes = getEnsuredArray(options.hashes); hashes.forEach((hash) => { - fileIndices.forEach((fileIndex) => { - this.requests.push(getMethodCall('f.priority.set', [`${hash}:f${fileIndex}`, options.priority])); + indices.forEach((index) => { + this.requests.push(getMethodCall('f.priority.set', [`${hash}:f${index}`, options.priority])); }); this.requests.push(getMethodCall('d.update_priorities', [hash])); }); diff --git a/server/models/client.js b/server/models/client.js index 1be8c3f8..f90408e9 100644 --- a/server/models/client.js +++ b/server/models/client.js @@ -218,11 +218,10 @@ const client = { }, setFilePriority(user, services, hashes, data, callback) { - // TODO Add support for multiple hashes. - const {fileIndices} = data; + const {indices, priority} = data; const request = new ClientRequest(user, services); - request.setFilePriority({hashes, fileIndices, priority: data.priority}); + request.setFilePriority({hashes, indices, priority}); request.onComplete((response, error) => { services.torrentService.fetchTorrentList(); callback(response, error); diff --git a/server/routes/api/torrents.ts b/server/routes/api/torrents.ts index da07be26..f72b4c3a 100644 --- a/server/routes/api/torrents.ts +++ b/server/routes/api/torrents.ts @@ -211,6 +211,17 @@ router.patch('/tracker', (req, res) => { * @param {string} hash.path */ +/** + * PATCH /api/torrents/{hash}/contents + * @summary Sets properties of contents of a torrent. Only priority can be set. + * @tags Torrent + * @security AuthenticatedUser + * @param {string} hash.path + */ +router.patch('/:hash/contents', (req, res) => { + client.setFilePriority(req.user, req.services, req.params.hash, req.body, ajaxUtil.getResponseFn(res)); +}); + /** * GET /api/torrents/{hash}/contents/{indices}/data * @summary Gets downloaded data of contents of a torrent. @@ -258,15 +269,4 @@ router.patch('/:hash/priority', (req, res) => { client.setPriority(req.user, req.services, req.params.hash, req.body, ajaxUtil.getResponseFn(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)); -}); - export default router;