feat(torrents): support remote torrent metadata

This commit is contained in:
NimBold
2026-08-02 00:29:49 +03:30
parent 0f1f4e8003
commit d0541308c7
6 changed files with 281 additions and 4 deletions
+1 -3
View File
@@ -574,9 +574,7 @@ export const AddDownloadsModal = () => {
const requestContext = requestContextForUrl(contextUrl);
if (row.isTorrent) {
const torrentCacheId = row.torrentCacheId || `${row.id}-${row.generation}`;
const proxy = row.sourceUrl.trim().toLowerCase().startsWith('magnet:')
? await getProxyArgs(settingsStore)
: undefined;
const proxy = await getProxyArgs(settingsStore);
const torrentData = await invoke('inspect_torrent', {
source: row.sourceUrl,
id: torrentCacheId,
+14
View File
@@ -12,6 +12,7 @@ import {
mediaTypeForFormat,
metadataSummaryMessage,
isYouTubePlaylistUrl,
isRemoteTorrentUrl,
playlistFilePrefix,
reconcileDownloadRows,
refreshFailedMetadataRows,
@@ -106,6 +107,19 @@ describe('add download metadata workflow', () => {
expect(rows[1].torrentCacheId).toBe(`${rows[1].id}-1`);
});
it('admits remote .torrent URLs through the Torrent metadata path', () => {
expect(isRemoteTorrentUrl('https://example.com/files/sample.torrent?download=1')).toBe(true);
expect(isRemoteTorrentUrl('https://example.com/files/sample.zip')).toBe(false);
const rows = reconcileDownloadRows('https://example.com/files/sample.torrent?download=1', []);
expect(rows[0]).toMatchObject({
isTorrent: true,
isMedia: false,
status: 'loading'
});
});
it('gives refreshed torrent metadata a new cache identity', () => {
const existing = row({
id: 'torrent-row',
+11 -1
View File
@@ -91,6 +91,16 @@ const isLocalTorrentPath = (value: string): boolean => {
&& (value.startsWith('/') || /^[a-z]:[\\/]/i.test(value));
};
export const isRemoteTorrentUrl = (value: string): boolean => {
try {
const parsed = new URL(value);
return (parsed.protocol === 'http:' || parsed.protocol === 'https:')
&& parsed.pathname.toLowerCase().endsWith('.torrent');
} catch {
return false;
}
};
type ParsedInput = {
identity: string;
sourceUrl: string;
@@ -153,7 +163,7 @@ const parseInputLines = (
if (!isTorrent) {
const url = new URL(line);
valid = ALLOWED_SCHEMES.has(url.protocol);
isTorrent = valid && url.protocol === 'magnet:';
isTorrent = valid && (url.protocol === 'magnet:' || isRemoteTorrentUrl(sourceUrl));
if (valid) sourceUrl = url.href;
}
} catch {