From 21a42cf72069ff755bdfa845a6314db9ed4299c7 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Fri, 9 Aug 2024 21:40:51 +0200 Subject: [PATCH] Add publishcontroller --- SpCloudMain/CMakeLists.txt | 2 +- SpCloudMain/Controllers/PublishController.cpp | 95 +++++++++++++++++++ SpCloudMain/SpCloudMain.cpp | 13 +-- 3 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 SpCloudMain/Controllers/PublishController.cpp diff --git a/SpCloudMain/CMakeLists.txt b/SpCloudMain/CMakeLists.txt index 2717eed..e942636 100644 --- a/SpCloudMain/CMakeLists.txt +++ b/SpCloudMain/CMakeLists.txt @@ -3,7 +3,7 @@ # # Add source to this project's executable. -add_executable (SpCloudMain "SpCloudMain.cpp" "SpCloudMain.h") +add_executable (SpCloudMain "SpCloudMain.cpp" "SpCloudMain.h" ) if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET SpCloudMain PROPERTY CXX_STANDARD 20) diff --git a/SpCloudMain/Controllers/PublishController.cpp b/SpCloudMain/Controllers/PublishController.cpp new file mode 100644 index 0000000..ecbc039 --- /dev/null +++ b/SpCloudMain/Controllers/PublishController.cpp @@ -0,0 +1,95 @@ +//#pragma once +//#include "AuthorizationService.h" +//#include "FileProcessingService.h" +//#include "httplib.h" +//#include +//#include "httplib.h" + +class PublishController +{ + +private: + /*AuthorizationService authorization; + + FileProcessingService file_processing;*/ + + std::string publish_app_path = "C:/Temps/"; + +public: + PublishController(/*httplib::Server& svr, AuthorizationService authorization, FileProcessingService file_processing*/) + { + std::cout << "test" << "\n"; + /*this->authorization = authorization; + + this->file_processing = file_processing;*/ + + //svr.Post("/publish", [this](const httplib::Request& req, httplib::Response& res) + // { + // this->process_publish(req, res); + // //httplib::Headers test = req.headers;//Todo add processing header for authorization layer + // }); + } + // + //private: + // void process_publish(const httplib::Request& req, httplib::Response& res) + // { + // if (this->authorization.is_user_authorized()) + // { + // const auto& content = req.files.begin()->second.content; + // + // const auto& filename = this->publish_app_path + req.files.begin()->second.filename; + // + // if (filename.size() >= 4 && filename.substr(filename.size() - 4) == ".rar") { + // if (file_processing.save_file(filename, content)) { + // + // std::string random_string = generate_random_string(20);//Todo think about change + // + // file_processing.unzip(filename, this->publish_app_path + random_string); + // + // this->dotnet_publish(this->publish_app_path + random_string); + // + // res.set_content("File uploaded successfully: " + filename, "text/plain"); + // } + // else { + // res.status = 500; + // res.set_content("Failed to save file, please ensure you are putting rar file" + // + filename, "text/plain"); + // } + // } + // else { + // res.status = 400; + // res.set_content("Invalid file type. Only .rar files are allowed.", + // "text/plain"); + // } + // } + // else + // { + // //Todo add logging and exiting from function with bead request + // } + // } + // + // void dotnet_publish(const std::string& path) + // { + // std::string dll_file_name = file_processing.find_file_by_suffix(path, "dll"); + // + // std::string command = R"(dotnet )" + path + "/" + dll_file_name; + // + // std::thread commandThread(&CommandService::execute_command, command); + // + // commandThread.detach(); + // } + // + // static std::string generate_random_string(size_t length, const std::string& char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") { + // std::random_device rd; + // std::mt19937 generator(rd()); + // std::uniform_int_distribution<> distribution(0, char_set.size() - 1); + // + // std::string random_string; + // for (size_t i = 0; i < length; ++i) { + // char random_char = char_set[distribution(generator)]; + // random_string += random_char; + // } + // + // return random_string; + // } +}; \ No newline at end of file diff --git a/SpCloudMain/SpCloudMain.cpp b/SpCloudMain/SpCloudMain.cpp index 10c8212..8d1f455 100644 --- a/SpCloudMain/SpCloudMain.cpp +++ b/SpCloudMain/SpCloudMain.cpp @@ -1,17 +1,18 @@ // SpCloudMain.cpp : Defines the entry point for the application. // +// ReSharper disable CppClangTidyBugproneSuspiciousInclude + #include "SpCloudMain.h" +#include "Controllers/PublishController.cpp" + using namespace std; int main() { - while (true) - { - cout << "Hello ." << endl; - cout << "Hello 2." << endl; - } + std::cout << "SpCloud start\n"; + + PublishController publish_controller; - return 0; }