From 3da5c736ee6c1261e5eea8076e4b45d35242d28d Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Sun, 30 Jun 2024 16:37:56 -0700 Subject: [PATCH] Support sending custom status codes via WebAPI --- src/webui/api/apicontroller.cpp | 6 ++++++ src/webui/api/apicontroller.h | 3 +++ src/webui/webapplication.cpp | 3 +++ 3 files changed, 12 insertions(+) diff --git a/src/webui/api/apicontroller.cpp b/src/webui/api/apicontroller.cpp index ca2c318f42be..9b459fbed721 100644 --- a/src/webui/api/apicontroller.cpp +++ b/src/webui/api/apicontroller.cpp @@ -42,6 +42,7 @@ void APIResult::clear() data.clear(); mimeType.clear(); filename.clear(); + statusCode = 0; } APIController::APIController(IApplication *app, QObject *parent) @@ -105,3 +106,8 @@ void APIController::setResult(const QByteArray &result, const QString &mimeType, m_result.mimeType = mimeType; m_result.filename = filename; } + +void APIController::setStatus(const int statusCode) +{ + m_result.statusCode = statusCode; +} diff --git a/src/webui/api/apicontroller.h b/src/webui/api/apicontroller.h index edcfc16fc3d7..8759245b6901 100644 --- a/src/webui/api/apicontroller.h +++ b/src/webui/api/apicontroller.h @@ -43,6 +43,7 @@ struct APIResult QVariant data; QString mimeType; QString filename; + int statusCode; void clear(); }; @@ -67,6 +68,8 @@ class APIController : public ApplicationComponent void setResult(const QJsonObject &result); void setResult(const QByteArray &result, const QString &mimeType = {}, const QString &filename = {}); + void setStatus(int statusCode); + private: StringMap m_params; DataMap m_data; diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 6a339d159565..918edb80e3f4 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -356,6 +356,9 @@ void WebApplication::doProcessRequest() try { const APIResult result = controller->run(action, m_params, data); + if (result.statusCode != 0) + status(result.statusCode); + switch (result.data.userType()) { case QMetaType::QJsonDocument: