properly resolve all URLs

This commit is contained in:
Martin Rotter 2022-05-06 10:04:06 +02:00
parent 6bde01321f
commit 521eb92935
5 changed files with 25 additions and 9 deletions

View File

@ -26,7 +26,7 @@
<url type="donation">https://github.com/sponsors/martinrotter</url> <url type="donation">https://github.com/sponsors/martinrotter</url>
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="4.2.2" date="2022-05-04"/> <release version="4.2.2" date="2022-05-06"/>
</releases> </releases>
<content_rating type="oars-1.0"> <content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute> <content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -281,7 +281,8 @@ void FeedMessageViewer::initialize() {
m_toolBarMessages->setFloatable(false); m_toolBarMessages->setFloatable(false);
m_toolBarMessages->setMovable(false); m_toolBarMessages->setMovable(false);
m_toolBarMessages->setAllowedAreas(Qt::ToolBarArea::TopToolBarArea); m_toolBarMessages->setAllowedAreas(Qt::ToolBarArea::TopToolBarArea);
m_messagesBrowser->clear();
// m_messagesBrowser->clear();
// Now refresh visual setup. // Now refresh visual setup.
refreshVisualProperties(); refreshVisualProperties();

View File

@ -66,19 +66,21 @@ QVariant TextBrowserViewer::loadOneResource(int type, const QUrl& name) {
return {}; return {};
} }
if (!m_resourcesEnabled || !m_loadedResources.contains(name)) { auto resolved_name = m_currentUrl.isValid() ? m_currentUrl.resolved(name) : name;
if (!m_resourcesEnabled || !m_loadedResources.contains(resolved_name)) {
// Resources are not enabled. // Resources are not enabled.
return m_placeholderImage; return m_placeholderImage;
} }
// Resources are enabled and we already have the resource. // Resources are enabled and we already have the resource.
QByteArray resource_data = m_loadedResources.value(name); QByteArray resource_data = m_loadedResources.value(resolved_name);
if (resource_data.isEmpty()) { if (resource_data.isEmpty()) {
return m_placeholderImageError; return m_placeholderImageError;
} }
else { else {
return QImage::fromData(m_loadedResources.value(name)); return QImage::fromData(m_loadedResources.value(resolved_name));
} }
} }
@ -439,7 +441,7 @@ void TextBrowserViewer::setHtml(const QString& html, const QUrl& base_url) {
while (i.hasNext()) { while (i.hasNext()) {
QRegularExpressionMatch match = i.next(); QRegularExpressionMatch match = i.next();
auto captured_url = match.captured(1); auto captured_url = base_url.isValid() ? base_url.resolved(QUrl(match.captured(1))) : QUrl(match.captured(1));
if (!found_resources.contains(captured_url)) { if (!found_resources.contains(captured_url)) {
found_resources.append(captured_url); found_resources.append(captured_url);

View File

@ -90,9 +90,9 @@ class TextBrowserViewer : public QTextBrowser, public WebViewer {
private: private:
bool m_resourcesEnabled; bool m_resourcesEnabled;
QList<QUrl> m_neededResources; QList<QUrl> m_neededResources; // All URLs here must be resolved.
QScopedPointer<Downloader> m_resourceDownloader; QScopedPointer<Downloader> m_resourceDownloader;
QMap<QUrl, QByteArray> m_loadedResources; QMap<QUrl, QByteArray> m_loadedResources; // All URLs here must be resolved.
QPixmap m_placeholderImage; QPixmap m_placeholderImage;
QPixmap m_placeholderImageError; QPixmap m_placeholderImageError;

View File

@ -142,6 +142,12 @@ void Downloader::finished() {
m_timer->stop(); m_timer->stop();
QUrl original_url = reply->property("original_url").toUrl();
if (!original_url.isValid()) {
original_url = reply->request().url();
}
// In this phase, some part of downloading process is completed. // In this phase, some part of downloading process is completed.
QUrl redirection_url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); QUrl redirection_url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
@ -180,6 +186,10 @@ void Downloader::finished() {
else if (reply_operation == QNetworkAccessManager::DeleteOperation) { else if (reply_operation == QNetworkAccessManager::DeleteOperation) {
runDeleteRequest(request); runDeleteRequest(request);
} }
if (m_activeReply != nullptr) {
m_activeReply->setProperty("original_url", original_url);
}
} }
else { else {
// No redirection is indicated. Final file is obtained in our "reply" object. // No redirection is indicated. Final file is obtained in our "reply" object.
@ -204,6 +214,9 @@ void Downloader::finished() {
m_lastContentType = reply->header(QNetworkRequest::ContentTypeHeader); m_lastContentType = reply->header(QNetworkRequest::ContentTypeHeader);
m_lastOutputError = reply->error(); m_lastOutputError = reply->error();
// original_url = m_activeReply->property("original_url").toUrl();
m_activeReply->deleteLater(); m_activeReply->deleteLater();
m_activeReply = nullptr; m_activeReply = nullptr;
@ -211,7 +224,7 @@ void Downloader::finished() {
m_inputMultipartData->deleteLater(); m_inputMultipartData->deleteLater();
} }
emit completed(reply->request().url(), m_lastOutputError, m_lastOutputData); emit completed(original_url, m_lastOutputError, m_lastOutputData);
} }
} }