API: rename /file-priority API

This commit is contained in:
Jesse Chan
2020-09-30 20:29:15 +08:00
parent 2443bc9303
commit 9bcf1d8e07
4 changed files with 20 additions and 22 deletions
@@ -242,11 +242,10 @@ const TorrentActions = {
},
),
setFilePriority: (hash: TorrentProperties['hash'], fileIndices: Array<number>, priority: number) =>
setFilePriority: (hash: TorrentProperties['hash'], indices: Array<number>, 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,
},
});
+3 -3
View File
@@ -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]));
});
+2 -3
View File
@@ -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);
+11 -11
View File
@@ -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;