Skip to content

Commit 703978b

Browse files
committed
server: qBittorrent, Transmission: normalize hash to upper case
1 parent 87e4b54 commit 703978b

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

server/services/Transmission/clientGatewayService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class TransmissionClientGatewayService extends ClientGatewayService {
361361
const status = torrentPropertiesUtil.getTorrentStatus(torrent);
362362

363363
const torrentProperties: TorrentProperties = {
364-
hash: torrent.hashString,
364+
hash: torrent.hashString.toUpperCase(),
365365
name: torrent.name,
366366
bytesDone: torrent.haveValid,
367367
dateAdded: torrent.addedDate,

server/services/qBittorrent/clientGatewayService.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
224224
const {torrents} = await this.fetchTorrentList();
225225

226226
const flipNeeded: Array<string> = hashes.filter((hash) => {
227-
const currentIsSequential = torrents[hash]?.isSequential;
227+
const currentIsSequential = torrents[hash.toUpperCase()]?.isSequential;
228228
return currentIsSequential != null && currentIsSequential !== isSequential;
229229
});
230230

@@ -253,7 +253,7 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
253253
return this.clientRequestManager
254254
.torrentsAddTrackers(hash, trackers)
255255
.then(this.processClientRequestSuccess, this.processClientRequestError)
256-
.then(() => delete this.cachedProperties[hash]);
256+
.then(() => delete this.cachedProperties[hash.toUpperCase()]);
257257
}),
258258
).then(() => undefined);
259259
}
@@ -303,14 +303,14 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
303303
{},
304304
...(await Promise.all(
305305
infos.map(async (info) => {
306-
if (this.cachedProperties[info.hash] == null) {
307-
const properties = await this.clientRequestManager
308-
.getTorrentProperties(info.hash)
309-
.catch(() => undefined);
310-
const trackers = await this.clientRequestManager.getTorrentTrackers(info.hash).catch(() => undefined);
306+
const hash = info.hash.toUpperCase();
307+
308+
if (this.cachedProperties[hash] == null) {
309+
const properties = await this.clientRequestManager.getTorrentProperties(hash).catch(() => undefined);
310+
const trackers = await this.clientRequestManager.getTorrentTrackers(hash).catch(() => undefined);
311311

312312
if (properties != null && trackers != null && Array.isArray(trackers)) {
313-
this.cachedProperties[info.hash] = {
313+
this.cachedProperties[hash] = {
314314
dateCreated: properties?.creation_date,
315315
isPrivate: trackers[0]?.msg.includes('is private'),
316316
trackerURIs: getDomainsFromURLs(
@@ -322,7 +322,7 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
322322
}
323323
}
324324

325-
const {dateCreated = 0, isPrivate = false, trackerURIs = []} = this.cachedProperties[info.hash] || {};
325+
const {dateCreated = 0, isPrivate = false, trackerURIs = []} = this.cachedProperties[hash] || {};
326326

327327
const torrentProperties: TorrentProperties = {
328328
bytesDone: info.completed,
@@ -332,7 +332,7 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
332332
downRate: info.dlspeed,
333333
downTotal: info.downloaded,
334334
eta: info.eta >= 8640000 ? -1 : info.eta,
335-
hash: info.hash,
335+
hash,
336336
isPrivate,
337337
isInitialSeeding: info.super_seeding,
338338
isSequential: info.seq_dl,

shared/types/Torrent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface TorrentProperties {
2525
downTotal: number;
2626
// Torrent ETA (seconds), -1 means infinity
2727
eta: number;
28+
// Upper-case hash of info section of the torrent
2829
hash: string;
2930
isPrivate: boolean;
3031
// If initial seeding mode (aka super seeding) is enabled

0 commit comments

Comments
 (0)