Skip to content

Commit

Permalink
Maintain 200 status code for existing APIs
Browse files Browse the repository at this point in the history
This is to avoid introducing breaking changes. Without this change, these APIs would start returning a 204 due to their lack of response content.
  • Loading branch information
Piccirello committed Dec 7, 2024
1 parent 78fbcab commit 872629e
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void AppController::shutdownAction()
{
QCoreApplication::exit();
});
setResult(QString());
}

void AppController::preferencesAction()
Expand Down Expand Up @@ -1157,6 +1158,8 @@ void AppController::setPreferencesAction()

// Save preferences
pref->apply();

setResult(QString());
}

void AppController::defaultSavePathAction()
Expand All @@ -1167,9 +1170,9 @@ void AppController::defaultSavePathAction()
void AppController::sendTestEmailAction()
{
app()->sendTestEmail();
setResult(QString());
}


void AppController::getDirectoryContentAction()
{
requireParams({u"dirPath"_s});
Expand Down Expand Up @@ -1259,6 +1262,8 @@ void AppController::setCookiesAction()
}

Net::DownloadManager::instance()->setAllCookies(cookies);

setResult(QString());
}

void AppController::networkInterfaceListAction()
Expand Down
3 changes: 3 additions & 0 deletions src/webui/api/authcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ AuthController::AuthController(ISessionManager *sessionManager, IApplication *ap
void AuthController::setUsername(const QString &username)
{
m_username = username;
setResult(QString());
}

void AuthController::setPasswordHash(const QByteArray &passwordHash)
{
m_passwordHash = passwordHash;
setResult(QString());
}

void AuthController::loginAction()
Expand Down Expand Up @@ -99,6 +101,7 @@ void AuthController::loginAction()
void AuthController::logoutAction() const
{
m_sessionManager->sessionEnd();
setResult(QString());
}

bool AuthController::isBanned() const
Expand Down
20 changes: 20 additions & 0 deletions src/webui/api/rsscontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void RSSController::addFolderAction()
const nonstd::expected<void, QString> result = RSS::Session::instance()->addFolder(path);
if (!result)
throw APIError(APIErrorType::Conflict, result.error());

setResult(QString());
}

void RSSController::addFeedAction()
Expand All @@ -64,6 +66,8 @@ void RSSController::addFeedAction()
const nonstd::expected<void, QString> result = RSS::Session::instance()->addFeed(url, (path.isEmpty() ? url : path));
if (!result)
throw APIError(APIErrorType::Conflict, result.error());

setResult(QString());
}

void RSSController::setFeedURLAction()
Expand All @@ -75,6 +79,8 @@ void RSSController::setFeedURLAction()
const nonstd::expected<void, QString> result = RSS::Session::instance()->setFeedURL(path, url);
if (!result)
throw APIError(APIErrorType::Conflict, result.error());

setResult(QString());
}

void RSSController::removeItemAction()
Expand All @@ -85,6 +91,8 @@ void RSSController::removeItemAction()
const nonstd::expected<void, QString> result = RSS::Session::instance()->removeItem(path);
if (!result)
throw APIError(APIErrorType::Conflict, result.error());

setResult(QString());
}

void RSSController::moveItemAction()
Expand All @@ -96,6 +104,8 @@ void RSSController::moveItemAction()
const nonstd::expected<void, QString> result = RSS::Session::instance()->moveItem(itemPath, destPath);
if (!result)
throw APIError(APIErrorType::Conflict, result.error());

setResult(QString());
}

void RSSController::itemsAction()
Expand Down Expand Up @@ -130,6 +140,8 @@ void RSSController::markAsReadAction()
{
item->markAsRead();
}

setResult(QString());
}

void RSSController::refreshItemAction()
Expand All @@ -140,6 +152,8 @@ void RSSController::refreshItemAction()
RSS::Item *item = RSS::Session::instance()->itemByPath(itemPath);
if (item)
item->refresh();

