mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-06 09:30:29 +00:00
feat(torrents): support remote torrent metadata
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user