From 602d8a68365e8dac1b1f2453527335440ff42089 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 4 May 2024 16:13:52 +0200 Subject: [PATCH] Use HashMap in BrowsableFolderServeWebPage, as the bug that was preventing this was already fixed quite a while ago. --- .../browsable_folder_serve_web_page.cpp | 30 ++++++++----------- .../browsable_folder_serve_web_page.h | 9 ++---- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/modules/web/nodes/folder_serve_nodes/browsable_folder_serve_web_page.cpp b/modules/web/nodes/folder_serve_nodes/browsable_folder_serve_web_page.cpp index ee464a26d..4cc3175c3 100644 --- a/modules/web/nodes/folder_serve_nodes/browsable_folder_serve_web_page.cpp +++ b/modules/web/nodes/folder_serve_nodes/browsable_folder_serve_web_page.cpp @@ -51,21 +51,19 @@ void BrowsableFolderServeWebPage::set_should_render_menu(const bool &val) { void BrowsableFolderServeWebPage::_handle_request(Ref request) { String file_name = request->get_path(true, false); - for (int i = 0; i < _folder_indexes.size(); ++i) { - const BFSNEntry &e = _folder_indexes[i]; + String *data = _folder_indexes.getptr(file_name); - if (e.uri == file_name) { - if (_should_render_menu) { - render_menu(request); - } - - request->body += e.data; - request->compile_and_send_body(); - return; - } + if (!data) { + request->send_error(HTTPServerEnums::HTTP_STATUS_CODE_404_NOT_FOUND); + return; } - request->send_error(HTTPServerEnums::HTTP_STATUS_CODE_404_NOT_FOUND); + if (_should_render_menu) { + render_menu(request); + } + + request->body += *data; + request->compile_and_send_body(); } void BrowsableFolderServeWebPage::_render_index(Ref request) { @@ -106,7 +104,7 @@ void BrowsableFolderServeWebPage::evaluate_dir(const String &path, const bool to String file = dir->get_next(); - while (file != "") { + while (!file.empty()) { String np = path.append_path(file); String nnp = np.substr(serve_folder.length(), np.length() - serve_folder.length()); @@ -168,11 +166,7 @@ void BrowsableFolderServeWebPage::render_dir_page(const String &dir_uri, const V } b.cdiv(); - BFSNEntry e; - e.uri = dir_uri; - e.data = b.result; - - _folder_indexes.push_back(e); + _folder_indexes[dir_uri] = b.result; if (dir_uri == "/") { _index = b.result; diff --git a/modules/web/nodes/folder_serve_nodes/browsable_folder_serve_web_page.h b/modules/web/nodes/folder_serve_nodes/browsable_folder_serve_web_page.h index c24fb9552..887417b6e 100644 --- a/modules/web/nodes/folder_serve_nodes/browsable_folder_serve_web_page.h +++ b/modules/web/nodes/folder_serve_nodes/browsable_folder_serve_web_page.h @@ -32,7 +32,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "core/containers/vector.h" +#include "core/containers/hash_map.h" #include "core/string/ustring.h" #include "folder_serve_web_page.h" @@ -76,12 +76,7 @@ protected: bool _should_render_menu; - struct BFSNEntry { - String uri; - String data; - }; - - Vector _folder_indexes; + HashMap _folder_indexes; String _index; };