From 0a908f93ce9de38f351cc124e70987e80e69dc56 Mon Sep 17 00:00:00 2001 From: ShanaryS Date: Mon, 26 May 2025 11:42:57 -0400 Subject: [PATCH] fix: check for torrent metadata before getFiles() --- src/webui/api/torrentscontroller.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 1e26ca1ce..3a681664d 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -301,7 +301,7 @@ namespace { const BitTorrent::TorrentInfo::PieceRange idx = info.filePieces(index); - QJsonObject fileDict = + const QJsonObject fileDict = { {KEY_FILE_INDEX, index}, {KEY_FILE_PROGRESS, fp[index]}, @@ -412,7 +412,7 @@ void TorrentsController::infoAction() QVariantMap serializedTorrent = serialize(*torrent); - if (includeFiles) + if (includeFiles && torrent->hasMetadata()) serializedTorrent.insert(KEY_PROP_FILES, getFiles(torrent)); if (includeTrackers) serializedTorrent.insert(KEY_PROP_TRACKERS, getTrackers(torrent)); @@ -765,6 +765,9 @@ void TorrentsController::filesAction() }); } + if (!torrent->hasMetadata()) + return setResult(QJsonArray {}); + QJsonArray fileList = getFiles(torrent, fileIndexes); if (!fileList.isEmpty()) {