mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-22 17:06:40 +00:00
feat(torrents): add tracker timing controls
This commit is contained in:
@@ -13,7 +13,7 @@ import { FolderPlus, Save, Settings, Shield, RefreshCw, FileText, HardDrive, Dat
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
import { invokeCommand as invoke } from '../ipc';
|
||||
import { DuplicateResolutionModal, DuplicateConflict } from './DuplicateResolutionModal';
|
||||
import { canonicalizeDownloadFileName, categoryForFileName, downloadFileNameWithSuffix, downloadFileNamesMatch, downloadMediaKindsMatch, isValidTorrentExcludeTrackerList, isValidTorrentTrackerList, MAX_TORRENT_STOP_TIMEOUT, normalizeSpeedLimitForBackend, normalizeTorrentPrioritizePiece, TORRENT_ENCRYPTION_POLICY_DISABLED, TORRENT_ENCRYPTION_POLICY_FORCE_ENCRYPTION, TORRENT_ENCRYPTION_POLICY_REQUIRE_CRYPTO, type TorrentEncryptionPolicy } from '../utils/downloads';
|
||||
import { canonicalizeDownloadFileName, categoryForFileName, downloadFileNameWithSuffix, downloadFileNamesMatch, downloadMediaKindsMatch, isValidTorrentExcludeTrackerList, isValidTorrentTrackerList, MAX_TORRENT_STOP_TIMEOUT, MAX_TORRENT_TRACKER_INTERVAL, MAX_TORRENT_TRACKER_TIMEOUT, normalizeSpeedLimitForBackend, normalizeTorrentPrioritizePiece, normalizeTorrentTrackerInterval, normalizeTorrentTrackerTimeout, TORRENT_ENCRYPTION_POLICY_DISABLED, TORRENT_ENCRYPTION_POLICY_FORCE_ENCRYPTION, TORRENT_ENCRYPTION_POLICY_REQUIRE_CRYPTO, type TorrentEncryptionPolicy } from '../utils/downloads';
|
||||
import { fetchMediaMetadataDeduped, fetchMediaPlaylistMetadataDeduped } from '../utils/mediaMetadata';
|
||||
import {
|
||||
expandTilde,
|
||||
@@ -237,6 +237,9 @@ export const AddDownloadsModal = () => {
|
||||
const [torrentEncryptionPolicy, setTorrentEncryptionPolicy] = useState<TorrentEncryptionPolicy>(TORRENT_ENCRYPTION_POLICY_DISABLED);
|
||||
const [torrentTrackers, setTorrentTrackers] = useState('');
|
||||
const [torrentExcludeTrackers, setTorrentExcludeTrackers] = useState('');
|
||||
const [torrentTrackerConnectTimeout, setTorrentTrackerConnectTimeout] = useState('');
|
||||
const [torrentTrackerTimeout, setTorrentTrackerTimeout] = useState('');
|
||||
const [torrentTrackerInterval, setTorrentTrackerInterval] = useState('0');
|
||||
const [torrentStopTimeout, setTorrentStopTimeout] = useState('0');
|
||||
const [torrentPrioritizePiece, setTorrentPrioritizePiece] = useState('');
|
||||
const [freeSpace, setFreeSpace] = useState('Unknown');
|
||||
@@ -382,6 +385,9 @@ export const AddDownloadsModal = () => {
|
||||
setTorrentCheckIntegrity(false);
|
||||
setTorrentTrackers('');
|
||||
setTorrentExcludeTrackers('');
|
||||
setTorrentTrackerConnectTimeout('');
|
||||
setTorrentTrackerTimeout('');
|
||||
setTorrentTrackerInterval('0');
|
||||
setTorrentStopTimeout('0');
|
||||
setUseAuth(false);
|
||||
setUsername('');
|
||||
@@ -987,6 +993,18 @@ export const AddDownloadsModal = () => {
|
||||
addToast({ message: t($ => $.addDownloads.torrentExcludeTrackersInvalid), variant: 'error', isActionable: true });
|
||||
return;
|
||||
}
|
||||
if (hasSelectedTorrent && torrentTrackerConnectTimeout.trim() && !normalizeTorrentTrackerTimeout(torrentTrackerConnectTimeout)) {
|
||||
addToast({ message: t($ => $.addDownloads.torrentTrackerTimeoutInvalid), variant: 'error', isActionable: true });
|
||||
return;
|
||||
}
|
||||
if (hasSelectedTorrent && torrentTrackerTimeout.trim() && !normalizeTorrentTrackerTimeout(torrentTrackerTimeout)) {
|
||||
addToast({ message: t($ => $.addDownloads.torrentTrackerTimeoutInvalid), variant: 'error', isActionable: true });
|
||||
return;
|
||||
}
|
||||
if (hasSelectedTorrent && torrentTrackerInterval.trim() && normalizeTorrentTrackerInterval(torrentTrackerInterval) === undefined) {
|
||||
addToast({ message: t($ => $.addDownloads.torrentTrackerIntervalInvalid), variant: 'error', isActionable: true });
|
||||
return;
|
||||
}
|
||||
if (hasSelectedTorrent && torrentPrioritizePiece.trim() && !normalizeTorrentPrioritizePiece(torrentPrioritizePiece)) {
|
||||
addToast({ message: t($ => $.addDownloads.torrentPrioritizePieceInvalid), variant: 'error', isActionable: true });
|
||||
return;
|
||||
@@ -1501,6 +1519,15 @@ export const AddDownloadsModal = () => {
|
||||
: undefined,
|
||||
torrentTrackers: item.isTorrent ? torrentTrackers.trim() || undefined : undefined,
|
||||
torrentExcludeTrackers: item.isTorrent ? torrentExcludeTrackers.trim() || undefined : undefined,
|
||||
torrentTrackerConnectTimeout: item.isTorrent && torrentTrackerConnectTimeout.trim()
|
||||
? Number(torrentTrackerConnectTimeout)
|
||||
: undefined,
|
||||
torrentTrackerTimeout: item.isTorrent && torrentTrackerTimeout.trim()
|
||||
? Number(torrentTrackerTimeout)
|
||||
: undefined,
|
||||
torrentTrackerInterval: item.isTorrent && torrentTrackerInterval.trim()
|
||||
? Number(torrentTrackerInterval)
|
||||
: undefined,
|
||||
torrentStopTimeout: item.isTorrent && torrentStopTimeout.trim() ? Number(torrentStopTimeout) : undefined,
|
||||
torrentPrioritizePiece: item.isTorrent ? normalizeTorrentPrioritizePiece(torrentPrioritizePiece) || undefined : undefined,
|
||||
size: item.size || (item.sizeBytes ? formatBytes(item.sizeBytes) : undefined),
|
||||
@@ -2242,6 +2269,64 @@ export const AddDownloadsModal = () => {
|
||||
{t($ => $.addDownloads.torrentExcludeTrackersHint)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-[1fr_auto] gap-2 items-center pt-2 border-t border-border-modal/50">
|
||||
<label htmlFor="torrent-tracker-connect-timeout" className="text-text-muted">
|
||||
{t($ => $.addDownloads.torrentTrackerConnectTimeout)}
|
||||
</label>
|
||||
<div className="flex items-center gap-1">
|
||||
<input
|
||||
id="torrent-tracker-connect-timeout"
|
||||
type="number"
|
||||
min={1}
|
||||
max={MAX_TORRENT_TRACKER_TIMEOUT}
|
||||
step={1}
|
||||
value={torrentTrackerConnectTimeout}
|
||||
onChange={event => setTorrentTrackerConnectTimeout(event.currentTarget.value)}
|
||||
placeholder="60"
|
||||
className="app-control w-24 px-2 py-1 text-end font-mono"
|
||||
aria-describedby="torrent-tracker-timing-hint"
|
||||
/>
|
||||
<span className="text-[10px] text-text-muted">{t($ => $.addDownloads.seconds)}</span>
|
||||
</div>
|
||||
<label htmlFor="torrent-tracker-timeout" className="text-text-muted">
|
||||
{t($ => $.addDownloads.torrentTrackerTimeout)}
|
||||
</label>
|
||||
<div className="flex items-center gap-1">
|
||||
<input
|
||||
id="torrent-tracker-timeout"
|
||||
type="number"
|
||||
min={1}
|
||||
max={MAX_TORRENT_TRACKER_TIMEOUT}
|
||||
step={1}
|
||||
value={torrentTrackerTimeout}
|
||||
onChange={event => setTorrentTrackerTimeout(event.currentTarget.value)}
|
||||
placeholder="60"
|
||||
className="app-control w-24 px-2 py-1 text-end font-mono"
|
||||
aria-describedby="torrent-tracker-timing-hint"
|
||||
/>
|
||||
<span className="text-[10px] text-text-muted">{t($ => $.addDownloads.seconds)}</span>
|
||||
</div>
|
||||
<label htmlFor="torrent-tracker-interval" className="text-text-muted">
|
||||
{t($ => $.addDownloads.torrentTrackerInterval)}
|
||||
</label>
|
||||
<div className="flex items-center gap-1">
|
||||
<input
|
||||
id="torrent-tracker-interval"
|
||||
type="number"
|
||||
min={0}
|
||||
max={MAX_TORRENT_TRACKER_INTERVAL}
|
||||
step={1}
|
||||
value={torrentTrackerInterval}
|
||||
onChange={event => setTorrentTrackerInterval(event.currentTarget.value)}
|
||||
className="app-control w-24 px-2 py-1 text-end font-mono"
|
||||
aria-describedby="torrent-tracker-timing-hint"
|
||||
/>
|
||||
<span className="text-[10px] text-text-muted">{t($ => $.addDownloads.seconds)}</span>
|
||||
</div>
|
||||
<p id="torrent-tracker-timing-hint" className="col-span-2 text-[10px] text-text-muted">
|
||||
{t($ => $.addDownloads.torrentTrackerTimingHint)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-[1fr_auto] gap-2 items-center pt-2 border-t border-border-modal/50">
|
||||
<label htmlFor="torrent-max-peers" className="text-text-muted">
|
||||
{t($ => $.addDownloads.torrentMaxPeers)}
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
formatDownloadTotal,
|
||||
resolveDownloadSizeDisplay
|
||||
} from '../utils/downloadProgress';
|
||||
import { isValidTorrentExcludeTrackerList, isValidTorrentTrackerList, MAX_TORRENT_STOP_TIMEOUT, normalizeSpeedLimitForBackend, normalizeTorrentEncryptionPolicy, normalizeTorrentPrioritizePiece, resolveDownloadConnections, TORRENT_ENCRYPTION_POLICY_DISABLED, TORRENT_ENCRYPTION_POLICY_FORCE_ENCRYPTION, TORRENT_ENCRYPTION_POLICY_REQUIRE_CRYPTO, type TorrentEncryptionPolicy } from '../utils/downloads';
|
||||
import { isValidTorrentExcludeTrackerList, isValidTorrentTrackerList, MAX_TORRENT_STOP_TIMEOUT, MAX_TORRENT_TRACKER_INTERVAL, MAX_TORRENT_TRACKER_TIMEOUT, normalizeSpeedLimitForBackend, normalizeTorrentEncryptionPolicy, normalizeTorrentPrioritizePiece, normalizeTorrentTrackerInterval, normalizeTorrentTrackerTimeout, resolveDownloadConnections, TORRENT_ENCRYPTION_POLICY_DISABLED, TORRENT_ENCRYPTION_POLICY_FORCE_ENCRYPTION, TORRENT_ENCRYPTION_POLICY_REQUIRE_CRYPTO, type TorrentEncryptionPolicy } from '../utils/downloads';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { formatDateTime, type CalendarPreference } from '../utils/dateTime';
|
||||
import { isTopmostModal, useModalFocus } from '../hooks/useModalFocus';
|
||||
@@ -91,6 +91,9 @@ export const PropertiesModal = () => {
|
||||
const [torrentEncryptionPolicy, setTorrentEncryptionPolicy] = useState<TorrentEncryptionPolicy>(TORRENT_ENCRYPTION_POLICY_DISABLED);
|
||||
const [torrentTrackers, setTorrentTrackers] = useState('');
|
||||
const [torrentExcludeTrackers, setTorrentExcludeTrackers] = useState('');
|
||||
const [torrentTrackerConnectTimeout, setTorrentTrackerConnectTimeout] = useState('');
|
||||
const [torrentTrackerTimeout, setTorrentTrackerTimeout] = useState('');
|
||||
const [torrentTrackerInterval, setTorrentTrackerInterval] = useState('0');
|
||||
const [torrentStopTimeout, setTorrentStopTimeout] = useState('0');
|
||||
const [torrentPrioritizePiece, setTorrentPrioritizePiece] = useState('');
|
||||
const [torrentPeerDiagnostics, setTorrentPeerDiagnostics] = useState<TorrentPeerDiagnostics | null>(null);
|
||||
@@ -197,6 +200,9 @@ export const PropertiesModal = () => {
|
||||
setTorrentEncryptionPolicy(normalizeTorrentEncryptionPolicy(activeItem.torrentEncryptionPolicy) || TORRENT_ENCRYPTION_POLICY_DISABLED);
|
||||
setTorrentTrackers(activeItem.torrentTrackers || '');
|
||||
setTorrentExcludeTrackers(activeItem.torrentExcludeTrackers || '');
|
||||
setTorrentTrackerConnectTimeout(activeItem.torrentTrackerConnectTimeout === undefined ? '' : String(activeItem.torrentTrackerConnectTimeout));
|
||||
setTorrentTrackerTimeout(activeItem.torrentTrackerTimeout === undefined ? '' : String(activeItem.torrentTrackerTimeout));
|
||||
setTorrentTrackerInterval(activeItem.torrentTrackerInterval === undefined ? '0' : String(activeItem.torrentTrackerInterval));
|
||||
setTorrentStopTimeout(activeItem.torrentStopTimeout === undefined ? '0' : String(activeItem.torrentStopTimeout));
|
||||
setTorrentPrioritizePiece(activeItem.torrentPrioritizePiece || '');
|
||||
setErrorMessage('');
|
||||
@@ -349,6 +355,18 @@ export const PropertiesModal = () => {
|
||||
setErrorMessage(t($ => $.properties.torrentExcludeTrackersInvalid));
|
||||
return;
|
||||
}
|
||||
if (item.isTorrent && torrentTrackerConnectTimeout.trim() && !normalizeTorrentTrackerTimeout(torrentTrackerConnectTimeout)) {
|
||||
setErrorMessage(t($ => $.properties.torrentTrackerTimeoutInvalid));
|
||||
return;
|
||||
}
|
||||
if (item.isTorrent && torrentTrackerTimeout.trim() && !normalizeTorrentTrackerTimeout(torrentTrackerTimeout)) {
|
||||
setErrorMessage(t($ => $.properties.torrentTrackerTimeoutInvalid));
|
||||
return;
|
||||
}
|
||||
if (item.isTorrent && torrentTrackerInterval.trim() && normalizeTorrentTrackerInterval(torrentTrackerInterval) === undefined) {
|
||||
setErrorMessage(t($ => $.properties.torrentTrackerIntervalInvalid));
|
||||
return;
|
||||
}
|
||||
if (item.isTorrent && torrentPrioritizePiece.trim() && !normalizeTorrentPrioritizePiece(torrentPrioritizePiece)) {
|
||||
setErrorMessage(t($ => $.properties.torrentPrioritizePieceInvalid));
|
||||
return;
|
||||
@@ -399,6 +417,15 @@ export const PropertiesModal = () => {
|
||||
torrentCheckIntegrity,
|
||||
torrentTrackers: torrentTrackers.trim() || undefined,
|
||||
torrentExcludeTrackers: torrentExcludeTrackers.trim() || undefined,
|
||||
torrentTrackerConnectTimeout: torrentTrackerConnectTimeout.trim()
|
||||
? Number(torrentTrackerConnectTimeout)
|
||||
: undefined,
|
||||
torrentTrackerTimeout: torrentTrackerTimeout.trim()
|
||||
? Number(torrentTrackerTimeout)
|
||||
: undefined,
|
||||
torrentTrackerInterval: torrentTrackerInterval.trim()
|
||||
? Number(torrentTrackerInterval)
|
||||
: undefined,
|
||||
torrentStopTimeout: normalizedStopTimeout,
|
||||
torrentPrioritizePiece: normalizeTorrentPrioritizePiece(torrentPrioritizePiece) || undefined,
|
||||
torrentRemoveUnselectedFile: item.torrentFileIndices !== undefined
|
||||
@@ -940,6 +967,71 @@ export const PropertiesModal = () => {
|
||||
{t($ => $.properties.torrentExcludeTrackersHint)}
|
||||
</p>
|
||||
</div>
|
||||
<label className="text-xs text-text-muted text-right" htmlFor="torrent-tracker-connect-timeout-properties">
|
||||
{t($ => $.properties.torrentTrackerConnectTimeout)}
|
||||
</label>
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
id="torrent-tracker-connect-timeout-properties"
|
||||
type="number"
|
||||
min={1}
|
||||
max={MAX_TORRENT_TRACKER_TIMEOUT}
|
||||
step={1}
|
||||
value={torrentTrackerConnectTimeout}
|
||||
onChange={event => setTorrentTrackerConnectTimeout(event.currentTarget.value)}
|
||||
placeholder="60"
|
||||
disabled={transferLocked}
|
||||
aria-describedby="torrent-tracker-timing-properties-hint"
|
||||
className="app-control w-24 px-2.5 py-1.5 text-end text-xs font-mono disabled:opacity-50"
|
||||
/>
|
||||
<span className="text-[11px] text-text-muted">{t($ => $.properties.seconds)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<label className="text-xs text-text-muted text-right" htmlFor="torrent-tracker-timeout-properties">
|
||||
{t($ => $.properties.torrentTrackerTimeout)}
|
||||
</label>
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
id="torrent-tracker-timeout-properties"
|
||||
type="number"
|
||||
min={1}
|
||||
max={MAX_TORRENT_TRACKER_TIMEOUT}
|
||||
step={1}
|
||||
value={torrentTrackerTimeout}
|
||||
onChange={event => setTorrentTrackerTimeout(event.currentTarget.value)}
|
||||
placeholder="60"
|
||||
disabled={transferLocked}
|
||||
aria-describedby="torrent-tracker-timing-properties-hint"
|
||||
className="app-control w-24 px-2.5 py-1.5 text-end text-xs font-mono disabled:opacity-50"
|
||||
/>
|
||||
<span className="text-[11px] text-text-muted">{t($ => $.properties.seconds)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<label className="text-xs text-text-muted text-right" htmlFor="torrent-tracker-interval-properties">
|
||||
{t($ => $.properties.torrentTrackerInterval)}
|
||||
</label>
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
id="torrent-tracker-interval-properties"
|
||||
type="number"
|
||||
min={0}
|
||||
max={MAX_TORRENT_TRACKER_INTERVAL}
|
||||
step={1}
|
||||
value={torrentTrackerInterval}
|
||||
onChange={event => setTorrentTrackerInterval(event.currentTarget.value)}
|
||||
disabled={transferLocked}
|
||||
aria-describedby="torrent-tracker-timing-properties-hint"
|
||||
className="app-control w-24 px-2.5 py-1.5 text-end text-xs font-mono disabled:opacity-50"
|
||||
/>
|
||||
<span className="text-[11px] text-text-muted">{t($ => $.properties.seconds)}</span>
|
||||
</div>
|
||||
<p id="torrent-tracker-timing-properties-hint" className="mt-1 text-[11px] text-text-muted">
|
||||
{t($ => $.properties.torrentTrackerTimingHint)}
|
||||
</p>
|
||||
</div>
|
||||
<label className="text-xs text-text-muted text-right" htmlFor="torrent-stop-timeout-properties">
|
||||
{t($ => $.properties.torrentStopTimeout)}
|
||||
</label>
|
||||
|
||||
Reference in New Issue
Block a user