This commit is contained in:
Bark 2025-07-03 00:00:32 +03:00 committed by GitHub
commit 78f9bc0514
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 2 deletions

View file

@ -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;

View file

@ -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())
{

View file

@ -104,6 +104,7 @@ namespace Net
QString url;
DownloadStatus status = DownloadStatus::Failed;
QString errorString;
QString contentType;
QByteArray data;
Path filePath;
QString magnetURI;

View file

@ -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'))

View file

@ -58,7 +58,7 @@ public:
~TrackersAdditionDialog();
private slots:
void onAccepted() const;
void onAccepted();
void onDownloadButtonClicked();
void onTorrentListDownloadFinished(const Net::DownloadResult &result);