From f24f03e6df14e19396970ac739b71273aef7727a Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 3 Feb 2021 12:13:27 +0100 Subject: [PATCH] reedah tested with greader plugin. --- .../miscellaneous/databasequeries.cpp | 53 ++++++++++--------- .../miscellaneous/databasequeries.h | 3 +- .../services/greader/definitions.h | 2 +- .../services/greader/greadernetwork.cpp | 53 ++++++++++++++++--- .../services/greader/greadernetwork.h | 4 +- .../services/greader/greaderserviceroot.cpp | 5 +- .../services/greader/greaderserviceroot.h | 4 +- .../greader/gui/greaderaccountdetails.cpp | 4 +- 8 files changed, 87 insertions(+), 41 deletions(-) diff --git a/src/librssguard/miscellaneous/databasequeries.cpp b/src/librssguard/miscellaneous/databasequeries.cpp index 7db3a442e..f990d43d1 100755 --- a/src/librssguard/miscellaneous/databasequeries.cpp +++ b/src/librssguard/miscellaneous/databasequeries.cpp @@ -1812,32 +1812,6 @@ bool DatabaseQueries::deleteOwnCloudAccount(const QSqlDatabase& db, int account_ return q.exec(); } -bool DatabaseQueries::overwriteGreaderAccount(const QSqlDatabase& db, const QString& username, const QString& password, - const QString& url, int batch_size, int account_id) { - QSqlQuery query(db); - - query.prepare("UPDATE GoogleReaderApiAccounts " - "SET username = :username, password = :password, url = :url, " - "msg_limit = :msg_limit " - "WHERE id = :id;"); - query.bindValue(QSL(":username"), username); - query.bindValue(QSL(":password"), TextFactory::encrypt(password)); - query.bindValue(QSL(":url"), url); - query.bindValue(QSL(":id"), account_id); - query.bindValue(QSL(":msg_limit"), batch_size <= 0 ? GREADER_UNLIMITED_BATCH_SIZE : batch_size); - - if (query.exec()) { - return true; - } - else { - qWarningNN << LOGSEC_GREADER - << "Updating account failed: '" - << query.lastError().text() - << "'."; - return false; - } -} - bool DatabaseQueries::overwriteOwnCloudAccount(const QSqlDatabase& db, const QString& username, const QString& password, const QString& url, bool force_server_side_feed_update, int batch_size, bool download_only_unread_messages, int account_id) { @@ -1893,6 +1867,33 @@ bool DatabaseQueries::createGreaderAccount(const QSqlDatabase& db, int id_to_ass } } +bool DatabaseQueries::overwriteGreaderAccount(const QSqlDatabase& db, const QString& username, const QString& password, + GreaderServiceRoot::Service service, const QString& url, + int batch_size, int account_id) { + QSqlQuery query(db); + + query.prepare("UPDATE GoogleReaderApiAccounts " + "SET username = :username, password = :password, url = :url, type = :service, msg_limit = :msg_limit " + "WHERE id = :id;"); + query.bindValue(QSL(":username"), username); + query.bindValue(QSL(":password"), TextFactory::encrypt(password)); + query.bindValue(QSL(":url"), url); + query.bindValue(QSL(":service"), int(service)); + query.bindValue(QSL(":id"), account_id); + query.bindValue(QSL(":msg_limit"), batch_size <= 0 ? GREADER_UNLIMITED_BATCH_SIZE : batch_size); + + if (query.exec()) { + return true; + } + else { + qWarningNN << LOGSEC_GREADER + << "Updating account failed: '" + << query.lastError().text() + << "'."; + return false; + } +} + bool DatabaseQueries::createOwnCloudAccount(const QSqlDatabase& db, int id_to_assign, const QString& username, const QString& password, const QString& url, bool force_server_side_feed_update, diff --git a/src/librssguard/miscellaneous/databasequeries.h b/src/librssguard/miscellaneous/databasequeries.h index 5c6335a96..433bb21d6 100644 --- a/src/librssguard/miscellaneous/databasequeries.h +++ b/src/librssguard/miscellaneous/databasequeries.h @@ -157,7 +157,8 @@ class DatabaseQueries { const QString& password, GreaderServiceRoot::Service service, const QString& url, int batch_size); static bool overwriteGreaderAccount(const QSqlDatabase& db, const QString& username, const QString& password, - const QString& url, int batch_size, int account_id); + GreaderServiceRoot::Service service, const QString& url, int batch_size, + int account_id); // Nextcloud account. static QList getOwnCloudAccounts(const QSqlDatabase& db, bool* ok = nullptr); diff --git a/src/librssguard/services/greader/definitions.h b/src/librssguard/services/greader/definitions.h index f7f75a923..e381806b4 100755 --- a/src/librssguard/services/greader/definitions.h +++ b/src/librssguard/services/greader/definitions.h @@ -18,10 +18,10 @@ #define GREADER_API_SUBSCRIPTION_LIST "reader/api/0/subscription/list?output=json" #define GREADER_API_STREAM_CONTENTS "reader/api/0/stream/contents/%1?output=json&n=%2" #define GREADER_API_EDIT_TAG "reader/api/0/edit-tag" +#define GREADER_API_TOKEN "reader/api/0/token" // Misc. #define GREADER_API_EDIT_TAG_BATCH 200 -#define GREADER_API_ANY_LABEL "user/-/label" // The Old Reader. #define TOR_SPONSORED_STREAM_ID "tor/sponsored" diff --git a/src/librssguard/services/greader/greadernetwork.cpp b/src/librssguard/services/greader/greadernetwork.cpp index 2c36cdf92..845ca86ef 100755 --- a/src/librssguard/services/greader/greadernetwork.cpp +++ b/src/librssguard/services/greader/greadernetwork.cpp @@ -62,6 +62,10 @@ QNetworkReply::NetworkError GreaderNetwork::editLabels(const QString& state, args += working_subset.join(QL1C('&')); + if (m_service == GreaderServiceRoot::Service::Reedah) { + args += QSL("&T=%1").arg(m_authToken); + } + // We send this batch. QByteArray output; auto result_edit = NetworkFactory::performNetworkOperation(full_url, @@ -103,7 +107,9 @@ QNetworkReply::NetworkError GreaderNetwork::markMessagesStarred(RootItem::Import QList GreaderNetwork::streamContents(ServiceRoot* root, const QString& stream_id, Feed::Status& error, const QNetworkProxy& proxy) { QString full_url = generateFullUrl(Operations::StreamContents).arg(stream_id, - QString::number(batchSize())); + QString::number(batchSize() <= 0 + ? 2000000 + : batchSize())); auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt(); if (!ensureLogin(proxy)) { @@ -190,7 +196,8 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con QList lbls; QJsonArray json; - if (m_service == GreaderServiceRoot::Service::Bazqux) { + if (m_service == GreaderServiceRoot::Service::Bazqux || + m_service == GreaderServiceRoot::Service::Reedah) { // We need to process subscription list first and extract categories. json = QJsonDocument::fromJson(feeds.toUtf8()).object()["subscriptions"].toArray(); @@ -223,9 +230,9 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con if ((label["type"].toString() == QL1S("folder")) || (m_service == GreaderServiceRoot::Service::TheOldReader && - label_id.startsWith(GREADER_API_ANY_LABEL))) { + label_id.contains(QSL("/label/")))) { - // We have label (not "state"). + // We have category (not "state" or "tag" or "label"). auto* category = new Category(); category->setDescription(label["htmlUrl"].toString()); @@ -242,7 +249,8 @@ RootItem* GreaderNetwork::decodeTagsSubscriptions(const QString& categories, con new_lbl->setCustomId(label_id); lbls.append(new_lbl); } - else if (m_service == GreaderServiceRoot::Service::Bazqux && + else if ((m_service == GreaderServiceRoot::Service::Bazqux || + m_service == GreaderServiceRoot::Service::Reedah) && label_id.contains(QSL("/label/"))) { if (!cats.contains(label_id)) { // This stream is not a category, it is label, bitches! @@ -357,7 +365,7 @@ QNetworkReply::NetworkError GreaderNetwork::clientLogin(const QNetworkProxy& pro } } - QRegularExpression exp("^(unused|none|null)$"); + QRegularExpression exp("^(NA|unused|none|null)$"); if (exp.match(m_authSid).hasMatch()) { m_authSid = QString(); @@ -371,6 +379,29 @@ QNetworkReply::NetworkError GreaderNetwork::clientLogin(const QNetworkProxy& pro clearCredentials(); return QNetworkReply::NetworkError::InternalServerError; } + + if (m_service == GreaderServiceRoot::Service::Reedah) { + // We need "T=" token for editing. + full_url = generateFullUrl(Operations::Token); + + network_result = NetworkFactory::performNetworkOperation(full_url, + timeout, + args, + output, + QNetworkAccessManager::Operation::GetOperation, + { authHeader() }, + false, + {}, + {}, + proxy); + + if (network_result.first == QNetworkReply::NetworkError::NoError) { + m_authToken = output; + } + else { + clearCredentials(); + } + } } return network_result.first; @@ -416,11 +447,14 @@ QString GreaderNetwork::serviceToString(GreaderServiceRoot::Service service) { case GreaderServiceRoot::Service::Bazqux: return QSL("Bazqux"); + case GreaderServiceRoot::Service::Reedah: + return QSL("Reedah"); + case GreaderServiceRoot::Service::TheOldReader: return QSL("The Old Reader"); default: - return tr("Unknown service"); + return tr("Other services"); } } @@ -534,7 +568,7 @@ void GreaderNetwork::setBatchSize(int batch_size) { } void GreaderNetwork::clearCredentials() { - m_authAuth = m_authSid = QString(); + m_authAuth = m_authSid = m_authToken = QString(); } QString GreaderNetwork::sanitizedBaseUrl() const { @@ -561,6 +595,9 @@ QString GreaderNetwork::generateFullUrl(GreaderNetwork::Operations operation) co case Operations::ClientLogin: return sanitizedBaseUrl() + GREADER_API_CLIENT_LOGIN; + case Operations::Token: + return sanitizedBaseUrl() + GREADER_API_TOKEN; + case Operations::TagList: return sanitizedBaseUrl() + GREADER_API_TAG_LIST; diff --git a/src/librssguard/services/greader/greadernetwork.h b/src/librssguard/services/greader/greadernetwork.h index a203cf55a..df81ba4ee 100755 --- a/src/librssguard/services/greader/greadernetwork.h +++ b/src/librssguard/services/greader/greadernetwork.h @@ -18,7 +18,8 @@ class GreaderNetwork : public QObject { TagList, SubscriptionList, StreamContents, - EditTag + EditTag, + Token }; explicit GreaderNetwork(QObject* parent = nullptr); @@ -84,6 +85,7 @@ class GreaderNetwork : public QObject { int m_batchSize; QString m_authSid; QString m_authAuth; + QString m_authToken; }; #endif // GREADERNETWORK_H diff --git a/src/librssguard/services/greader/greaderserviceroot.cpp b/src/librssguard/services/greader/greaderserviceroot.cpp index 552ec31b1..99cc45eb9 100755 --- a/src/librssguard/services/greader/greaderserviceroot.cpp +++ b/src/librssguard/services/greader/greaderserviceroot.cpp @@ -168,8 +168,9 @@ void GreaderServiceRoot::saveAccountDataToDatabase(bool creating_new) { if (!creating_new) { if (DatabaseQueries::overwriteGreaderAccount(database, m_network->username(), - m_network->password(), m_network->baseUrl(), - m_network->batchSize(), accountId())) { + m_network->password(), m_network->service(), + m_network->baseUrl(), m_network->batchSize(), + accountId())) { updateTitleIcon(); itemChanged(QList() << this); } diff --git a/src/librssguard/services/greader/greaderserviceroot.h b/src/librssguard/services/greader/greaderserviceroot.h index 297e31305..b917f8269 100755 --- a/src/librssguard/services/greader/greaderserviceroot.h +++ b/src/librssguard/services/greader/greaderserviceroot.h @@ -15,7 +15,9 @@ class GreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot { enum class Service { FreshRss = 1, TheOldReader = 2, - Bazqux = 4 + Bazqux = 4, + Reedah = 8, + Other = 1024 }; explicit GreaderServiceRoot(RootItem* parent = nullptr); diff --git a/src/librssguard/services/greader/gui/greaderaccountdetails.cpp b/src/librssguard/services/greader/gui/greaderaccountdetails.cpp index 9432d23ea..225ee9fc0 100755 --- a/src/librssguard/services/greader/gui/greaderaccountdetails.cpp +++ b/src/librssguard/services/greader/gui/greaderaccountdetails.cpp @@ -13,7 +13,9 @@ GreaderAccountDetails::GreaderAccountDetails(QWidget* parent) : QWidget(parent) for (auto serv : { GreaderServiceRoot::Service::Bazqux, GreaderServiceRoot::Service::FreshRss, - GreaderServiceRoot::Service::TheOldReader }) { + GreaderServiceRoot::Service::Reedah, + GreaderServiceRoot::Service::TheOldReader, + GreaderServiceRoot::Service::Other }) { m_ui.m_cmbService->addItem(GreaderNetwork::serviceToString(serv), QVariant::fromValue(serv)); }