From 8f3ba858c5329ed412f3fb9a4f87f19731b07aff Mon Sep 17 00:00:00 2001 From: "Leon Etienne (ubuntu wsl)" Date: Mon, 28 Sep 2020 20:11:52 +0200 Subject: [PATCH] Added clear_log function --- Tubio/RestQueryHandler.cpp | 12 +++++++ Tubio/RestQueryHandler.h | 1 + Tubio_rest.postman_collection.json | 54 ++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/Tubio/RestQueryHandler.cpp b/Tubio/RestQueryHandler.cpp index 3dd655b..b67fd18 100644 --- a/Tubio/RestQueryHandler.cpp +++ b/Tubio/RestQueryHandler.cpp @@ -32,6 +32,7 @@ bool RestQueryHandler::ProcessQuery(const std::string clientAdress, const Json& else if (requestName == "fetch_alltime_cache") return FetchAlltimeCache(requestBody, responseBody, responseCode); else if (requestName == "get_disk_usage") return GetDiskUsage(requestBody, responseBody, responseCode); else if (requestName == "clear_download_cache") return ClearDownloadCache(requestBody, responseBody, responseCode); + else if (requestName == "clear_logs") return ClearLogs(requestBody, responseBody, responseCode); else if (requestName == "foo") return Example_Foo(requestBody, responseBody, responseCode); else if (requestName == "show_console") return ShowConsole(requestBody, responseBody, responseCode); else if (requestName == "hide_console") return HideConsole(requestBody, responseBody, responseCode); @@ -343,7 +344,18 @@ bool RestQueryHandler::GetDiskUsage(const JsonBlock& request, JsonBlock& respons return true; } +bool RestQueryHandler::ClearLogs(const JsonBlock& request, JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode) +{ + responseCode = OK; + responseBody.CloneFrom(RestResponseTemplates::GetByCode(OK)); + responseBody.Set("message") = "The logs have been cleared."; + LogHistory::ClearLogHistory(); + log->cout << "Cleared logs..."; + log->Flush(); + + return true; +} diff --git a/Tubio/RestQueryHandler.h b/Tubio/RestQueryHandler.h index f4ffe52..a698904 100644 --- a/Tubio/RestQueryHandler.h +++ b/Tubio/RestQueryHandler.h @@ -23,6 +23,7 @@ namespace Rest static bool FetchAlltimeCache(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode); static bool QueueDownload(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode); static bool ClearDownloadCache(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode); + static bool ClearLogs(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode); static bool KillYourself(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode); static bool HideConsole(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode); static bool ShowConsole(const JasonPP::JsonBlock& request, JasonPP::JsonBlock& responseBody, HTTP_STATUS_CODE& responseCode); diff --git a/Tubio_rest.postman_collection.json b/Tubio_rest.postman_collection.json index f0e0ea6..09b8112 100644 --- a/Tubio_rest.postman_collection.json +++ b/Tubio_rest.postman_collection.json @@ -337,6 +337,60 @@ } }, "response": [] + }, + { + "name": "GetDiskUsage", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"request\": \"get_disk_usage\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:6969/api", + "host": [ + "localhost" + ], + "port": "6969", + "path": [ + "api" + ] + } + }, + "response": [] + }, + { + "name": "ClearLogs", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"request\": \"clear_logs\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:6969/api", + "host": [ + "localhost" + ], + "port": "6969", + "path": [ + "api" + ] + } + }, + "response": [] } ], "protocolProfileBehavior": {}