From 2b031e7e05bf51fc5e69cd4cd7cc8e6f269ede53 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 14 Jun 2026 23:53:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=20transmission-rpc=20?= =?UTF-8?q?v7=20=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/transmission/transmission.py | 10 ++++++-- tests/test_transmission_compat.py | 32 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/app/modules/transmission/transmission.py b/app/modules/transmission/transmission.py index 21970de3..e91fb3fc 100755 --- a/app/modules/transmission/transmission.py +++ b/app/modules/transmission/transmission.py @@ -278,9 +278,15 @@ class Transmission: except Exception as err: logger.error(f"获取种子文件列表出错:{str(err)}") return None - if torrent: + if not torrent: + return None + try: + get_files = getattr(torrent, "get_files", None) + if callable(get_files): + return get_files() return torrent.files() - else: + except Exception as err: + logger.error(f"获取种子文件列表出错:{str(err)}") return None def set_files(self, tid: str, file_ids: list) -> bool: diff --git a/tests/test_transmission_compat.py b/tests/test_transmission_compat.py index 603c1aa0..5b11d939 100644 --- a/tests/test_transmission_compat.py +++ b/tests/test_transmission_compat.py @@ -132,3 +132,35 @@ def test_login_skips_incomplete_file_suffix_when_already_matches(): assert downloader.trc is fake_client fake_client.set_session.assert_not_called() + + +def test_get_files_uses_transmission_rpc_v7_get_files(): + """ + transmission-rpc v7 任务对象应使用 get_files 获取文件列表。 + """ + downloader = Transmission.__new__(Transmission) + torrent_files = [object()] + torrent = types.SimpleNamespace(get_files=MagicMock(return_value=torrent_files)) + fake_client = MagicMock() + fake_client.get_torrent.return_value = torrent + downloader.trc = fake_client + + assert downloader.get_files("1") == torrent_files + fake_client.get_torrent.assert_called_once_with("1") + torrent.get_files.assert_called_once_with() + + +def test_get_files_falls_back_to_legacy_files_method(): + """ + 旧版 transmission-rpc 任务对象仍应通过 files 获取文件列表。 + """ + downloader = Transmission.__new__(Transmission) + torrent_files = [object()] + torrent = types.SimpleNamespace(files=MagicMock(return_value=torrent_files)) + fake_client = MagicMock() + fake_client.get_torrent.return_value = torrent + downloader.trc = fake_client + + assert downloader.get_files("1") == torrent_files + fake_client.get_torrent.assert_called_once_with("1") + torrent.files.assert_called_once_with()