From 59a3fc74fd82db09fecd20065f1a314f18190003 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Wed, 26 May 2021 22:19:37 +0800 Subject: [PATCH] API: add a "dateActive" field to TorrentProperties Last time the torrent is active, -1 means currently active, 0 means data unavailable --- server/services/Deluge/clientGatewayService.ts | 3 +++ server/services/Deluge/types/DelugeCoreMethods.ts | 2 +- server/services/Transmission/clientGatewayService.ts | 2 ++ server/services/qBittorrent/clientGatewayService.ts | 1 + server/services/rTorrent/clientGatewayService.ts | 1 + .../rTorrent/constants/methodCallConfigs/torrentList.ts | 4 ++++ shared/types/Torrent.ts | 2 ++ 7 files changed, 14 insertions(+), 1 deletion(-) diff --git a/server/services/Deluge/clientGatewayService.ts b/server/services/Deluge/clientGatewayService.ts index 8d7723bb..57ba5476 100644 --- a/server/services/Deluge/clientGatewayService.ts +++ b/server/services/Deluge/clientGatewayService.ts @@ -283,6 +283,7 @@ class DelugeClientGatewayService extends ClientGatewayService { async fetchTorrentList(): Promise { return this.clientRequestManager .coreGetTorrentsStatus([ + 'active_time', 'download_location', 'download_payload_rate', 'eta', @@ -321,6 +322,8 @@ class DelugeClientGatewayService extends ClientGatewayService { const torrentProperties: TorrentProperties = { bytesDone: status.total_done, + dateActive: + status.download_payload_rate > 0 || status.upload_payload_rate > 0 ? -1 : status.active_time, dateAdded: status.time_added, dateCreated: 0, dateFinished: diff --git a/server/services/Deluge/types/DelugeCoreMethods.ts b/server/services/Deluge/types/DelugeCoreMethods.ts index 1df6fe96..c6c4c060 100644 --- a/server/services/Deluge/types/DelugeCoreMethods.ts +++ b/server/services/Deluge/types/DelugeCoreMethods.ts @@ -102,7 +102,7 @@ export type DelugeCoreTorrentState = 'Downloading' | 'Seeding' | 'Paused' | 'Che export type DelugeCoreTorrentStorageMode = 'sparse' | 'allocate'; export interface DelugeCoreTorrentStatuses { - active_time: unknown; + active_time: number; seeding_time: unknown; finished_time: number; all_time_download: unknown; diff --git a/server/services/Transmission/clientGatewayService.ts b/server/services/Transmission/clientGatewayService.ts index acfde38a..d05db7d3 100644 --- a/server/services/Transmission/clientGatewayService.ts +++ b/server/services/Transmission/clientGatewayService.ts @@ -346,6 +346,7 @@ class TransmissionClientGatewayService extends ClientGatewayService { 'totalSize', 'trackers', 'labels', + 'activityDate', ]) .then(this.processClientRequestSuccess, this.processClientRequestError) .then(async (torrents) => { @@ -364,6 +365,7 @@ class TransmissionClientGatewayService extends ClientGatewayService { hash: torrent.hashString.toUpperCase(), name: torrent.name, bytesDone: torrent.haveValid, + dateActive: torrent.rateDownload > 0 || torrent.rateUpload > 0 ? -1 : torrent.activityDate, dateAdded: torrent.addedDate, dateCreated: torrent.dateCreated, dateFinished: torrent.doneDate, diff --git a/server/services/qBittorrent/clientGatewayService.ts b/server/services/qBittorrent/clientGatewayService.ts index 1e2e787e..d70ac53e 100644 --- a/server/services/qBittorrent/clientGatewayService.ts +++ b/server/services/qBittorrent/clientGatewayService.ts @@ -360,6 +360,7 @@ class QBittorrentClientGatewayService extends ClientGatewayService { const torrentProperties: TorrentProperties = { bytesDone: info.completed, + dateActive: info.dlspeed > 0 || info.upspeed > 0 ? -1 : info.last_activity, dateAdded: info.added_on, dateCreated, dateFinished: info.completion_on, diff --git a/server/services/rTorrent/clientGatewayService.ts b/server/services/rTorrent/clientGatewayService.ts index 9347513e..a3483bd8 100644 --- a/server/services/rTorrent/clientGatewayService.ts +++ b/server/services/rTorrent/clientGatewayService.ts @@ -649,6 +649,7 @@ class RTorrentClientGatewayService extends ClientGatewayService { processedResponses.map(async (response) => { const torrentProperties: TorrentProperties = { bytesDone: response.bytesDone, + dateActive: response.downRate > 0 || response.upRate > 0 ? -1 : response.dateActive, dateAdded: response.dateAdded, dateCreated: response.dateCreated, dateFinished: response.dateFinished, diff --git a/server/services/rTorrent/constants/methodCallConfigs/torrentList.ts b/server/services/rTorrent/constants/methodCallConfigs/torrentList.ts index fcd9925f..385151ef 100644 --- a/server/services/rTorrent/constants/methodCallConfigs/torrentList.ts +++ b/server/services/rTorrent/constants/methodCallConfigs/torrentList.ts @@ -98,6 +98,10 @@ const torrentListMethodCallConfigs = { methodCall: 'd.timestamp.finished=', transformValue: numberTransformer, }, + dateActive: { + methodCall: 'd.timestamp.last_active=', + transformValue: numberTransformer, + }, tags: { methodCall: 'd.custom1=', transformValue: (value: unknown): string[] => { diff --git a/shared/types/Torrent.ts b/shared/types/Torrent.ts index 0db328fe..79312191 100644 --- a/shared/types/Torrent.ts +++ b/shared/types/Torrent.ts @@ -18,6 +18,8 @@ export enum TorrentPriority { export interface TorrentProperties { bytesDone: number; + // Last time the torrent is active, -1 means currently active, 0 means data unavailable + dateActive: number; dateAdded: number; dateCreated: number; dateFinished: number;