replace original URL with redirected/final URL when guessing feed

This commit is contained in:
Martin Rotter 2024-11-12 14:33:59 +01:00
parent 793cbcbf58
commit 78dc97f23f
4 changed files with 84 additions and 72 deletions

View File

@ -146,24 +146,24 @@ void StandardFeedDetails::guessIconOnly(StandardFeed::SourceType source_type,
const QList<QPair<QByteArray, QByteArray>>& headers, const QList<QPair<QByteArray, QByteArray>>& headers,
const QNetworkProxy& custom_proxy) { const QNetworkProxy& custom_proxy) {
try { try {
StandardFeed* metadata = StandardFeed::guessFeed(source_type, auto metadata = StandardFeed::guessFeed(source_type,
source, source,
post_process_script, post_process_script,
protection, protection,
true, true,
username, username,
password, password,
{}, {},
custom_proxy); custom_proxy);
// Icon or whole feed was guessed. // 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, m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Icon fetched successfully."), tr("Icon fetched successfully."),
tr("Icon metadata fetched.")); tr("Icon metadata fetched."));
// Remove temporary feed object. // Remove temporary feed object.
metadata->deleteLater(); metadata.first->deleteLater();
} }
catch (const ScriptException& ex) { catch (const ScriptException& ex) {
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error, m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,
@ -191,22 +191,27 @@ void StandardFeedDetails::guessFeed(StandardFeed::SourceType source_type,
const QList<QPair<QByteArray, QByteArray>>& headers, const QList<QPair<QByteArray, QByteArray>>& headers,
const QNetworkProxy& custom_proxy) { const QNetworkProxy& custom_proxy) {
try { try {
StandardFeed* metadata = StandardFeed::guessFeed(source_type, auto metadata = StandardFeed::guessFeed(source_type,
source, source,
post_process_script, post_process_script,
protection, protection,
true, true,
username, username,
password, password,
headers, headers,
custom_proxy); custom_proxy);
// Icon or whole feed was guessed. // Icon or whole feed was guessed.
m_ui.m_btnIcon->setIcon(metadata->icon()); m_ui.m_btnIcon->setIcon(metadata.first->icon());
m_ui.m_txtTitle->lineEdit()->setText(metadata->sanitizedTitle()); m_ui.m_txtTitle->lineEdit()->setText(metadata.first->sanitizedTitle());
m_ui.m_txtDescription->lineEdit()->setText(metadata->description()); m_ui.m_txtDescription->lineEdit()->setText(metadata.first->description());
m_ui.m_cmbType->setCurrentIndex(m_ui.m_cmbType->findData(QVariant::fromValue((int)metadata->type()))); m_ui.m_cmbType->setCurrentIndex(m_ui.m_cmbType->findData(QVariant::fromValue((int)metadata.first->type())));
int encoding_index = m_ui.m_cmbEncoding->findText(metadata->encoding(), Qt::MatchFlag::MatchFixedString);
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) { if (encoding_index >= 0) {
m_ui.m_cmbEncoding->setCurrentIndex(encoding_index); m_ui.m_cmbEncoding->setCurrentIndex(encoding_index);
@ -221,7 +226,7 @@ void StandardFeedDetails::guessFeed(StandardFeed::SourceType source_type,
tr("Feed and icon metadata fetched.")); tr("Feed and icon metadata fetched."));
// Remove temporary feed object. // Remove temporary feed object.
metadata->deleteLater(); metadata.first->deleteLater();
} }
catch (const ScriptException& ex) { catch (const ScriptException& ex) {
m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error, m_ui.m_lblFetchMetadata->setStatus(WidgetWithStatus::StatusType::Error,

View File

@ -230,24 +230,28 @@ QString StandardFeed::sourceTypeToString(StandardFeed::SourceType type) {
void StandardFeed::fetchMetadataForItself() { void StandardFeed::fetchMetadataForItself() {
try { try {
StandardFeed* metadata = guessFeed(sourceType(), auto metadata = guessFeed(sourceType(),
source(), source(),
postProcessScript(), postProcessScript(),
protection(), protection(),
true, true,
username(), username(),
password(), password(),
{}, {},
getParentServiceRoot()->networkProxy()); getParentServiceRoot()->networkProxy());
// Copy metadata to our object. // Copy metadata to our object.
setTitle(metadata->title()); setTitle(metadata.first->title());
setDescription(metadata->description()); setDescription(metadata.first->description());
setType(metadata->type()); setType(metadata.first->type());
setEncoding(metadata->encoding()); setEncoding(metadata.first->encoding());
setIcon(metadata->icon()); setIcon(metadata.first->icon());
metadata->deleteLater(); if (metadata.second.m_url.isValid()) {
setSource(metadata.second.m_url.toString());
}
metadata.first->deleteLater();
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
@ -279,15 +283,16 @@ void StandardFeed::setSourceType(SourceType source_type) {
m_sourceType = source_type; m_sourceType = source_type;
} }
StandardFeed* StandardFeed::guessFeed(StandardFeed::SourceType source_type, QPair<StandardFeed*, NetworkResult> StandardFeed::guessFeed(StandardFeed::SourceType source_type,
const QString& source, const QString& source,
const QString& post_process_script, const QString& post_process_script,
NetworkFactory::NetworkFactory::NetworkAuthentication protection, NetworkFactory::NetworkFactory::NetworkAuthentication
bool fetch_icons, protection,
const QString& username, bool fetch_icons,
const QString& password, const QString& username,
const QList<QPair<QByteArray, QByteArray>>& http_headers, const QString& password,
const QNetworkProxy& custom_proxy) { const QList<QPair<QByteArray, QByteArray>>& http_headers,
const QNetworkProxy& custom_proxy) {
auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt(); auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
QByteArray feed_contents; QByteArray feed_contents;
NetworkResult network_result; NetworkResult network_result;
@ -406,7 +411,7 @@ StandardFeed* StandardFeed::guessFeed(StandardFeed::SourceType source_type,
} }
} }
return feed; return {feed, network_result};
} }
Qt::ItemFlags StandardFeed::additionalFlags() const { Qt::ItemFlags StandardFeed::additionalFlags() const {

View File

@ -79,15 +79,16 @@ class StandardFeed : public Feed {
// Returns pointer to guessed feed (if at least partially // Returns pointer to guessed feed (if at least partially
// guessed) and retrieved error/status code from network layer // guessed) and retrieved error/status code from network layer
// or nullptr feed. // or nullptr feed.
static StandardFeed* guessFeed(SourceType source_type, static QPair<StandardFeed*, NetworkResult> guessFeed(SourceType source_type,
const QString& url, const QString& url,
const QString& post_process_script, const QString& post_process_script,
NetworkFactory::NetworkAuthentication protection, NetworkFactory::NetworkAuthentication protection,
bool fetch_icons = true, bool fetch_icons = true,
const QString& username = {}, const QString& username = {},
const QString& password = {}, const QString& password = {},
const QList<QPair<QByteArray, QByteArray>>& http_headers = {}, const QList<QPair<QByteArray, QByteArray>>& http_headers = {},
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy); const QNetworkProxy& custom_proxy =
QNetworkProxy::ProxyType::DefaultProxy);
// Converts particular feed type to string. // Converts particular feed type to string.
static QString typeToString(Type type); static QString typeToString(Type type);

View File

@ -196,19 +196,20 @@ bool FeedsImportExportModel::produceFeed(const FeedLookup& feed_lookup) {
: feed_lookup.post_process_script; : feed_lookup.post_process_script;
try { try {
new_feed = StandardFeed::guessFeed(source_type, auto new_feed_data = StandardFeed::guessFeed(source_type,
feed_lookup.url, feed_lookup.url,
pp_script, pp_script,
NetworkFactory::NetworkAuthentication::NoAuthentication, NetworkFactory::NetworkAuthentication::NoAuthentication,
!feed_lookup.do_not_fetch_icons, !feed_lookup.do_not_fetch_icons,
{}, {},
{}, {},
{}, {},
feed_lookup.custom_proxy); feed_lookup.custom_proxy);
new_feed->setSourceType(source_type); new_feed_data.first->setSourceType(source_type);
new_feed->setSource(feed_lookup.url); new_feed_data.first->setPostProcessScript(pp_script);
new_feed->setPostProcessScript(pp_script);
new_feed = new_feed_data.first;
if (feed_lookup.do_not_fetch_titles) { if (feed_lookup.do_not_fetch_titles) {
QString old_title = feed_lookup.custom_data[QSL("title")].toString(); QString old_title = feed_lookup.custom_data[QSL("title")].toString();