From a15667dba1f9b5d3044058ae2d85627fb986192e Mon Sep 17 00:00:00 2001 From: HamletDuFromage <61667930+HamletDuFromage@users.noreply.github.com> Date: Sat, 26 Jul 2025 16:03:16 +0200 Subject: [PATCH] allow setCommentAction() to take multiple hashes as an argument --- WebAPI_Changelog.md | 2 +- src/webui/api/torrentscontroller.cpp | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/WebAPI_Changelog.md b/WebAPI_Changelog.md index 72fe986d1..3bfe4356c 100644 --- a/WebAPI_Changelog.md +++ b/WebAPI_Changelog.md @@ -2,7 +2,7 @@ ## 2.12.1 * [#23031](https://github.com/qbittorrent/qBittorrent/pull/23031) - * Add `torrents/setComment` endpoint with parameters `hash` and `comment` for setting a new torrent comment + * Add `torrents/setComment` endpoint with parameters `hashes` and `comment` for setting a new torrent comment ## 2.12.0 diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index ef64f525e..df4a79588 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -2146,17 +2146,14 @@ void TorrentsController::onMetadataDownloaded(const BitTorrent::TorrentInfo &inf void TorrentsController::setCommentAction() { - requireParams({u"hash"_s, u"comment"_s}); + requireParams({u"hashes"_s, u"comment"_s}); - const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]); - - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); - if (!torrent) - throw APIError(APIErrorType::NotFound); - - QString comment = params()[u"comment"_s].trimmed() + const QStringList hashes {params()[u"hashes"_s].split(u'|')}; + const QString comment = params()[u"comment"_s].trimmed() .replace(QRegularExpression(u"\r?\n"_s), u" "_s); - torrent->setComment(comment); - setResult(QString()); + applyToTorrents(hashes, [&comment](BitTorrent::Torrent *const torrent) + { + torrent->setComment(comment); + }); }