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) {
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 (!data) {
request->send_error(HTTPServerEnums::HTTP_STATUS_CODE_404_NOT_FOUND);
return;
}
if (e.uri == file_name) {
if (_should_render_menu) {
render_menu(request);
}
request->body += e.data;
request->body += *data;
request->compile_and_send_body();
return;
}
}
request->send_error(HTTPServerEnums::HTTP_STATUS_CODE_404_NOT_FOUND);
}
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();
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;

View File

@ -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<BFSNEntry> _folder_indexes;
HashMap<String, String> _folder_indexes;
String _index;
};