Browse Source

WebAPI: Expand RSS related API

Added markAsRead API method with optional parameter for specifying single article.
Added the rss_smart_episode_filters and rss_download_repack_proper_episodes keys to preference api.
Added matchingArticles API method for retrieving articles that match specified rule.
adaptive-webui-19844
Sepro 5 years ago
parent
commit
a3b58e59da
  1. 6
      src/webui/api/appcontroller.cpp
  2. 50
      src/webui/api/rsscontroller.cpp
  3. 2
      src/webui/api/rsscontroller.h

6
src/webui/api/appcontroller.cpp

@ -255,6 +255,8 @@ void AppController::preferencesAction() @@ -255,6 +255,8 @@ void AppController::preferencesAction()
data["rss_max_articles_per_feed"] = RSS::Session::instance()->maxArticlesPerFeed();
data["rss_processing_enabled"] = RSS::Session::instance()->isProcessingEnabled();
data["rss_auto_downloading_enabled"] = RSS::AutoDownloader::instance()->isProcessingEnabled();
data["rss_download_repack_proper_episodes"] = RSS::AutoDownloader::instance()->downloadRepacks();
data["rss_smart_episode_filters"] = RSS::AutoDownloader::instance()->smartEpisodeFilters().join('\n');
// Advanced settings
// qBitorrent preferences
@ -643,6 +645,10 @@ void AppController::setPreferencesAction() @@ -643,6 +645,10 @@ void AppController::setPreferencesAction()
RSS::Session::instance()->setProcessingEnabled(it.value().toBool());
if (hasKey("rss_auto_downloading_enabled"))
RSS::AutoDownloader::instance()->setProcessingEnabled(it.value().toBool());
if (hasKey("rss_download_repack_proper_episodes"))
RSS::AutoDownloader::instance()->setDownloadRepacks(it.value().toBool());
if (hasKey("rss_smart_episode_filters"))
RSS::AutoDownloader::instance()->setSmartEpisodeFilters(it.value().toString().split('\n'));
// Advanced settings
// qBittorrent preferences

50
src/webui/api/rsscontroller.cpp

@ -28,12 +28,15 @@ @@ -28,12 +28,15 @@
#include "rsscontroller.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include "base/rss/rss_article.h"
#include "base/rss/rss_autodownloader.h"
#include "base/rss/rss_autodownloadrule.h"
#include "base/rss/rss_feed.h"
#include "base/rss/rss_folder.h"
#include "base/rss/rss_session.h"
#include "base/utils/string.h"
@ -91,6 +94,29 @@ void RSSController::itemsAction() @@ -91,6 +94,29 @@ void RSSController::itemsAction()
setResult(jsonVal.toObject());
}
void RSSController::markAsReadAction()
{
requireParams({"itemPath"});
const QString itemPath {params()["itemPath"]};
const QString articleId {params()["articleId"]};
RSS::Item *item = RSS::Session::instance()->itemByPath(itemPath);
if (!item) return;
if (!articleId.isNull()) {
RSS::Feed *feed = qobject_cast<RSS::Feed *>(item);
if (feed) {
RSS::Article *article = feed->articleByGUID(articleId);
if (article)
article->markAsRead();
}
}
else {
item->markAsRead();
}
}
void RSSController::refreshItemAction()
{
requireParams({"itemPath"});
@ -139,3 +165,27 @@ void RSSController::rulesAction() @@ -139,3 +165,27 @@ void RSSController::rulesAction()
setResult(jsonObj);
}
void RSSController::matchingArticlesAction()
{
requireParams({"ruleName"});
const QString ruleName {params()["ruleName"]};
const RSS::AutoDownloadRule rule = RSS::AutoDownloader::instance()->ruleByName(ruleName);
QJsonObject jsonObj;
for (const QString &feedURL : rule.feedURLs()) {
const RSS::Feed *feed = RSS::Session::instance()->feedByURL(feedURL);
if (!feed) continue; // feed doesn't exist
QJsonArray matchingArticles;
for (const RSS::Article *article : feed->articles()) {
if (rule.matches(article->data()))
matchingArticles << article->title();
}
if (!matchingArticles.isEmpty())
jsonObj.insert(feed->name(), matchingArticles);
}
setResult(jsonObj);
}

2
src/webui/api/rsscontroller.h

@ -44,9 +44,11 @@ private slots: @@ -44,9 +44,11 @@ private slots:
void removeItemAction();
void moveItemAction();
void itemsAction();
void markAsReadAction();
void refreshItemAction();
void setRuleAction();
void renameRuleAction();
void removeRuleAction();
void rulesAction();
void matchingArticlesAction();
};

Loading…
Cancel
Save