Change scope of file processing and adjust di in publish contoller

This commit is contained in:
Hepatica
2024-08-11 02:22:09 +02:00
parent 1f3086c96c
commit f2f8169c61
3 changed files with 16 additions and 10 deletions

View File

@@ -12,18 +12,18 @@ class PublishController
private: private:
AuthorizationService authorization; AuthorizationService authorization;
FileProcessingService file_processing; std::shared_ptr<FileProcessingService> file_processing;//Smart pointer
std::string publish_app_path = "/mnt/c/Users/Danil/SpCloudApp"; std::string publish_app_path = "/mnt/c/Users/Danil/SpCloudApp";
//std::string publish_app_path = "/home/danilt2000/SpCloud/"; //std::string publish_app_path = "/home/danilt2000/SpCloud/";
//std::string publish_app_path = "C:/Temps/";// Todo delete if not needed //std::string publish_app_path = "C:/Temps/";// Todo delete if not needed
public: public:
PublishController(httplib::Server& svr, AuthorizationService authorization, FileProcessingService file_processing) PublishController(httplib::Server& svr, AuthorizationService authorization, std::shared_ptr<FileProcessingService> file_processing) : authorization(authorization), file_processing(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)
{ {
@@ -43,7 +43,7 @@ private:
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_with_retry(filename, content)) { //if (file_processing.save_file_with_retry(filename, content)) {
if (file_processing.save_file(filename, content)) { if (file_processing->save_file(filename, content)) {
//Todo uncommit later //Todo uncommit later
//std::string random_string = generate_random_string(20);//Todo think about change //std::string random_string = generate_random_string(20);//Todo think about change
@@ -74,7 +74,7 @@ private:
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;

View File

@@ -6,15 +6,18 @@
#include <thread> #include <thread>
#include <sys/stat.h> #include <sys/stat.h>
#include "CommandService.cpp" #include "CommandService.cpp"
#include "Logger.cpp"
//#include <Poco/Mutex.h> //#include <Poco/Mutex.h>
//#include <Poco/Path.h> //#include <Poco/Path.h>
//#include <Poco/FileStr*/eam.h > //#include <Poco/FileStr*/eam.h >
class FileProcessingService class FileProcessingService
{ {
public: public:
FileProcessingService(/*&Logger logger*/) FileProcessingService(Logger& logger) : logger_(logger)
{ {
} }
bool save_file(const std::string& filename, const std::string& content) { bool save_file(const std::string& filename, const std::string& content) {
@@ -25,8 +28,9 @@ public:
if (!ofs) return false; if (!ofs) return false;
ofs << content; logger_.log(INFO, "Start saving file");
ofs << content;
return ofs.good(); return ofs.good();
} }
@@ -136,4 +140,5 @@ public:
/*private: /*private:
std::mutex file_mutex; */// Мьютекс для синхронизации доступа к файлу std::mutex file_mutex; */// Мьютекс для синхронизации доступа к файлу
Logger& logger_;
}; };

View File

@@ -7,7 +7,6 @@
#include "httplib.h" #include "httplib.h"
#include "Controllers/PublishController.cpp" #include "Controllers/PublishController.cpp"
//#include "Service/AuthorizationService.cpp" //#include "Service/AuthorizationService.cpp"
#include "Service/Logger.cpp"
//#include "Service/FileProcessingService.cpp" //#include "Service/FileProcessingService.cpp"
using namespace std; using namespace std;
@@ -36,7 +35,9 @@ int main()
AuthorizationService authorization_service; AuthorizationService authorization_service;
FileProcessingService file_processing; //FileProcessingService file_processing(logger);
auto file_processing = std::make_shared<FileProcessingService>(logger);
PublishController publish_controller(svr, authorization_service, file_processing); PublishController publish_controller(svr, authorization_service, file_processing);