Merge pull request #7061 from Piccirello/webui-rename-torrent

Rename torrent from webui context menu (addresses #6815)
This commit is contained in:
Mike Tzou 2017-08-13 23:39:35 +08:00 committed by GitHub
commit 0522db3f19
7 changed files with 115 additions and 0 deletions

View file

@ -30,6 +30,8 @@
#include <QCoreApplication>
#include <QTimer>
#include <QCryptographicHash>
#include <QRegularExpression>
#include <queue>
#include <vector>
@ -119,6 +121,7 @@ QMap<QString, QMap<QString, WebApplication::Action> > WebApplication::initialize
ADD_ACTION(command, topPrio);
ADD_ACTION(command, bottomPrio);
ADD_ACTION(command, setLocation);
ADD_ACTION(command, rename);
ADD_ACTION(command, recheck);
ADD_ACTION(command, setCategory);
ADD_ACTION(command, addCategory);
@ -800,6 +803,25 @@ void WebApplication::action_command_setLocation()
}
}
void WebApplication::action_command_rename()
{
CHECK_URI(0);
CHECK_PARAMETERS("hash" << "name");
QString hash = request().posts["hash"];
QString name = request().posts["name"].trimmed();
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
if (torrent && !name.isEmpty()) {
name.replace(QRegularExpression("\r?\n|\r"), " ");
qDebug() << "Renaming" << torrent->name() << "to" << name;
torrent->setName(name);
}
else {
status(400, "Incorrect torrent hash or name");
}
}
void WebApplication::action_command_recheck()
{
CHECK_URI(0);