feat(torrents): support tracker exclusion

This commit is contained in:
NimBold
2026-08-02 01:19:18 +03:30
parent ab9f0507d0
commit a46a64994d
20 changed files with 295 additions and 32 deletions
+4
View File
@@ -855,6 +855,7 @@ describe('useDownloadStore', () => {
torrentPeerSpeedLimit: 0 as unknown as string,
torrentCheckIntegrity: 'yes' as unknown as boolean,
torrentTrackers: 123 as unknown as string,
torrentExcludeTrackers: 123 as unknown as string,
torrentStopTimeout: 604801
});
@@ -862,6 +863,7 @@ describe('useDownloadStore', () => {
expect(normalized.torrentPeerSpeedLimit).toBeUndefined();
expect(normalized.torrentCheckIntegrity).toBeUndefined();
expect(normalized.torrentTrackers).toBeUndefined();
expect(normalized.torrentExcludeTrackers).toBeUndefined();
expect(normalized.torrentStopTimeout).toBeUndefined();
});
@@ -1515,6 +1517,7 @@ describe('useDownloadStore', () => {
isTorrent: true,
torrentCheckIntegrity: true,
torrentTrackers: 'https://tracker.example/announce',
torrentExcludeTrackers: '*',
torrentStopTimeout: 300
}, { type: 'start-now' });
@@ -1528,6 +1531,7 @@ describe('useDownloadStore', () => {
id: 'start-1',
torrent_check_integrity: true,
torrent_trackers: 'https://tracker.example/announce',
torrent_exclude_trackers: '*',
torrent_stop_timeout: 300
})
})
+10 -2
View File
@@ -9,7 +9,7 @@ import type { ExtensionCookieScope } from '../bindings/ExtensionCookieScope';
import type { Queue } from '../bindings/Queue';
import { useSettingsStore } from './useSettingsStore';
import { useDownloadProgressStore } from './downloadProgressStore';
import { canonicalizeDownloadFileName, categoryForFileName, isActiveDownloadStatus, isTransferActiveStatus, MAX_TORRENT_STOP_TIMEOUT, normalizeSpeedLimitForBackend, redactDownloadForPersistence, resolveDownloadConnections } from '../utils/downloads';
import { canonicalizeDownloadFileName, categoryForFileName, isActiveDownloadStatus, isTransferActiveStatus, isValidTorrentExcludeTrackerList, isValidTorrentTrackerList, MAX_TORRENT_STOP_TIMEOUT, normalizeSpeedLimitForBackend, redactDownloadForPersistence, resolveDownloadConnections } from '../utils/downloads';
import {
resolveCategoryDestination
} from '../utils/downloadLocations';
@@ -352,6 +352,7 @@ async function dispatchItemInternal(id: string, proxyOverride?: string | null):
torrent_peer_speed_limit: item.torrentPeerSpeedLimit || undefined,
torrent_check_integrity: item.torrentCheckIntegrity,
torrent_trackers: item.torrentTrackers || undefined,
torrent_exclude_trackers: item.torrentExcludeTrackers || undefined,
torrent_stop_timeout: item.torrentStopTimeout,
lifecycle_generation: lifecycleGeneration.toString(),
};
@@ -634,9 +635,13 @@ export const normalizePersistedDownloadProgress = (download: DownloadItem): Down
? rawCheckIntegrity
: undefined;
const rawTrackers = download.torrentTrackers as unknown;
const normalizedTrackers = typeof rawTrackers === 'string' && rawTrackers.trim()
const normalizedTrackers = typeof rawTrackers === 'string' && rawTrackers.trim() && isValidTorrentTrackerList(rawTrackers)
? rawTrackers.trim()
: undefined;
const rawExcludeTrackers = download.torrentExcludeTrackers as unknown;
const normalizedExcludeTrackers = typeof rawExcludeTrackers === 'string' && rawExcludeTrackers.trim() && isValidTorrentExcludeTrackerList(rawExcludeTrackers)
? rawExcludeTrackers.trim()
: undefined;
const rawStopTimeout = download.torrentStopTimeout as unknown;
const normalizedStopTimeout = typeof rawStopTimeout === 'number' &&
Number.isInteger(rawStopTimeout) &&
@@ -648,6 +653,7 @@ export const normalizePersistedDownloadProgress = (download: DownloadItem): Down
rawPeerSpeedLimit !== normalizedPeerSpeedLimit ||
rawCheckIntegrity !== normalizedCheckIntegrity ||
rawTrackers !== normalizedTrackers ||
rawExcludeTrackers !== normalizedExcludeTrackers ||
rawStopTimeout !== normalizedStopTimeout
? {
...download,
@@ -655,6 +661,7 @@ export const normalizePersistedDownloadProgress = (download: DownloadItem): Down
torrentPeerSpeedLimit: normalizedPeerSpeedLimit,
torrentCheckIntegrity: normalizedCheckIntegrity,
torrentTrackers: normalizedTrackers,
torrentExcludeTrackers: normalizedExcludeTrackers,
torrentStopTimeout: normalizedStopTimeout
}
: download;
@@ -2188,6 +2195,7 @@ export const useDownloadStore = create<DownloadState>((set, get) => {
torrent_peer_speed_limit: item.torrentPeerSpeedLimit || undefined,
torrent_check_integrity: item.torrentCheckIntegrity,
torrent_trackers: item.torrentTrackers || undefined,
torrent_exclude_trackers: item.torrentExcludeTrackers || undefined,
torrent_stop_timeout: item.torrentStopTimeout,
lifecycle_generation: currentDownloadLifecycle(item.id).toString(),
});