pass http/auth when downloading icons too for tt rss

This commit is contained in:
Martin Rotter 2022-01-12 09:07:14 +01:00
parent 30b30cbf1e
commit 45afba57e3
9 changed files with 28 additions and 7 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.1.2" date="2022-01-10"/> <release version="4.1.2" date="2022-01-12"/>
</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

@ -144,8 +144,11 @@ QString NetworkFactory::sanitizeUrl(const QString& url) {
{}); {});
} }
QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<QPair<QString, bool>>& urls, int timeout, QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<QPair<QString, bool>>& urls,
QIcon& output, const QNetworkProxy& custom_proxy) { int timeout,
QIcon& output,
const QList<QPair<QByteArray, QByteArray>>& additional_headers,
const QNetworkProxy& custom_proxy) {
QNetworkReply::NetworkError network_result = QNetworkReply::NetworkError::UnknownNetworkError; QNetworkReply::NetworkError network_result = QNetworkReply::NetworkError::UnknownNetworkError;
for (const auto& url : urls) { for (const auto& url : urls) {
@ -162,7 +165,7 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<QPair<QStri
{}, {},
icon_data, icon_data,
QNetworkAccessManager::Operation::GetOperation, QNetworkAccessManager::Operation::GetOperation,
{}, additional_headers,
false, false,
{}, {},
{}, {},

View file

@ -35,6 +35,7 @@ class NetworkFactory {
static QNetworkReply::NetworkError downloadIcon(const QList<QPair<QString, bool>>& urls, static QNetworkReply::NetworkError downloadIcon(const QList<QPair<QString, bool>>& urls,
int timeout, int timeout,
QIcon& output, QIcon& output,
const QList<QPair<QByteArray, QByteArray>>& additional_headers,
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy); const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
static NetworkResult performNetworkOperation(const QString& url, int timeout, static NetworkResult performNetworkOperation(const QString& url, int timeout,
const QByteArray& input_data, const QByteArray& input_data,

View file

@ -376,6 +376,7 @@ RootItem* FeedlyNetwork::decodeCollections(const QByteArray& json, bool obtain_i
{ fee_obj[QSL("logo")].toString(), true } }, { fee_obj[QSL("logo")].toString(), true } },
timeout, timeout,
icon, icon,
{},
proxy); proxy);
if (result == QNetworkReply::NetworkError::NoError && !icon.isNull()) { if (result == QNetworkReply::NetworkError::NoError && !icon.isNull()) {

View file

@ -784,6 +784,7 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con
if (NetworkFactory::downloadIcon(icon_urls, if (NetworkFactory::downloadIcon(icon_urls,
1000, 1000,
icon, icon,
{},
proxy) == QNetworkReply::NetworkError::NoError) { proxy) == QNetworkReply::NetworkError::NoError) {
feed->setIcon(icon); feed->setIcon(icon);
} }

View file

@ -448,6 +448,7 @@ StandardFeed* StandardFeed::guessFeed(StandardFeed::SourceType source_type,
if (NetworkFactory::downloadIcon(icon_possible_locations, if (NetworkFactory::downloadIcon(icon_possible_locations,
DOWNLOAD_TIMEOUT, DOWNLOAD_TIMEOUT,
icon_data, icon_data,
{},
custom_proxy) == QNetworkReply::NetworkError::NoError) { custom_proxy) == QNetworkReply::NetworkError::NoError) {
// Icon for feed was downloaded and is stored now in _icon_data. // Icon for feed was downloaded and is stored now in _icon_data.
feed->setIcon(icon_data); feed->setIcon(icon_data);

View file

@ -677,7 +677,10 @@ TtRssGetFeedsCategoriesResponse::TtRssGetFeedsCategoriesResponse(const QString&
TtRssGetFeedsCategoriesResponse::~TtRssGetFeedsCategoriesResponse() = default; TtRssGetFeedsCategoriesResponse::~TtRssGetFeedsCategoriesResponse() = default;
RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, const QNetworkProxy& proxy, const QString& base_address) const { RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(TtRssNetworkFactory* network,
bool obtain_icons,
const QNetworkProxy& proxy,
const QString& base_address) const {
auto* parent = new RootItem(); auto* parent = new RootItem();
// Chop the "api/" from the end of the address. // Chop the "api/" from the end of the address.
@ -740,9 +743,17 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, co
// Chop the "api/" suffix out and append // Chop the "api/" suffix out and append
QString full_icon_address = base_address + QL1C('/') + icon_path; QString full_icon_address = base_address + QL1C('/') + icon_path;
QIcon icon; QIcon icon;
QList<QPair<QByteArray, QByteArray>> headers;
if (network->authIsUsed()) {
headers << NetworkFactory::generateBasicAuthHeader(network->authUsername(),
network->authPassword());
}
auto res = NetworkFactory::downloadIcon({ { full_icon_address, true } }, auto res = NetworkFactory::downloadIcon({ { full_icon_address, true } },
DOWNLOAD_TIMEOUT, DOWNLOAD_TIMEOUT,
icon, icon,
headers,
proxy); proxy);
if (res == QNetworkReply::NoError) { if (res == QNetworkReply::NoError) {

View file

@ -48,6 +48,8 @@ class TtRssGetLabelsResponse : public TtRssResponse {
QList<RootItem*> labels() const; QList<RootItem*> labels() const;
}; };
class TtRssNetworkFactory;
class TtRssGetFeedsCategoriesResponse : public TtRssResponse { class TtRssGetFeedsCategoriesResponse : public TtRssResponse {
public: public:
explicit TtRssGetFeedsCategoriesResponse(const QString& raw_content = QString()); explicit TtRssGetFeedsCategoriesResponse(const QString& raw_content = QString());
@ -56,7 +58,8 @@ class TtRssGetFeedsCategoriesResponse : public TtRssResponse {
// Returns tree of feeds/categories. // Returns tree of feeds/categories.
// Top-level root of the tree is not needed here. // Top-level root of the tree is not needed here.
// Returned items do not have primary IDs assigned. // Returned items do not have primary IDs assigned.
RootItem* feedsCategories(bool obtain_icons, const QNetworkProxy& proxy, const QString& base_address = QString()) const; RootItem* feedsCategories(TtRssNetworkFactory* network, bool obtain_icons,
const QNetworkProxy& proxy, const QString& base_address = QString()) const;
}; };
class ServiceRoot; class ServiceRoot;

View file

@ -275,7 +275,7 @@ RootItem* TtRssServiceRoot::obtainNewTreeForSyncIn() const {
TtRssGetLabelsResponse labels = m_network->getLabels(networkProxy()); TtRssGetLabelsResponse labels = m_network->getLabels(networkProxy());
if (m_network->lastError() == QNetworkReply::NoError) { if (m_network->lastError() == QNetworkReply::NoError) {
auto* tree = feed_cats.feedsCategories(true, networkProxy(), m_network->url()); auto* tree = feed_cats.feedsCategories(m_network, true, networkProxy(), m_network->url());
auto* lblroot = new LabelsNode(tree); auto* lblroot = new LabelsNode(tree);
lblroot->setChildItems(labels.labels()); lblroot->setChildItems(labels.labels());