allow setCommentAction() to take multiple hashes as an argument

This commit is contained in:
HamletDuFromage 2025-07-26 16:03:16 +02:00
commit a15667dba1
2 changed files with 8 additions and 11 deletions

View file

@ -2,7 +2,7 @@
## 2.12.1 ## 2.12.1
* [#23031](https://github.com/qbittorrent/qBittorrent/pull/23031) * [#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 ## 2.12.0

View file

@ -2146,17 +2146,14 @@ void TorrentsController::onMetadataDownloaded(const BitTorrent::TorrentInfo &inf
void TorrentsController::setCommentAction() 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]); const QStringList hashes {params()[u"hashes"_s].split(u'|')};
const QString comment = params()[u"comment"_s].trimmed()
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
if (!torrent)
throw APIError(APIErrorType::NotFound);
QString comment = params()[u"comment"_s].trimmed()
.replace(QRegularExpression(u"\r?\n"_s), u" "_s); .replace(QRegularExpression(u"\r?\n"_s), u" "_s);
torrent->setComment(comment);
setResult(QString()); applyToTorrents(hashes, [&comment](BitTorrent::Torrent *const torrent)
{
torrent->setComment(comment);
});
} }