mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-06 21:21:24 -07:00
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.
This commit is contained in:
parent
e05ef12e68
commit
a3b58e59da
3 changed files with 58 additions and 0 deletions
|
@ -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()
|
|||
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()
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue