From 2f5b1b9b4ed4a7b565f77c8f81a5999405cd8046 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Wed, 30 Sep 2020 11:46:26 +0800 Subject: [PATCH] API: rearrange add, add-files and details endpoints Add and add-files endpoints belong to the Torrents section. getTorrentDetails should use /:hash/details format to match priority and file-priority endpoints. --- .../src/javascript/actions/TorrentActions.ts | 8 ++--- server/routes/client.ts | 32 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/client/src/javascript/actions/TorrentActions.ts b/client/src/javascript/actions/TorrentActions.ts index 3594eea3..e64a552a 100644 --- a/client/src/javascript/actions/TorrentActions.ts +++ b/client/src/javascript/actions/TorrentActions.ts @@ -19,7 +19,7 @@ const baseURI = ConfigStore.getBaseURI(); const TorrentActions = { addTorrentsByUrls: (options: AddTorrentByURLOptions) => axios - .post(`${baseURI}api/client/add`, options) + .post(`${baseURI}api/client/torrents/add`, options) .then((json) => json.data) .then( (response) => { @@ -44,7 +44,7 @@ const TorrentActions = { addTorrentsByFiles: (options: AddTorrentByFileOptions) => axios - .post(`${baseURI}api/client/add-files`, options) + .post(`${baseURI}api/client/torrents/add-files`, options) .then((json) => json.data) .then( (data) => { @@ -120,9 +120,7 @@ const TorrentActions = { fetchTorrentDetails: (hash: TorrentProperties['hash']) => axios - .post(`${baseURI}api/client/torrent-details`, { - hash, - }) + .get(`${baseURI}api/client/torrents/${hash}/details`) .then((json) => json.data) .then( (torrentDetails) => { diff --git a/server/routes/client.ts b/server/routes/client.ts index 7dbbadf2..76045d15 100644 --- a/server/routes/client.ts +++ b/server/routes/client.ts @@ -35,14 +35,6 @@ router.post('/connection-test', (req, res) => { }); }); -router.post('/add', (req, res) => { - client.addUrls(req.user, req.services, req.body, ajaxUtil.getResponseFn(res)); -}); - -router.post('/add-files', (req, res) => { - client.addFiles(req.user, req.services, req.body, ajaxUtil.getResponseFn(res)); -}); - router.get('/settings', (req, res) => { client.getSettings(req.user, req.services, req.query, ajaxUtil.getResponseFn(res)); }); @@ -55,16 +47,12 @@ router.put('/settings/speed-limits', (req, res) => { client.setSpeedLimits(req.user, req.services, req.body, ajaxUtil.getResponseFn(res)); }); -router.post('/torrent-details', (req, res) => { - client.getTorrentDetails(req.user, req.services, req.body.hash, ajaxUtil.getResponseFn(res)); +router.post('/torrents/add', (req, res) => { + client.addUrls(req.user, req.services, req.body, ajaxUtil.getResponseFn(res)); }); -router.patch('/torrents/:hash/priority', (req, res) => { - client.setPriority(req.user, req.services, req.params.hash, req.body, ajaxUtil.getResponseFn(res)); -}); - -router.patch('/torrents/:hash/file-priority', (req, res) => { - client.setFilePriority(req.user, req.services, req.params.hash, req.body, ajaxUtil.getResponseFn(res)); +router.post('/torrents/add-files', (req, res) => { + client.addFiles(req.user, req.services, req.body, ajaxUtil.getResponseFn(res)); }); /** @@ -200,6 +188,18 @@ router.patch('/torrents/tracker', (req, res) => { client.setTracker(req.user, req.services, req.body, ajaxUtil.getResponseFn(res)); }); +router.get('/torrents/:hash/details', (req, res) => { + client.getTorrentDetails(req.user, req.services, req.params.hash, ajaxUtil.getResponseFn(res)); +}); + +router.patch('/torrents/:hash/priority', (req, res) => { + client.setPriority(req.user, req.services, req.params.hash, req.body, ajaxUtil.getResponseFn(res)); +}); + +router.patch('/torrents/:hash/file-priority', (req, res) => { + client.setFilePriority(req.user, req.services, req.params.hash, req.body, ajaxUtil.getResponseFn(res)); +}); + router.get('/methods.json', (req, res) => { const {type} = req.query; const {args} = req.query;