Merge pull request #10474 from thalieht/backport

Backport #10464 to v4_1_x
This commit is contained in:
Mike Tzou 2019-04-11 10:16:08 +08:00 committed by GitHub
commit bad603454b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 5 deletions

View file

@ -2100,7 +2100,7 @@ bool Session::addTorrent(QString source, const AddTorrentParams &params)
LogMsg(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(source));
// Launch downloader
Net::DownloadHandler *handler =
Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(10485760 /* 10MB */).handleRedirectToMagnet(true));
Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE).handleRedirectToMagnet(true));
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
, this, &Session::handleDownloadFinished);
connect(handler, &Net::DownloadHandler::downloadFailed, this, &Session::handleDownloadFailed);

View file

@ -35,6 +35,7 @@
#include <QString>
#include <QUrl>
#include "base/global.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
@ -105,10 +106,9 @@ TorrentInfo TorrentInfo::loadFromFile(const QString &path, QString *error) noexc
return TorrentInfo();
}
const qint64 fileSizeLimit = 100 * 1024 * 1024; // 100 MB
if (file.size() > fileSizeLimit) {
if (file.size() > MAX_TORRENT_SIZE) {
if (error)
*error = tr("File size exceeds max limit %1").arg(fileSizeLimit);
*error = tr("File size exceeds max limit %1").arg(Utils::Misc::friendlyUnit(MAX_TORRENT_SIZE));
return TorrentInfo();
}

View file

@ -32,6 +32,7 @@
#include <QtGlobal>
const char C_TORRENT_FILE_EXTENSION[] = ".torrent";
const int MAX_TORRENT_SIZE = 100 * 1024 * 1024; // 100 MiB
template <typename T>
constexpr typename std::add_const<T>::type &asConst(T &t) noexcept { return t; }

View file

@ -235,7 +235,7 @@ void AddNewTorrentDialog::show(QString source, const BitTorrent::AddTorrentParam
// Launch downloader
// TODO: Don't save loaded torrent to file, just use downloaded data!
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(
Net::DownloadRequest(source).limit(10485760 /* 10MB */).handleRedirectToMagnet(true).saveToFile(true));
Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE).handleRedirectToMagnet(true).saveToFile(true));
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QString &)>(&Net::DownloadHandler::downloadFinished)
, dlg, &AddNewTorrentDialog::handleDownloadFinished);
connect(handler, &Net::DownloadHandler::downloadFailed, dlg, &AddNewTorrentDialog::handleDownloadFailed);