From 1536914888d589d86a7364f753529ac993ee95fd Mon Sep 17 00:00:00 2001 From: Vladislav Ostapov Date: Fri, 15 Nov 2024 14:26:30 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81:=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D0=BF=D1=83=D1=82=D1=8C=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA?= =?UTF-8?q?=D0=B8=D1=85=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20+=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BF=D0=BE=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=8F=D0=BB=20=D1=86=D0=B2=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 12 ++++++------ src/server/resource.cpp | 21 +++++++++++++-------- src/server/resource.h | 9 ++++++--- static/style.css | 4 ++-- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0611a03..08dea56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -121,12 +121,12 @@ public: api->startDaemon(); auth.users.emplace_back(std::make_shared("admin", "", http::auth::User::SUPERUSER)); - sf->registerFile(staticFilesPath + FAVICON_ICO, mime_types::image_png, true); - sf->registerFile(staticFilesPath + VUE_JS, mime_types::javascript, true); - sf->registerFile(staticFilesPath + STYLE_CSS, mime_types::text_css, true); - sf->registerFile(staticFilesPath + FIELDS_CSS, mime_types::text_css, true); - sf->registerFile(staticFilesPath + INDEX_HTML, mime_types::text_html, false); - sf->registerFile(staticFilesPath + LOGIN_HTML, mime_types::text_html, true); + sf->registerFile(staticFilesPath + FAVICON_ICO, FAVICON_ICO, mime_types::image_png, true); + sf->registerFile(staticFilesPath + VUE_JS, VUE_JS, mime_types::javascript, true); + sf->registerFile(staticFilesPath + STYLE_CSS, STYLE_CSS, mime_types::text_css, true); + sf->registerFile(staticFilesPath + FIELDS_CSS, FIELDS_CSS, mime_types::text_css, true); + sf->registerFile(staticFilesPath + INDEX_HTML, INDEX_HTML, mime_types::text_html, false); + sf->registerFile(staticFilesPath + LOGIN_HTML, LOGIN_HTML, mime_types::text_html, true); } void registerResources(http::server::Server& s) { diff --git a/src/server/resource.cpp b/src/server/resource.cpp index afd33d1..e80b272 100644 --- a/src/server/resource.cpp +++ b/src/server/resource.cpp @@ -22,13 +22,18 @@ static void loadFile(const std::string& path, std::vector& content) { http::resource::BasicResource::BasicResource(std::string path): path(std::move(path)) {} -http::resource::StaticFileFactory::StaticFileDef::StaticFileDef(std::string path, server::mime_types::Mime type, bool allowCache): path(std::move(path)), type(type), allowCache(allowCache) { +http::resource::StaticFileFactory::StaticFileDef::StaticFileDef(const std::string& path, std::string webPath, server::mime_types::Mime type, bool allowCache): + webPath(std::move(webPath)), +#ifdef USE_DEBUG + fsPath(path), +#endif + type(type), allowCache(allowCache) { #ifdef USE_DEBUG if (allowCache) { - BOOST_LOG_TRIVIAL(info) << "Load static file " << this->path; - loadFile(this->path, this->content); + BOOST_LOG_TRIVIAL(info) << "Load static file " << this->webPath; + loadFile(path, this->content); } else { - BOOST_LOG_TRIVIAL(info) << "Skip loading static file " << this->path; + BOOST_LOG_TRIVIAL(info) << "Skip loading static file " << this->webPath; } #else BOOST_LOG_TRIVIAL(info) << "Load static file " << this->path; @@ -39,20 +44,20 @@ http::resource::StaticFileFactory::StaticFileDef::~StaticFileDef() = default; http::resource::StaticFileFactory::StaticFileFactory() = default; -void http::resource::StaticFileFactory::registerFile(const std::string &path, server::mime_types::Mime type, bool allowCache) { - this->files.emplace_back(path, type, allowCache); +void http::resource::StaticFileFactory::registerFile(const std::string &path, const std::string &webPath, server::mime_types::Mime type, bool allowCache) { + this->files.emplace_back(path, webPath, type, allowCache); } void http::resource::StaticFileFactory::serve(const std::string &path, server::Reply &rep) { for (auto& f: this->files) { - if (f.path == path) { + if (f.webPath == path) { #ifdef USE_DEBUG if (f.allowCache) { rep.content.clear(); rep.content.insert(rep.content.end(), f.content.begin(), f.content.end()); } else { BOOST_LOG_TRIVIAL(debug) << "Reload file " << path << " (http path: " << path << ")"; - loadFile(f.path, rep.content); + loadFile(f.fsPath, rep.content); } #else rep.content.clear(); diff --git a/src/server/resource.h b/src/server/resource.h index 0f9e4d5..085ce66 100644 --- a/src/server/resource.h +++ b/src/server/resource.h @@ -23,9 +23,12 @@ namespace http::resource { class StaticFileFactory { class StaticFileDef { public: - StaticFileDef(std::string path, server::mime_types::Mime type, bool allowCache = true); + StaticFileDef(const std::string& path, std::string webPath, server::mime_types::Mime type, bool allowCache = true); - std::string path; + std::string webPath; +#ifdef USE_DEBUG + std::string fsPath; +#endif server::mime_types::Mime type; bool allowCache; std::vector content; @@ -36,7 +39,7 @@ namespace http::resource { public: StaticFileFactory(); - void registerFile(const std::string& path, server::mime_types::Mime type, bool allowCache = true); + void registerFile(const std::string& path, const std::string &webPath, server::mime_types::Mime type, bool allowCache = true); void serve(const std::string& path, server::Reply& rep); diff --git a/static/style.css b/static/style.css index 91162e3..3121517 100644 --- a/static/style.css +++ b/static/style.css @@ -11,8 +11,8 @@ body { --bg-color: #FEFEFE; --bg-selected: #F1F1F1; --bg-element: #a7a7a7; - --bg-action: #5181fe; - --bg-danger: #db2828; + --bg-action: #81a7ff; + --bg-danger: #ff6464; } @media (prefers-color-scheme: dark) {