Use HashMap in BrowsableFolderServeWebPage, as the bug that was preventing this was already fixed quite a while ago.

This commit is contained in:
Relintai 2024-05-04 16:13:52 +02:00
parent 61cecf068a
commit 602d8a6836
2 changed files with 14 additions and 25 deletions

View File

@ -51,21 +51,19 @@ void BrowsableFolderServeWebPage::set_should_render_menu(const bool &val) {
void BrowsableFolderServeWebPage::_handle_request(Ref<WebServerRequest> request) { void BrowsableFolderServeWebPage::_handle_request(Ref<WebServerRequest> request) {
String file_name = request->get_path(true, false); String file_name = request->get_path(true, false);
for (int i = 0; i < _folder_indexes.size(); ++i) { String *data = _folder_indexes.getptr(file_name);
const BFSNEntry &e = _folder_indexes[i];
if (e.uri == file_name) { if (!data) {
if (_should_render_menu) { request->send_error(HTTPServerEnums::HTTP_STATUS_CODE_404_NOT_FOUND);
render_menu(request); return;
}
request->body += e.data;
request->compile_and_send_body();
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<WebServerRequest> request) { void BrowsableFolderServeWebPage::_render_index(Ref<WebServerRequest> request) {
@ -106,7 +104,7 @@ void BrowsableFolderServeWebPage::evaluate_dir(const String &path, const bool to
String file = dir->get_next(); String file = dir->get_next();
while (file != "") { while (!file.empty()) {
String np = path.append_path(file); String np = path.append_path(file);
String nnp = np.substr(serve_folder.length(), np.length() - serve_folder.length()); 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(); b.cdiv();
BFSNEntry e; _folder_indexes[dir_uri] = b.result;
e.uri = dir_uri;
e.data = b.result;
_folder_indexes.push_back(e);
if (dir_uri == "/") { if (dir_uri == "/") {
_index = b.result; _index = b.result;

View File

@ -32,7 +32,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* 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 "core/string/ustring.h"
#include "folder_serve_web_page.h" #include "folder_serve_web_page.h"
@ -76,12 +76,7 @@ protected:
bool _should_render_menu; bool _should_render_menu;
struct BFSNEntry { HashMap<String, String> _folder_indexes;
String uri;
String data;
};
Vector<BFSNEntry> _folder_indexes;
String _index; String _index;
}; };