Loading src/theme.cpp +66 −8 Changes for src/theme.cpp: 66 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -45,6 +45,37 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated) : _Config(config){ auto trimlines = [&] (const std::string in){ std::string out; bool space=false; for(auto i : in){ switch(i){ case '\r': space=true; continue; case '\n': if(!space) out.push_back(' '); space=true; continue; case '\t': if(!space) out.push_back(' '); space=true; continue; case ' ': if(space) continue; space=true; default: space=false; out.push_back(i); break; } } return out; }; _Formated=formated; std::string ppath(_Config.Theme); Loading Loading @@ -88,16 +119,19 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated) : _Config(config){ // Construct the path string using the filename tfile.Path = "/theme/public/" + entry.path().filename().string(); tfile.Content = buf; tfile.Content = trimlines(buf); std::string fname = entry.path().filename().string(); size_t dot_pos = fname.rfind('.'); if (dot_pos != std::string::npos) { tfile.Ending = fname.substr(dot_pos + 1); size_t end_pos = fname.rfind('?') != std::string::npos ? fname.rfind('?') : fname.length(); if (++dot_pos != std::string::npos) { tfile.Ending = fname.substr(dot_pos,end_pos-dot_pos); } else { tfile.Ending = ""; } std::cout << tfile.Ending << std::endl; if (tfile.Ending == "png" || tfile.Ending == "jpg" || tfile.Ending == "webp" || tfile.Ending == "ico" || tfile.Ending == "svg") { tfile.Type = ThemeFilesTypes::IMAGE; } Loading Loading @@ -253,14 +287,39 @@ bool blogi::Theme::Controller(const int tid,libhttppp::HttpRequest &req){ } #include <algorithm> #include <cctype> #include <string> bool blogi::Theme::Response(const int tid, libhttppp::HttpRequest &req){ std::string publicf = req.getRequestURL(); if(publicf.length() >_Config.config.getprefix().length() && publicf.compare(_Config.config.getprefix().length(),13,"/theme/public/",13)==0){ auto to_lower = [](const std::string& str) { std::string data = str; std::transform(data.begin(), data.end(), data.begin(), [](unsigned char c){ return std::tolower(c); }); return data; }; std::string publicf = to_lower(req.getRequestURL()); std::string prefix_lower = to_lower(_Config.config.getprefix()); size_t prefix_len = prefix_lower.length(); const std::string public_theme_path = "/theme/public/"; size_t public_theme_path_len = public_theme_path.length(); if(publicf.length() > prefix_len && publicf.compare(prefix_len, public_theme_path_len, public_theme_path, public_theme_path_len) == 0) { for(auto curfile=_PublicFiles.begin(); curfile!=_PublicFiles.end(); curfile++){ if(publicf.compare(_Config.config.getprefix().length(),curfile->Path.length(),curfile->Path,0,curfile->Path.length())==0){ // 3. Convert the stored file path to lowercase for case-insensitive comparison std::string curfile_path_lower = to_lower(curfile->Path); size_t curfile_path_len = curfile_path_lower.length(); if(publicf.compare(prefix_len, curfile_path_len, curfile_path_lower, curfile_path_len) == 0){ if(req.SendData.pos < curfile->Content.length() ){ if( curfile->Compressed.length() > 0 && req.getHeaderData("accept-encoding") && req.getHeaderData("accept-encoding")->at(0).getvalue().find("br") != std::string::npos){ && to_lower(req.getHeaderData("accept-encoding")->at(0).getvalue()).find("br") != std::string::npos){ size_t len = BLOCKSIZE < curfile->Compressed.length()-req.SendData.pos ? BLOCKSIZE : curfile->Compressed.length()-req.SendData.pos; req.SendData.append(curfile->Compressed.substr(req.SendData.pos,len).c_str(),len); Loading @@ -275,7 +334,6 @@ bool blogi::Theme::Response(const int tid,libhttppp::HttpRequest &req){ } } } } return false; } Loading Loading
src/theme.cpp +66 −8 Changes for src/theme.cpp: 66 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -45,6 +45,37 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated) : _Config(config){ auto trimlines = [&] (const std::string in){ std::string out; bool space=false; for(auto i : in){ switch(i){ case '\r': space=true; continue; case '\n': if(!space) out.push_back(' '); space=true; continue; case '\t': if(!space) out.push_back(' '); space=true; continue; case ' ': if(space) continue; space=true; default: space=false; out.push_back(i); break; } } return out; }; _Formated=formated; std::string ppath(_Config.Theme); Loading Loading @@ -88,16 +119,19 @@ blogi::Theme::Theme(blogi::ThemeConfig& config,bool formated) : _Config(config){ // Construct the path string using the filename tfile.Path = "/theme/public/" + entry.path().filename().string(); tfile.Content = buf; tfile.Content = trimlines(buf); std::string fname = entry.path().filename().string(); size_t dot_pos = fname.rfind('.'); if (dot_pos != std::string::npos) { tfile.Ending = fname.substr(dot_pos + 1); size_t end_pos = fname.rfind('?') != std::string::npos ? fname.rfind('?') : fname.length(); if (++dot_pos != std::string::npos) { tfile.Ending = fname.substr(dot_pos,end_pos-dot_pos); } else { tfile.Ending = ""; } std::cout << tfile.Ending << std::endl; if (tfile.Ending == "png" || tfile.Ending == "jpg" || tfile.Ending == "webp" || tfile.Ending == "ico" || tfile.Ending == "svg") { tfile.Type = ThemeFilesTypes::IMAGE; } Loading Loading @@ -253,14 +287,39 @@ bool blogi::Theme::Controller(const int tid,libhttppp::HttpRequest &req){ } #include <algorithm> #include <cctype> #include <string> bool blogi::Theme::Response(const int tid, libhttppp::HttpRequest &req){ std::string publicf = req.getRequestURL(); if(publicf.length() >_Config.config.getprefix().length() && publicf.compare(_Config.config.getprefix().length(),13,"/theme/public/",13)==0){ auto to_lower = [](const std::string& str) { std::string data = str; std::transform(data.begin(), data.end(), data.begin(), [](unsigned char c){ return std::tolower(c); }); return data; }; std::string publicf = to_lower(req.getRequestURL()); std::string prefix_lower = to_lower(_Config.config.getprefix()); size_t prefix_len = prefix_lower.length(); const std::string public_theme_path = "/theme/public/"; size_t public_theme_path_len = public_theme_path.length(); if(publicf.length() > prefix_len && publicf.compare(prefix_len, public_theme_path_len, public_theme_path, public_theme_path_len) == 0) { for(auto curfile=_PublicFiles.begin(); curfile!=_PublicFiles.end(); curfile++){ if(publicf.compare(_Config.config.getprefix().length(),curfile->Path.length(),curfile->Path,0,curfile->Path.length())==0){ // 3. Convert the stored file path to lowercase for case-insensitive comparison std::string curfile_path_lower = to_lower(curfile->Path); size_t curfile_path_len = curfile_path_lower.length(); if(publicf.compare(prefix_len, curfile_path_len, curfile_path_lower, curfile_path_len) == 0){ if(req.SendData.pos < curfile->Content.length() ){ if( curfile->Compressed.length() > 0 && req.getHeaderData("accept-encoding") && req.getHeaderData("accept-encoding")->at(0).getvalue().find("br") != std::string::npos){ && to_lower(req.getHeaderData("accept-encoding")->at(0).getvalue()).find("br") != std::string::npos){ size_t len = BLOCKSIZE < curfile->Compressed.length()-req.SendData.pos ? BLOCKSIZE : curfile->Compressed.length()-req.SendData.pos; req.SendData.append(curfile->Compressed.substr(req.SendData.pos,len).c_str(),len); Loading @@ -275,7 +334,6 @@ bool blogi::Theme::Response(const int tid,libhttppp::HttpRequest &req){ } } } } return false; } Loading