Add WebAPI/WebUI for managing cookies

Closes #21125.
PR #21340.
This commit is contained in:
Thomas Piccirello 2024-09-30 05:13:25 -04:00 committed by GitHub
parent 10eb921d70
commit 6bbb7b71cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 285 additions and 29 deletions

View file

@ -34,7 +34,6 @@
#include <QJsonArray>
#include <QJsonObject>
#include <QList>
#include <QNetworkCookie>
#include <QRegularExpression>
#include <QUrl>
@ -53,7 +52,6 @@
#include "base/interfaces/iapplication.h"
#include "base/global.h"
#include "base/logger.h"
#include "base/net/downloadmanager.h"
#include "base/torrentfilter.h"
#include "base/utils/datetime.h"
#include "base/utils/fs.h"
@ -787,7 +785,6 @@ void TorrentsController::pieceStatesAction()
void TorrentsController::addAction()
{
const QString urls = params()[u"urls"_s];
const QString cookie = params()[u"cookie"_s];
const bool skipChecking = parseBool(params()[u"skip_checking"_s]).value_or(false);
const bool seqDownload = parseBool(params()[u"sequentialDownload"_s]).value_or(false);
@ -818,23 +815,6 @@ void TorrentsController::addAction()
? Utils::String::toEnum(contentLayoutParam, BitTorrent::TorrentContentLayout::Original)
: std::optional<BitTorrent::TorrentContentLayout> {});
QList<QNetworkCookie> cookies;
if (!cookie.isEmpty())
{
const QStringList cookiesStr = cookie.split(u"; "_s);
for (QString cookieStr : cookiesStr)
{
cookieStr = cookieStr.trimmed();
int index = cookieStr.indexOf(u'=');
if (index > 1)
{
QByteArray name = cookieStr.left(index).toLatin1();
QByteArray value = cookieStr.right(cookieStr.length() - index - 1).toLatin1();
cookies += QNetworkCookie(name, value);
}
}
}
const BitTorrent::AddTorrentParams addTorrentParams
{
// TODO: Check if destination actually exists
@ -875,7 +855,6 @@ void TorrentsController::addAction()
url = url.trimmed();
if (!url.isEmpty())
{
Net::DownloadManager::instance()->setCookiesFromUrl(cookies, QUrl::fromEncoded(url.toUtf8()));
partialSuccess |= app()->addTorrentManager()->addTorrent(url, addTorrentParams);
}
}