mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Merge 669f8cd06d
into feacfb0627
This commit is contained in:
commit
bac9a11cc7
5 changed files with 37 additions and 2 deletions
|
@ -4038,6 +4038,11 @@ void SessionImpl::updateTrackersFromURL()
|
||||||
{
|
{
|
||||||
if (result.status == Net::DownloadStatus::Success)
|
if (result.status == Net::DownloadStatus::Success)
|
||||||
{
|
{
|
||||||
|
if (!result.contentType.contains(u"text/plain"_s, Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
LogMsg(tr("Cannot add trackers from URL, expected Content-Type is \'text/plain\' received \"%1\"").arg(result.contentType), Log::WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setAdditionalTrackersFromURL(QString::fromUtf8(result.data));
|
setAdditionalTrackersFromURL(QString::fromUtf8(result.data));
|
||||||
LogMsg(tr("Tracker list updated"), Log::INFO);
|
LogMsg(tr("Tracker list updated"), Log::INFO);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -143,6 +143,7 @@ void Net::DownloadHandlerImpl::processFinishedDownload()
|
||||||
#else
|
#else
|
||||||
m_result.data = m_reply->readAll();
|
m_result.data = m_reply->readAll();
|
||||||
#endif
|
#endif
|
||||||
|
m_result.contentType = m_reply->header(QNetworkRequest::ContentTypeHeader).toString();
|
||||||
|
|
||||||
if (m_downloadRequest.saveToFile())
|
if (m_downloadRequest.saveToFile())
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,6 +104,7 @@ namespace Net
|
||||||
QString url;
|
QString url;
|
||||||
DownloadStatus status = DownloadStatus::Failed;
|
DownloadStatus status = DownloadStatus::Failed;
|
||||||
QString errorString;
|
QString errorString;
|
||||||
|
QString contentType;
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
Path filePath;
|
Path filePath;
|
||||||
QString magnetURI;
|
QString magnetURI;
|
||||||
|
|
|
@ -74,14 +74,35 @@ TrackersAdditionDialog::~TrackersAdditionDialog()
|
||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackersAdditionDialog::onAccepted() const
|
bool isValidEndpoint(const QStringView endpoint)
|
||||||
|
{
|
||||||
|
if (endpoint.isEmpty())
|
||||||
|
return false;
|
||||||
|
const QUrl url {endpoint.toString()};
|
||||||
|
if (!url.isValid())
|
||||||
|
return false;
|
||||||
|
if (url.scheme().isEmpty())
|
||||||
|
return false;
|
||||||
|
if (url.host().isEmpty())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackersAdditionDialog::onAccepted()
|
||||||
{
|
{
|
||||||
const QList<BitTorrent::TrackerEntryStatus> currentTrackers = m_torrent->trackers();
|
const QList<BitTorrent::TrackerEntryStatus> currentTrackers = m_torrent->trackers();
|
||||||
const int baseTier = !currentTrackers.isEmpty() ? (currentTrackers.last().tier + 1) : 0;
|
const int baseTier = !currentTrackers.isEmpty() ? (currentTrackers.last().tier + 1) : 0;
|
||||||
|
|
||||||
QList<BitTorrent::TrackerEntry> entries = BitTorrent::parseTrackerEntries(m_ui->textEditTrackersList->toPlainText());
|
QList<BitTorrent::TrackerEntry> entries = BitTorrent::parseTrackerEntries(m_ui->textEditTrackersList->toPlainText());
|
||||||
for (BitTorrent::TrackerEntry &entry : entries)
|
for (BitTorrent::TrackerEntry &entry : entries)
|
||||||
|
{
|
||||||
|
if (!isValidEndpoint(entry.url))
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Invalid tracker URL"), tr("The tracker URL \"%1\" is invalid").arg(entry.url));
|
||||||
|
return;
|
||||||
|
}
|
||||||
entry.tier = Utils::Number::clampingAdd(entry.tier, baseTier);
|
entry.tier = Utils::Number::clampingAdd(entry.tier, baseTier);
|
||||||
|
}
|
||||||
|
|
||||||
m_torrent->addTrackers(entries);
|
m_torrent->addTrackers(entries);
|
||||||
}
|
}
|
||||||
|
@ -116,6 +137,13 @@ void TrackersAdditionDialog::onTorrentListDownloadFinished(const Net::DownloadRe
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!result.contentType.contains(u"text/plain"_s, Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Download trackers list error")
|
||||||
|
, tr("The content type of the downloaded file is not plain text. Content-Type: \"%1\"").arg(result.contentType));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Add fetched trackers to the list
|
// Add fetched trackers to the list
|
||||||
const QString existingText = m_ui->textEditTrackersList->toPlainText();
|
const QString existingText = m_ui->textEditTrackersList->toPlainText();
|
||||||
if (!existingText.isEmpty() && !existingText.endsWith(u'\n'))
|
if (!existingText.isEmpty() && !existingText.endsWith(u'\n'))
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
~TrackersAdditionDialog();
|
~TrackersAdditionDialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onAccepted() const;
|
void onAccepted();
|
||||||
void onDownloadButtonClicked();
|
void onDownloadButtonClicked();
|
||||||
void onTorrentListDownloadFinished(const Net::DownloadResult &result);
|
void onTorrentListDownloadFinished(const Net::DownloadResult &result);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue