From a1dd47c8b77ba231b04f966841deeb2826b2573b Mon Sep 17 00:00:00 2001 From: ShanaryS Date: Sun, 25 May 2025 11:21:15 -0400 Subject: [PATCH] fix: don't expose is_seed in /torrents/info --- src/webui/api/torrentscontroller.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 825cb5cfa..ef4c518a9 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -299,6 +299,8 @@ namespace const BitTorrent::TorrentInfo info = torrent->info(); for (const int index : asConst(fileIndexes)) { + const BitTorrent::TorrentInfo::PieceRange idx = info.filePieces(index); + QJsonObject fileDict = { {KEY_FILE_INDEX, index}, @@ -307,15 +309,10 @@ namespace {KEY_FILE_SIZE, torrent->fileSize(index)}, {KEY_FILE_AVAILABILITY, fileAvailability[index]}, // need to provide paths using a platform-independent separator format - {KEY_FILE_NAME, torrent->filePath(index).data()} + {KEY_FILE_NAME, torrent->filePath(index).data()}, + {KEY_FILE_PIECE_RANGE, QJsonArray {idx.first(), idx.last()}} }; - const BitTorrent::TorrentInfo::PieceRange idx = info.filePieces(index); - fileDict[KEY_FILE_PIECE_RANGE] = QJsonArray {idx.first(), idx.last()}; - - if (index == 0) - fileDict[KEY_FILE_IS_SEED] = torrent->isFinished(); - fileList.append(fileDict); } @@ -768,7 +765,15 @@ void TorrentsController::filesAction() }); } - setResult(getFiles(torrent, fileIndexes)); + QJsonArray fileList = getFiles(torrent, fileIndexes); + if (!fileList.isEmpty()) + { + QJsonObject firstFile = fileList[0].toObject(); + firstFile[KEY_FILE_IS_SEED] = torrent->isFinished(); + fileList[0] = firstFile; + } + + setResult(fileList); } // Returns an array of hashes (of each pieces respectively) for a torrent in JSON format.