API: torrents: add "isSequential" torrent property

This commit is contained in:
Jesse Chan
2020-12-23 20:07:49 +08:00
parent 038ee3f7f1
commit 61b6b61569
9 changed files with 71 additions and 2 deletions
+27 -2
View File
@@ -20,6 +20,7 @@ import type {
MoveTorrentsOptions,
SetTorrentContentsPropertiesOptions,
SetTorrentsPriorityOptions,
SetTorrentsSequentialOptions,
SetTorrentsTrackersOptions,
StartTorrentsOptions,
StopTorrentsOptions,
@@ -120,7 +121,7 @@ router.post<unknown, unknown, AddTorrentByURLOptions>('/add-urls', async (req, r
return;
}
const {urls, cookies, destination, tags, isBasePath, isCompleted, start} = parsedResult.data;
const {urls, cookies, destination, tags, isBasePath, isCompleted, isSequential, start} = parsedResult.data;
const finalDestination = await getDestination(req.services, {
destination,
@@ -140,6 +141,7 @@ router.post<unknown, unknown, AddTorrentByURLOptions>('/add-urls', async (req, r
tags: tags ?? [],
isBasePath: isBasePath ?? false,
isCompleted: isCompleted ?? false,
isSequential: isSequential ?? false,
start: start ?? false,
})
.then((response) => {
@@ -171,7 +173,7 @@ router.post<unknown, unknown, AddTorrentByFileOptions>('/add-files', async (req,
return;
}
const {files, destination, tags, isBasePath, isCompleted, start} = parsedResult.data;
const {files, destination, tags, isBasePath, isCompleted, isSequential, start} = parsedResult.data;
const finalDestination = await getDestination(req.services, {
destination,
@@ -190,6 +192,7 @@ router.post<unknown, unknown, AddTorrentByFileOptions>('/add-files', async (req,
tags: tags ?? [],
isBasePath: isBasePath ?? false,
isCompleted: isCompleted ?? false,
isSequential: isSequential ?? false,
start: start ?? false,
})
.then((response) => {
@@ -261,6 +264,7 @@ router.post<unknown, unknown, CreateTorrentOptions>('/create', async (req, res)
tags: tags ?? [],
isBasePath: true,
isCompleted: true,
isSequential: false,
start: start || false,
})
.catch(() => {
@@ -431,6 +435,27 @@ router.patch<unknown, unknown, SetTorrentsPriorityOptions>('/priority', (req, re
});
});
/**
* PATCH /api/torrents/sequential
* @summary Sets sequential mode of torrents.
* @tags Torrent
* @security User
* @param {SetTorrentsSequentialOptions} request.body.required - options - application/json
* @return {object} 200 - success response - application/json
* @return {Error} 500 - failure response - application/json
*/
router.patch<unknown, unknown, SetTorrentsSequentialOptions>('/sequential', (req, res) => {
req.services?.clientGatewayService?.setTorrentsSequential(req.body).then(
(response) => {
req.services?.torrentService.fetchTorrentList();
res.status(200).json(response);
},
(err) => {
res.status(500).json(err);
},
);
});
/**
* PATCH /api/torrents/tags
* @summary Sets tags of torrents.
@@ -244,6 +244,11 @@ class TransmissionClientGatewayService extends ClientGatewayService {
.then(this.processClientRequestSuccess, this.processClientRequestError);
}
async setTorrentsSequential(): Promise<void> {
// Transmission maintainers rejected the feature.
throw new Error('Transmission does not support this feature.');
}
async setTorrentsTags({hashes, tags}: SetTorrentsTagsOptions): Promise<void> {
return this.clientRequestManager
.setTorrentsProperties({ids: hashes, labels: tags})
@@ -363,6 +368,7 @@ class TransmissionClientGatewayService extends ClientGatewayService {
upTotal: torrent.uploadedEver,
eta: torrent.eta,
isPrivate: torrent.isPrivate,
isSequential: false,
message: torrent.errorString,
peersConnected: torrent.peersGettingFromUs,
peersTotal: torrent.peersGettingFromUs,
+1
View File
@@ -256,6 +256,7 @@ class FeedService extends BaseService {
start,
isBasePath: false,
isCompleted: false,
isSequential: false,
})
.then(() => {
this.db.update({_id: feedID}, {$inc: {count: 1}}, {upsert: true});
@@ -9,6 +9,7 @@ import type {
MoveTorrentsOptions,
SetTorrentContentsPropertiesOptions,
SetTorrentsPriorityOptions,
SetTorrentsSequentialOptions,
SetTorrentsTrackersOptions,
StartTorrentsOptions,
StopTorrentsOptions,
@@ -107,6 +108,14 @@ abstract class ClientGatewayService extends BaseService<ClientGatewayServiceEven
*/
abstract setTorrentsPriority(options: SetTorrentsPriorityOptions): Promise<void>;
/**
* Sets sequential mode of torrents
*
* @param {SetTorrentsSequentialOptions} options - An object of options...
* @return {Promise<void>} - Rejects with error.
*/
abstract setTorrentsSequential(options: SetTorrentsSequentialOptions): Promise<void>;
/**
* Sets tags of torrents
*
@@ -193,6 +193,11 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
}
}
async setTorrentsSequential(): Promise<void> {
// TODO: not implemented
throw new Error();
}
async setTorrentsTags({hashes, tags}: SetTorrentsTagsOptions): Promise<void> {
return this.clientRequestManager.torrentsRemoveTags(hashes).then(() => {
this.clientRequestManager
@@ -294,6 +299,7 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
eta: info.eta >= 8640000 ? -1 : info.eta,
hash: info.hash,
isPrivate,
isSequential: false, // TODO: not implemented
message: '', // in tracker method
name: info.name,
peersConnected: info.num_leechs,
@@ -63,6 +63,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
tags,
isBasePath,
isCompleted,
isSequential,
start,
}: Required<AddTorrentByFileOptions>): Promise<void> {
const torrentPaths = await Promise.all(
@@ -81,6 +82,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
tags,
isBasePath,
isCompleted,
isSequential,
start,
});
}
@@ -433,6 +435,11 @@ class RTorrentClientGatewayService extends ClientGatewayService {
);
}
async setTorrentsSequential(): Promise<void> {
// TODO: not implemented
throw new Error();
}
async setTorrentsTags({hashes, tags}: SetTorrentsTagsOptions): Promise<void> {
const methodCalls = hashes.reduce((accumulator: MultiMethodCalls, hash) => {
accumulator.push({
@@ -601,6 +608,7 @@ class RTorrentClientGatewayService extends ClientGatewayService {
processedResponses.map(async (response) => {
const torrentProperties: TorrentProperties = {
...response,
isSequential: false, // TODO: not implemented
status: getTorrentStatusFromProperties(response),
percentComplete: getTorrentPercentCompleteFromProperties(response),
eta: getTorrentETAFromProperties(response),