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>
<content_rating type="oars-1.1" />
<releases>
<release version="4.1.2" date="2022-01-10"/>
<release version="4.1.2" date="2022-01-12"/>
</releases>
<content_rating type="oars-1.0">
<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,
QIcon& output, const QNetworkProxy& custom_proxy) {
QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<QPair<QString, bool>>& urls,
int timeout,
QIcon& output,
const QList<QPair<QByteArray, QByteArray>>& additional_headers,
const QNetworkProxy& custom_proxy) {
QNetworkReply::NetworkError network_result = QNetworkReply::NetworkError::UnknownNetworkError;
for (const auto& url : urls) {
@ -162,7 +165,7 @@ QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QList<QPair<QStri
{},
icon_data,
QNetworkAccessManager::Operation::GetOperation,
{},
additional_headers,
false,
{},
{},

View File

@ -35,6 +35,7 @@ class NetworkFactory {
static QNetworkReply::NetworkError downloadIcon(const QList<QPair<QString, bool>>& urls,
int timeout,
QIcon& output,
const QList<QPair<QByteArray, QByteArray>>& additional_headers,
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
static NetworkResult performNetworkOperation(const QString& url, int timeout,
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 } },
timeout,
icon,
{},
proxy);
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,
1000,
icon,
{},
proxy) == QNetworkReply::NetworkError::NoError) {
feed->setIcon(icon);
}

View File

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

View File

@ -677,7 +677,10 @@ TtRssGetFeedsCategoriesResponse::TtRssGetFeedsCategoriesResponse(const QString&
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();
// 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
QString full_icon_address = base_address + QL1C('/') + icon_path;
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 } },
DOWNLOAD_TIMEOUT,
icon,
headers,
proxy);
if (res == QNetworkReply::NoError) {

View File

@ -48,6 +48,8 @@ class TtRssGetLabelsResponse : public TtRssResponse {
QList<RootItem*> labels() const;
};
class TtRssNetworkFactory;
class TtRssGetFeedsCategoriesResponse : public TtRssResponse {
public:
explicit TtRssGetFeedsCategoriesResponse(const QString& raw_content = QString());
@ -56,7 +58,8 @@ class TtRssGetFeedsCategoriesResponse : public TtRssResponse {
// Returns tree of feeds/categories.
// Top-level root of the tree is not needed here.
// 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;

View File

@ -275,7 +275,7 @@ RootItem* TtRssServiceRoot::obtainNewTreeForSyncIn() const {
TtRssGetLabelsResponse labels = m_network->getLabels(networkProxy());
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);
lblroot->setChildItems(labels.labels());