mirror of
https://github.com/yawaflua/SpCloudCore.git
synced 2025-12-10 04:29:35 +02:00
Adjust publish controller
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
//#include "httplib.h"
|
#include "../httplib.h"
|
||||||
//#include <windows.h>
|
//#include <windows.h>
|
||||||
//#include "Service/AuthorizationService.cpp"
|
//#include "Service/AuthorizationService.cpp"
|
||||||
//#include "Service/FileProcessingService.cpp"
|
//#include "Service/FileProcessingService.cpp"
|
||||||
@@ -14,82 +14,82 @@ private:
|
|||||||
|
|
||||||
FileProcessingService file_processing;
|
FileProcessingService file_processing;
|
||||||
|
|
||||||
std::string publish_app_path = "C:/Temps/";
|
std::string publish_app_path = "C:/Temps/";//Todo change to linux path
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PublishController(/*httplib::Server& svr,*/ AuthorizationService authorization, FileProcessingService file_processing)
|
PublishController(httplib::Server& svr, AuthorizationService authorization, FileProcessingService file_processing)
|
||||||
{
|
{
|
||||||
/*this->authorization = authorization;
|
this->authorization = authorization;
|
||||||
|
|
||||||
this->file_processing = file_processing;*/
|
this->file_processing = file_processing;
|
||||||
|
|
||||||
//svr.Post("/publish", [this](const httplib::Request& req, httplib::Response& res)
|
svr.Post("/publish", [this](const httplib::Request& req, httplib::Response& res)
|
||||||
// {
|
{
|
||||||
// this->process_publish(req, res);
|
this->process_publish(req, res);
|
||||||
// //httplib::Headers test = req.headers;//Todo add processing header for authorization layer
|
//httplib::Headers test = req.headers;//Todo add processing header for authorization layer
|
||||||
// });
|
});
|
||||||
}
|
}
|
||||||
//
|
|
||||||
//private:
|
private:
|
||||||
// void process_publish(const httplib::Request& req, httplib::Response& res)
|
void process_publish(const httplib::Request& req, httplib::Response& res)
|
||||||
// {
|
{
|
||||||
// if (this->authorization.is_user_authorized())
|
if (this->authorization.is_user_authorized())
|
||||||
// {
|
{
|
||||||
// const auto& content = req.files.begin()->second.content;
|
const auto& content = req.files.begin()->second.content;
|
||||||
//
|
|
||||||
// const auto& filename = this->publish_app_path + req.files.begin()->second.filename;
|
const auto& filename = this->publish_app_path + req.files.begin()->second.filename;
|
||||||
//
|
|
||||||
// if (filename.size() >= 4 && filename.substr(filename.size() - 4) == ".rar") {
|
if (filename.size() >= 4 && filename.substr(filename.size() - 4) == ".rar") {
|
||||||
// if (file_processing.save_file(filename, content)) {
|
if (file_processing.save_file(filename, content)) {
|
||||||
//
|
|
||||||
// std::string random_string = generate_random_string(20);//Todo think about change
|
std::string random_string = generate_random_string(20);//Todo think about change
|
||||||
//
|
|
||||||
// file_processing.unzip(filename, this->publish_app_path + random_string);
|
file_processing.unzip(filename, this->publish_app_path + random_string);
|
||||||
//
|
|
||||||
// this->dotnet_publish(this->publish_app_path + random_string);
|
this->dotnet_publish(this->publish_app_path + random_string);
|
||||||
//
|
|
||||||
// res.set_content("File uploaded successfully: " + filename, "text/plain");
|
res.set_content("File uploaded successfully: " + filename, "text/plain");
|
||||||
// }
|
}
|
||||||
// else {
|
else {
|
||||||
// res.status = 500;
|
res.status = 500;
|
||||||
// res.set_content("Failed to save file, please ensure you are putting rar file"
|
res.set_content("Failed to save file, please ensure you are putting rar file"
|
||||||
// + filename, "text/plain");
|
+ filename, "text/plain");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// else {
|
else {
|
||||||
// res.status = 400;
|
res.status = 400;
|
||||||
// res.set_content("Invalid file type. Only .rar files are allowed.",
|
res.set_content("Invalid file type. Only .rar files are allowed.",
|
||||||
// "text/plain");
|
"text/plain");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// //Todo add logging and exiting from function with bead request
|
//Todo add logging and exiting from function with bead request
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// void dotnet_publish(const std::string& path)
|
void dotnet_publish(const std::string& path)
|
||||||
// {
|
{
|
||||||
// std::string dll_file_name = file_processing.find_file_by_suffix(path, "dll");
|
std::string dll_file_name = file_processing.find_file_by_suffix(path, "dll");
|
||||||
//
|
|
||||||
// std::string command = R"(dotnet )" + path + "/" + dll_file_name;
|
std::string command = R"(dotnet )" + path + "/" + dll_file_name;
|
||||||
//
|
|
||||||
// std::thread commandThread(&CommandService::execute_command, command);
|
std::thread commandThread(&CommandService::execute_command, command);
|
||||||
//
|
|
||||||
// commandThread.detach();
|
commandThread.detach();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// static std::string generate_random_string(size_t length, const std::string& char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") {
|
static std::string generate_random_string(size_t length, const std::string& char_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") {
|
||||||
// std::random_device rd;
|
std::random_device rd;
|
||||||
// std::mt19937 generator(rd());
|
std::mt19937 generator(rd());
|
||||||
// std::uniform_int_distribution<> distribution(0, char_set.size() - 1);
|
std::uniform_int_distribution<> distribution(0, char_set.size() - 1);
|
||||||
//
|
|
||||||
// std::string random_string;
|
std::string random_string;
|
||||||
// for (size_t i = 0; i < length; ++i) {
|
for (size_t i = 0; i < length; ++i) {
|
||||||
// char random_char = char_set[distribution(generator)];
|
char random_char = char_set[distribution(generator)];
|
||||||
// random_string += random_char;
|
random_string += random_char;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return random_string;
|
return random_string;
|
||||||
// }
|
}
|
||||||
};
|
};
|
||||||
@@ -32,7 +32,7 @@ int main()
|
|||||||
|
|
||||||
//PublishController publish_controller(svr, authorization_service, file_processing);
|
//PublishController publish_controller(svr, authorization_service, file_processing);
|
||||||
|
|
||||||
PublishController publish_controller(/*svr,*/ authorization_service, file_processing);
|
PublishController publish_controller(svr, authorization_service, file_processing);
|
||||||
|
|
||||||
std::cout << "Server is running at http://localhost:8080" << '\n';
|
std::cout << "Server is running at http://localhost:8080" << '\n';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user