Skip to content

Commit

Permalink
Change config endpoint request format
Browse files Browse the repository at this point in the history
  • Loading branch information
aiamnezia committed Jan 27, 2025
1 parent 2aa67fa commit 3a9615f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion proxyserver/proxyserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,29 @@ void ProxyServer::setupRoutes()
m_server.route("/api/v1/config", QHttpServerRequest::Method::Post, [this] (const QHttpServerRequest &request) {
QJsonObject response;

QString configStr = QString::fromUtf8(request.body());
QJsonParseError parseError;
QJsonDocument doc = QJsonDocument::fromJson(request.body(), &parseError);

if (parseError.error != QJsonParseError::NoError) {
response["status"] = "error";
response["message"] = "Invalid JSON format";
return response;
}

if (!doc.isObject() || !doc.object().contains("config") || !doc.object()["config"].isArray()) {
response["status"] = "error";
response["message"] = "Request must contain 'config' array field";
return response;
}

QJsonArray configArray = doc.object()["configs"].toArray();
if (configArray.isEmpty()) {
response["status"] = "error";
response["message"] = "Config array cannot be empty";
return response;
}

QString configStr = configArray[0].toString();
if (configStr.isEmpty()) {
response["status"] = "error";
response["message"] = "Config string cannot be empty";
Expand Down

0 comments on commit 3a9615f

Please sign in to comment.