mirror of
https://github.com/yawaflua/SpCloudCore.git
synced 2025-12-08 19:49:28 +02:00
introduce logger for publish contoller
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "../Service/AuthorizationService.cpp"
|
||||
#include "../Service/FileProcessingService.cpp"
|
||||
//#include "Service/Logger.cpp"
|
||||
|
||||
class PublishController
|
||||
{
|
||||
@@ -16,10 +17,14 @@ private:
|
||||
|
||||
//std::string publish_app_path = "/mnt/c/Users/Danil/SpCloudApp";
|
||||
std::string publish_app_path = "/home/danilt2000/SpCloud/";
|
||||
|
||||
Logger& logger_;
|
||||
|
||||
//std::string publish_app_path = "C:/Temps/";// Todo delete if not needed
|
||||
|
||||
public:
|
||||
PublishController(httplib::Server& svr, AuthorizationService authorization, std::shared_ptr<FileProcessingService> file_processing) : authorization(authorization), file_processing(file_processing)
|
||||
PublishController(httplib::Server& svr, AuthorizationService authorization, std::shared_ptr<FileProcessingService> file_processing, Logger& logger)
|
||||
: authorization(authorization), file_processing(file_processing), logger_(logger)
|
||||
{
|
||||
/*this->authorization = authorization;
|
||||
|
||||
@@ -27,6 +32,8 @@ public:
|
||||
|
||||
svr.Post("/publish", [this](const httplib::Request& req, httplib::Response& res)
|
||||
{
|
||||
logger_.log(INFO, "Start publish");
|
||||
|
||||
this->process_publish(req, res);
|
||||
//httplib::Headers test = req.headers;//Todo add processing header for authorization layer
|
||||
});
|
||||
|
||||
@@ -22,13 +22,17 @@ public:
|
||||
|
||||
bool save_file(const std::string& filename, const std::string& content) {
|
||||
|
||||
logger_.log(INFO, "Start saving file method");
|
||||
|
||||
//std::lock_guard<std::mutex> lock(file_mutex); // Блокируем мьютекс//Todo TEST STABILITY OF THIS
|
||||
|
||||
std::ofstream ofs(filename, std::ios::binary);
|
||||
|
||||
logger_.log(INFO, "Create file stream");
|
||||
|
||||
if (!ofs) return false;
|
||||
|
||||
logger_.log(INFO, "Start saving file");
|
||||
logger_.log(INFO, "Start save content");
|
||||
|
||||
ofs << content;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ int main()
|
||||
|
||||
auto file_processing = std::make_shared<FileProcessingService>(logger);
|
||||
|
||||
PublishController publish_controller(svr, authorization_service, file_processing);
|
||||
PublishController publish_controller(svr, authorization_service, file_processing, logger);
|
||||
|
||||
std::cout << "Server is running at http://localhost:8080" << '\n';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user