mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-14 02:27:09 -07:00
Merge 669f8cd06d
into 4f94eac235
This commit is contained in:
commit
78f9bc0514
5 changed files with 37 additions and 2 deletions
|
@ -4102,6 +4102,11 @@ void SessionImpl::updateTrackersFromURL()
|
|||
{
|
||||
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));
|
||||
LogMsg(tr("Tracker list updated"), Log::INFO);
|
||||
return;
|
||||
|
|
|
@ -143,6 +143,7 @@ void Net::DownloadHandlerImpl::processFinishedDownload()
|
|||
#else
|
||||
m_result.data = m_reply->readAll();
|
||||
#endif
|
||||
m_result.contentType = m_reply->header(QNetworkRequest::ContentTypeHeader).toString();
|
||||
|
||||
if (m_downloadRequest.saveToFile())
|
||||
{
|
||||
|
|
|
@ -104,6 +104,7 @@ namespace Net
|
|||
QString url;
|
||||
DownloadStatus status = DownloadStatus::Failed;
|
||||
QString errorString;
|
||||
QString contentType;
|
||||
QByteArray data;
|
||||
Path filePath;
|
||||
QString magnetURI;
|
||||
|
|
|
@ -74,14 +74,35 @@ TrackersAdditionDialog::~TrackersAdditionDialog()
|
|||
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 int baseTier = !currentTrackers.isEmpty() ? (currentTrackers.last().tier + 1) : 0;
|
||||
|
||||
QList<BitTorrent::TrackerEntry> entries = BitTorrent::parseTrackerEntries(m_ui->textEditTrackersList->toPlainText());
|
||||
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);
|
||||
}
|
||||
|
||||
m_torrent->addTrackers(entries);
|
||||
}
|
||||
|
@ -116,6 +137,13 @@ void TrackersAdditionDialog::onTorrentListDownloadFinished(const Net::DownloadRe
|
|||
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
|
||||
const QString existingText = m_ui->textEditTrackersList->toPlainText();
|
||||
if (!existingText.isEmpty() && !existingText.endsWith(u'\n'))
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
~TrackersAdditionDialog();
|
||||
|
||||
private slots:
|
||||
void onAccepted() const;
|
||||
void onAccepted();
|
||||
void onDownloadButtonClicked();
|
||||
void onTorrentListDownloadFinished(const Net::DownloadResult &result);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue