properly resolve all URLs
This commit is contained in:
parent
6bde01321f
commit
521eb92935
@ -26,7 +26,7 @@
|
||||
<url type="donation">https://github.com/sponsors/martinrotter</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="4.2.2" date="2022-05-04"/>
|
||||
<release version="4.2.2" date="2022-05-06"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -281,7 +281,8 @@ void FeedMessageViewer::initialize() {
|
||||
m_toolBarMessages->setFloatable(false);
|
||||
m_toolBarMessages->setMovable(false);
|
||||
m_toolBarMessages->setAllowedAreas(Qt::ToolBarArea::TopToolBarArea);
|
||||
m_messagesBrowser->clear();
|
||||
|
||||
// m_messagesBrowser->clear();
|
||||
|
||||
// Now refresh visual setup.
|
||||
refreshVisualProperties();
|
||||
|
@ -66,19 +66,21 @@ QVariant TextBrowserViewer::loadOneResource(int type, const QUrl& name) {
|
||||
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.
|
||||
return m_placeholderImage;
|
||||
}
|
||||
|
||||
// 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()) {
|
||||
return m_placeholderImageError;
|
||||
}
|
||||
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()) {
|
||||
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)) {
|
||||
found_resources.append(captured_url);
|
||||
|
@ -90,9 +90,9 @@ class TextBrowserViewer : public QTextBrowser, public WebViewer {
|
||||
|
||||
private:
|
||||
bool m_resourcesEnabled;
|
||||
QList<QUrl> m_neededResources;
|
||||
QList<QUrl> m_neededResources; // All URLs here must be resolved.
|
||||
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_placeholderImageError;
|
||||
|
||||
|
@ -142,6 +142,12 @@ void Downloader::finished() {
|
||||
|
||||
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.
|
||||
QUrl redirection_url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
|
||||
|
||||
@ -180,6 +186,10 @@ void Downloader::finished() {
|
||||
else if (reply_operation == QNetworkAccessManager::DeleteOperation) {
|
||||
runDeleteRequest(request);
|
||||
}
|
||||
|
||||
if (m_activeReply != nullptr) {
|
||||
m_activeReply->setProperty("original_url", original_url);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 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_lastOutputError = reply->error();
|
||||
|
||||
// original_url = m_activeReply->property("original_url").toUrl();
|
||||
|
||||
m_activeReply->deleteLater();
|
||||
m_activeReply = nullptr;
|
||||
|
||||
@ -211,7 +224,7 @@ void Downloader::finished() {
|
||||
m_inputMultipartData->deleteLater();
|
||||
}
|
||||
|
||||
emit completed(reply->request().url(), m_lastOutputError, m_lastOutputData);
|
||||
emit completed(original_url, m_lastOutputError, m_lastOutputData);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user