Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAPI: add new method setTags to upsert tags on torrents #22156

Merged
merged 10 commits into from
Jan 24, 2025
21 changes: 21 additions & 0 deletions src/webui/api/torrentscontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
zze0s marked this conversation as resolved.
Show resolved Hide resolved
{
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});
Expand Down
1 change: 1 addition & 0 deletions src/webui/api/torrentscontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private slots:
void removeCategoriesAction();
void categoriesAction();
void addTagsAction();
void setTagsAction();
void removeTagsAction();
void createTagsAction();
void deleteTagsAction();
Expand Down
3 changes: 2 additions & 1 deletion src/webui/webapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -212,6 +212,7 @@ class WebApplication final : public ApplicationComponent<QObject>
{{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},
Expand Down
Loading