diff --git a/src/base/bittorrent/torrent.h b/src/base/bittorrent/torrent.h index 644af158b..c47036147 100644 --- a/src/base/bittorrent/torrent.h +++ b/src/base/bittorrent/torrent.h @@ -144,6 +144,7 @@ namespace BitTorrent virtual QDateTime creationDate() const = 0; virtual QString creator() const = 0; virtual QString comment() const = 0; + virtual void setComment(const QString &comment) = 0; virtual bool isPrivate() const = 0; virtual qlonglong totalSize() const = 0; virtual qlonglong wantedSize() const = 0; diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index c3a7c0f2b..e67d44a95 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -2959,3 +2959,8 @@ QFuture> TorrentImpl::invokeAsync(Func &&func) const return future; } + +void TorrentImpl::setComment(const QString &comment) +{ + m_comment = comment; +} diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index 2c1f9af77..e44d875c9 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -106,6 +106,7 @@ namespace BitTorrent QDateTime creationDate() const override; QString creator() const override; QString comment() const override; + void setComment(const QString &comment) override; bool isPrivate() const override; qlonglong totalSize() const override; qlonglong wantedSize() const override; diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index d0c5f54af..065830f48 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -2143,3 +2143,20 @@ void TorrentsController::onMetadataDownloaded(const BitTorrent::TorrentInfo &inf iter.value().setTorrentInfo(info); } } + +void TorrentsController::setCommentAction() +{ + requireParams({u"hash"_s, u"comment"_s}); + + const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]); + QString comment = params()[u"comment"_s].trimmed(); + + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); + if (!torrent) + throw APIError(APIErrorType::NotFound); + + comment.replace(QRegularExpression(u"\r?\n|\r"_s), u" "_s); + torrent->setComment(comment); + + setResult(QString()); +} diff --git a/src/webui/api/torrentscontroller.h b/src/webui/api/torrentscontroller.h index 2792c835c..7f81ec15a 100644 --- a/src/webui/api/torrentscontroller.h +++ b/src/webui/api/torrentscontroller.h @@ -71,6 +71,7 @@ private slots: void recheckAction(); void reannounceAction(); void renameAction(); + void setCommentAction(); void setCategoryAction(); void createCategoryAction(); void editCategoryAction();