setResult(QString());
}

void RSSController::setRuleAction()
Expand All @@ -151,6 +165,8 @@ void RSSController::setRuleAction()

const auto jsonObj = QJsonDocument::fromJson(ruleDef).object();
RSS::AutoDownloader::instance()->setRule(RSS::AutoDownloadRule::fromJsonObject(jsonObj, ruleName));

setResult(QString());
}

void RSSController::renameRuleAction()
Expand All @@ -161,6 +177,8 @@ void RSSController::renameRuleAction()
const QString newRuleName {params()[u"newRuleName"_s].trimmed()};

RSS::AutoDownloader::instance()->renameRule(ruleName, newRuleName);

setResult(QString());
}

void RSSController::removeRuleAction()
Expand All @@ -169,6 +187,8 @@ void RSSController::removeRuleAction()

const QString ruleName {params()[u"ruleName"_s].trimmed()};
RSS::AutoDownloader::instance()->removeRule(ruleName);

setResult(QString());
}

void RSSController::rulesAction()
Expand Down
16 changes: 16 additions & 0 deletions src/webui/api/searchcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void SearchController::stopAction()
searchHandler->cancelSearch();
m_activeSearches.remove(id);
}

setResult(QString());
}

void SearchController::statusAction()
Expand Down Expand Up @@ -215,6 +217,8 @@ void SearchController::deleteAction()
searchHandler->cancelSearch();
m_activeSearches.remove(id);
m_searchHandlers.erase(iter);

setResult(QString());
}

void SearchController::downloadTorrentAction()
Expand All @@ -238,6 +242,8 @@ void SearchController::downloadTorrentAction()
downloadHandler->deleteLater();
});
}

setResult(QString());
}

void SearchController::pluginsAction()
Expand All @@ -253,6 +259,8 @@ void SearchController::installPluginAction()
const QStringList sources = params()[u"sources"_s].split(u'|');
for (const QString &source : sources)
SearchPluginManager::instance()->installPlugin(source);

setResult(QString());
}

void SearchController::uninstallPluginAction()
Expand All @@ -262,6 +270,8 @@ void SearchController::uninstallPluginAction()
const QStringList names = params()[u"names"_s].split(u'|');
for (const QString &name : names)
SearchPluginManager::instance()->uninstallPlugin(name.trimmed());

setResult(QString());
}

void SearchController::enablePluginAction()
Expand All @@ -273,6 +283,8 @@ void SearchController::enablePluginAction()

for (const QString &name : names)
SearchPluginManager::instance()->enablePlugin(name.trimmed(), enable);

setResult(QString());
}

void SearchController::updatePluginsAction()
Expand All @@ -282,6 +294,8 @@ void SearchController::updatePluginsAction()
connect(pluginManager, &SearchPluginManager::checkForUpdatesFinished, this, &SearchController::checkForUpdatesFinished);
connect(pluginManager, &SearchPluginManager::checkForUpdatesFailed, this, &SearchController::checkForUpdatesFailed);
pluginManager->checkForUpdates();

setResult(QString());
}

void SearchController::checkForUpdatesFinished(const QHash<QString, PluginVersion> &updateInfo)
Expand All @@ -300,6 +314,8 @@ void SearchController::checkForUpdatesFinished(const QHash<QString, PluginVersio
LogMsg(tr("Updating plugin %1").arg(pluginName), Log::INFO);
pluginManager->updatePlugin(pluginName);
}

setResult(QString());
}

void SearchController::checkForUpdatesFailed(const QString &reason)
Expand Down
2 changes: 2 additions & 0 deletions src/webui/api/torrentcreatorcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,6 @@ void TorrentCreatorController::deleteTaskAction()

if (!m_torrentCreationManager->deleteTask(id))
throw APIError(APIErrorType::NotFound);

setResult(QString());
}
Loading

0 comments on commit 872629e

Please sign in to comment.