Require torrent category creation to be explicit

This commit is contained in:
Thomas Piccirello
2018-07-23 01:48:35 -04:00
parent ee57b68901
commit d89ef22d85
2 changed files with 6 additions and 4 deletions

View File

@@ -811,6 +811,10 @@ void TorrentsController::setCategoryAction()
const QString category {params()["category"].trimmed()};
applyToTorrents(hashes, [category](BitTorrent::TorrentHandle *torrent)
{
auto *session = BitTorrent::Session::instance();
const QStringList categories = session->categories().keys();
if (!categories.contains(category) && !session->addCategory(category))
throw APIError(APIErrorType::Conflict, tr("Unable to create category"));
if (!torrent->setCategory(category))
throw APIError(APIErrorType::Conflict, tr("Incorrect category name"));
});