Browse Source

Merge pull request #12549 from SeproDE/rss-api

Expand RSS related WebAPI
adaptive-webui-19844
Vladimir Golovnev 5 years ago committed by GitHub
parent
commit
c10318b576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/webui/api/appcontroller.cpp
  2. 50
      src/webui/api/rsscontroller.cpp
  3. 2
      src/webui/api/rsscontroller.h

10
src/webui/api/appcontroller.cpp

@ -165,7 +165,7 @@ void AppController::preferencesAction()
data["ip_filter_enabled"] = session->isIPFilteringEnabled(); data["ip_filter_enabled"] = session->isIPFilteringEnabled();
data["ip_filter_path"] = Utils::Fs::toNativePath(session->IPFilterFile()); data["ip_filter_path"] = Utils::Fs::toNativePath(session->IPFilterFile());
data["ip_filter_trackers"] = session->isTrackerFilteringEnabled(); data["ip_filter_trackers"] = session->isTrackerFilteringEnabled();
data["banned_IPs"] = session->bannedIPs().join("\n"); data["banned_IPs"] = session->bannedIPs().join('\n');
// Speed // Speed
// Global Rate Limits // Global Rate Limits
@ -231,7 +231,7 @@ void AppController::preferencesAction()
QStringList authSubnetWhitelistStringList; QStringList authSubnetWhitelistStringList;
for (const Utils::Net::Subnet &subnet : asConst(pref->getWebUiAuthSubnetWhitelist())) for (const Utils::Net::Subnet &subnet : asConst(pref->getWebUiAuthSubnetWhitelist()))
authSubnetWhitelistStringList << Utils::Net::subnetToString(subnet); authSubnetWhitelistStringList << Utils::Net::subnetToString(subnet);
data["bypass_auth_subnet_whitelist"] = authSubnetWhitelistStringList.join("\n"); data["bypass_auth_subnet_whitelist"] = authSubnetWhitelistStringList.join('\n');
data["web_ui_max_auth_fail_count"] = pref->getWebUIMaxAuthFailCount(); data["web_ui_max_auth_fail_count"] = pref->getWebUIMaxAuthFailCount();
data["web_ui_ban_duration"] = static_cast<int>(pref->getWebUIBanDuration().count()); data["web_ui_ban_duration"] = static_cast<int>(pref->getWebUIBanDuration().count());
data["web_ui_session_timeout"] = pref->getWebUISessionTimeout(); data["web_ui_session_timeout"] = pref->getWebUISessionTimeout();
@ -258,6 +258,8 @@ void AppController::preferencesAction()
data["rss_max_articles_per_feed"] = RSS::Session::instance()->maxArticlesPerFeed(); data["rss_max_articles_per_feed"] = RSS::Session::instance()->maxArticlesPerFeed();
data["rss_processing_enabled"] = RSS::Session::instance()->isProcessingEnabled(); data["rss_processing_enabled"] = RSS::Session::instance()->isProcessingEnabled();
data["rss_auto_downloading_enabled"] = RSS::AutoDownloader::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 // Advanced settings
// qBitorrent preferences // qBitorrent preferences
@ -651,6 +653,10 @@ void AppController::setPreferencesAction()
RSS::Session::instance()->setProcessingEnabled(it.value().toBool()); RSS::Session::instance()->setProcessingEnabled(it.value().toBool());
if (hasKey("rss_auto_downloading_enabled")) if (hasKey("rss_auto_downloading_enabled"))
RSS::AutoDownloader::instance()->setProcessingEnabled(it.value().toBool()); 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 // Advanced settings
// qBittorrent preferences // qBittorrent preferences

50
src/webui/api/rsscontroller.cpp

@ -28,12 +28,15 @@
#include "rsscontroller.h" #include "rsscontroller.h"
#include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonValue> #include <QJsonValue>
#include "base/rss/rss_article.h"
#include "base/rss/rss_autodownloader.h" #include "base/rss/rss_autodownloader.h"
#include "base/rss/rss_autodownloadrule.h" #include "base/rss/rss_autodownloadrule.h"
#include "base/rss/rss_feed.h"
#include "base/rss/rss_folder.h" #include "base/rss/rss_folder.h"
#include "base/rss/rss_session.h" #include "base/rss/rss_session.h"
#include "base/utils/string.h" #include "base/utils/string.h"
@ -91,6 +94,29 @@ void RSSController::itemsAction()
setResult(jsonVal.toObject()); 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() void RSSController::refreshItemAction()
{ {
requireParams({"itemPath"}); requireParams({"itemPath"});
@ -139,3 +165,27 @@ void RSSController::rulesAction()
setResult(jsonObj); 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:
void removeItemAction(); void removeItemAction();
void moveItemAction(); void moveItemAction();
void itemsAction(); void itemsAction();
void markAsReadAction();
void refreshItemAction(); void refreshItemAction();
void setRuleAction(); void setRuleAction();
void renameRuleAction(); void renameRuleAction();
void removeRuleAction(); void removeRuleAction();
void rulesAction(); void rulesAction();
void matchingArticlesAction();
}; };

Loading…
Cancel
Save