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 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,
@ -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);
@ -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,

View File

@ -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());
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());
@ -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;
@ -406,7 +411,7 @@ StandardFeed* StandardFeed::guessFeed(StandardFeed::SourceType source_type,
}
}
return feed;
return {feed, network_result};
}
Qt::ItemFlags StandardFeed::additionalFlags() const {

View File

@ -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);

View File

@ -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);
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->setSourceType(source_type);
new_feed->setSource(feed_lookup.url);
new_feed->setPostProcessScript(pp_script);
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();