diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index dcf9580b69e8..2d4136943db6 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -1475,6 +1475,27 @@ void TorrentsController::addTagsAction() } } +void TorrentsController::setTagsAction() +{ + requireParams({u"hashes"_s, u"tags"_s}); + + const QStringList hashes {params()[u"hashes"_s].split(u'|', Qt::SkipEmptyParts)}; + const QStringList tags {params()[u"tags"_s].split(u',', Qt::SkipEmptyParts)}; + + const TagSet newTags {tags.begin(), tags.end()}; + applyToTorrents(hashes, [&newTags](BitTorrent::Torrent *const torrent) + { + TagSet tmpTags {newTags}; + for (const Tag &tag : asConst(torrent->tags())) + { + if (tmpTags.erase(tag) == 0) + torrent->removeTag(tag); + } + for (const Tag &tag : tmpTags) + torrent->addTag(tag); + }); +} + void TorrentsController::removeTagsAction() { requireParams({u"hashes"_s}); diff --git a/src/webui/api/torrentscontroller.h b/src/webui/api/torrentscontroller.h index 82e6e01a6b4d..a233048acc76 100644 --- a/src/webui/api/torrentscontroller.h +++ b/src/webui/api/torrentscontroller.h @@ -61,6 +61,7 @@ private slots: void removeCategoriesAction(); void categoriesAction(); void addTagsAction(); + void setTagsAction(); void removeTagsAction(); void createTagsAction(); void deleteTagsAction(); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 514ed3f14d96..e30d5f349e69 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -54,7 +54,7 @@ #include "base/utils/version.h" #include "api/isessionmanager.h" -inline const Utils::Version<3, 2> API_VERSION {2, 11, 3}; +inline const Utils::Version<3, 2> API_VERSION {2, 11, 4}; class QTimer; @@ -212,6 +212,7 @@ class WebApplication final : public ApplicationComponent {{u"torrents"_s, u"setShareLimits"_s}, Http::METHOD_POST}, {{u"torrents"_s, u"setSSLParameters"_s}, Http::METHOD_POST}, {{u"torrents"_s, u"setSuperSeeding"_s}, Http::METHOD_POST}, + {{u"torrents"_s, u"setTags"_s}, Http::METHOD_POST}, {{u"torrents"_s, u"setUploadLimit"_s}, Http::METHOD_POST}, {{u"transfer"_s, u"setDownloadLimit"_s}, Http::METHOD_POST}, {{u"transfer"_s, u"setSpeedLimitsMode"_s}, Http::METHOD_POST},