Skip to content

Commit

Permalink
replace original URL with redirected/final URL when guessing feed
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Nov 12, 2024
1 parent 793cbcb commit 78dc97f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 73 deletions.
57 changes: 31 additions & 26 deletions src/librssguard-standard/src/gui/standardfeeddetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,24 @@ void StandardFeedDetails::guessIconOnly(StandardFeed::SourceType source_type,
const QList<QPair<QByteArray, QByteArray>>& headers,
const QNetworkProxy& custom_proxy) {
try {
StandardFeed* metadata = StandardFeed::guessFeed(source_type,
source,
post_process_script,
protection,
true,
username,
password,
{},
custom_proxy);
auto metadata = StandardFeed::guessFeed(source_type,
source,
post_process_script,
protection,
true,
username,
password,
{},
custom_proxy);

// Icon or whole feed was guessed.
m_ui.m_btnIcon->setIcon(metadata->icon());
m_ui.m_btnIcon->setIcon(metadata.first->icon());
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Icon fetched successfully."),
tr("Icon metadata fetched."));

// Remove temporary feed object.
metadata->deleteLater();
metadata.first->deleteLater();
}
catch (const ScriptException& ex) {
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,
Expand Down Expand Up @@ -191,22 +191,27 @@ void StandardFeedDetails::guessFeed(StandardFeed::SourceType source_type,
const QList<QPair<QByteArray, QByteArray>>& headers,
const QNetworkProxy& custom_proxy) {
try {
StandardFeed* metadata = StandardFeed::guessFeed(source_type,
source,
post_process_script,
protection,
true,
username,
password,
headers,
custom_proxy);
auto metadata = StandardFeed::guessFeed(source_type,
source,
post_process_script,
protection,
true,
username,
password,
headers,
custom_proxy);

// Icon or whole feed was guessed.
m_ui.m_btnIcon->setIcon(metadata->icon());
m_ui.m_txtTitle->lineEdit()->setText(metadata->sanitizedTitle());
m_ui.m_txtDescription->lineEdit()->setText(metadata->description());
m_ui.m_cmbType->setCurrentIndex(m_ui.m_cmbType->findData(QVariant::fromValue((int)metadata->type())));
int encoding_index = m_ui.m_cmbEncoding->findText(metadata->encoding(), Qt::MatchFlag::MatchFixedString);
m_ui.m_btnIcon->setIcon(metadata.first->icon());
m_ui.m_txtTitle->lineEdit()->setText(metadata.first->sanitizedTitle());
m_ui.m_txtDescription->lineEdit()->setText(metadata.first->description());
m_ui.m_cmbType->setCurrentIndex(m_ui.m_cmbType->findData(QVariant::fromValue((int)metadata.first->type())));

if (metadata.second.m_url.isValid()) {
m_ui.m_txtSource->textEdit()->setPlainText(metadata.second.m_url.toString());
}

int encoding_index = m_ui.m_cmbEncoding->findText(metadata.first->encoding(), Qt::MatchFlag::MatchFixedString);

if (encoding_index >= 0) {
m_ui.m_cmbEncoding->setCurrentIndex(encoding_index);
Expand All @@ -221,7 +226,7 @@ void StandardFeedDetails::guessFeed(StandardFeed::SourceType source_type,
tr("Feed and icon metadata fetched."));

// Remove temporary feed object.
metadata->deleteLater();
metadata.first->deleteLater();
}
catch (const ScriptException& ex) {
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,
Expand Down
55 changes: 30 additions & 25 deletions src/librssguard-standard/src/standardfeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,24 +230,28 @@ QString StandardFeed::sourceTypeToString(StandardFeed::SourceType type) {

void StandardFeed::fetchMetadataForItself() {
try {
StandardFeed* metadata = guessFeed(sourceType(),
source(),
postProcessScript(),
protection(),
true,
username(),
password(),
{},
getParentServiceRoot()->networkProxy());
auto metadata = guessFeed(sourceType(),
source(),
postProcessScript(),
protection(),
true,
username(),
password(),
{},
getParentServiceRoot()->networkProxy());

// Copy metadata to our object.
setTitle(metadata->title());
setDescription(metadata->description());
setType(metadata->type());
setEncoding(metadata->encoding());
setIcon(metadata->icon());
setTitle(metadata.first->title());
setDescription(metadata.first->description());
setType(metadata.first->type());
setEncoding(metadata.first->encoding());
setIcon(metadata.first->icon());

if (metadata.second.m_url.isValid()) {
setSource(metadata.second.m_url.toString());
}

metadata->deleteLater();
metadata.first->deleteLater();

QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());

Expand Down Expand Up @@ -279,15 +283,16 @@ void StandardFeed::setSourceType(SourceType source_type) {
m_sourceType = source_type;
}

StandardFeed* StandardFeed::guessFeed(StandardFeed::SourceType source_type,
const QString& source,
const QString& post_process_script,
NetworkFactory::NetworkFactory::NetworkAuthentication protection,
bool fetch_icons,
const QString& username,
const QString& password,
const QList<QPair<QByteArray, QByteArray>>& http_headers,
const QNetworkProxy& custom_proxy) {
QPair<StandardFeed*, NetworkResult> StandardFeed::guessFeed(StandardFeed::SourceType source_type,
const QString& source,
const QString& post_process_script,
NetworkFactory::NetworkFactory::NetworkAuthentication
protection,
bool fetch_icons,
const QString& username,
const QString& password,
const QList<QPair<QByteArray, QByteArray>>& http_headers,
const QNetworkProxy& custom_proxy) {
auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
QByteArray feed_contents;
NetworkResult network_result;
Expand Down Expand Up @@ -406,7 +411,7 @@ StandardFeed* StandardFeed::guessFeed(StandardFeed::SourceType source_type,
}
}

return feed;
return {feed, network_result};
}

Qt::ItemFlags StandardFeed::additionalFlags() const {
Expand Down
19 changes: 10 additions & 9 deletions src/librssguard-standard/src/standardfeed.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ class StandardFeed : public Feed {
// Returns pointer to guessed feed (if at least partially
// guessed) and retrieved error/status code from network layer
// or nullptr feed.
static StandardFeed* guessFeed(SourceType source_type,
const QString& url,
const QString& post_process_script,
NetworkFactory::NetworkAuthentication protection,
bool fetch_icons = true,
const QString& username = {},
const QString& password = {},
const QList<QPair<QByteArray, QByteArray>>& http_headers = {},
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
static QPair<StandardFeed*, NetworkResult> guessFeed(SourceType source_type,
const QString& url,
const QString& post_process_script,
NetworkFactory::NetworkAuthentication protection,
bool fetch_icons = true,
const QString& username = {},
const QString& password = {},
const QList<QPair<QByteArray, QByteArray>>& http_headers = {},
const QNetworkProxy& custom_proxy =
QNetworkProxy::ProxyType::DefaultProxy);

// Converts particular feed type to string.
static QString typeToString(Type type);
Expand Down
27 changes: 14 additions & 13 deletions src/librssguard-standard/src/standardfeedsimportexportmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,20 @@ bool FeedsImportExportModel::produceFeed(const FeedLookup& feed_lookup) {
: feed_lookup.post_process_script;

try {
new_feed = StandardFeed::guessFeed(source_type,
feed_lookup.url,
pp_script,
NetworkFactory::NetworkAuthentication::NoAuthentication,
!feed_lookup.do_not_fetch_icons,
{},
{},
{},
feed_lookup.custom_proxy);

new_feed->setSourceType(source_type);
new_feed->setSource(feed_lookup.url);
new_feed->setPostProcessScript(pp_script);
auto new_feed_data = StandardFeed::guessFeed(source_type,
feed_lookup.url,
pp_script,
NetworkFactory::NetworkAuthentication::NoAuthentication,
!feed_lookup.do_not_fetch_icons,
{},
{},
{},
feed_lookup.custom_proxy);

new_feed_data.first->setSourceType(source_type);
new_feed_data.first->setPostProcessScript(pp_script);

new_feed = new_feed_data.first;

if (feed_lookup.do_not_fetch_titles) {
QString old_title = feed_lookup.custom_data[QSL("title")].toString();
Expand Down

0 comments on commit 78dc97f

Please sign in to comment.