Added a new FolderServeNode.

This commit is contained in:
Relintai 2022-02-06 09:21:01 +01:00
parent 7dbc34137a
commit c592484350
4 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,12 @@
#!/usr/bin/env python
Import("env_mod")
Import("env")
env_mod.core_sources = []
env_mod.add_source_files(env_mod.core_sources, "*.cpp")
# Build it all as a library
lib = env_mod.add_library("paged_list", env_mod.core_sources)
env.Prepend(LIBS=[lib])

View File

@ -0,0 +1,27 @@
import os
import platform
import sys
def is_active():
return True
def get_name():
return "paged_list"
def can_build():
return True
def get_opts():
return []
def get_flags():
return []
def configure(env):
pass

View File

@ -0,0 +1,56 @@
#include "folder_serve_node.h"
#include "web/file_cache.h"
#include "web/html/html_builder.h"
#include "web/http/request.h"
void FolderServeNode::handle_request_main(Request *request) {
const String &rp = request->get_current_path_segment();
if (rp == "") {
request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND);
return;
}
String file_name = "/" + request->get_path();
if (file_cache->wwwroot_has_file(file_name)) {
String fp = file_cache->wwwroot;
fp.append_path(file_name);
request->send_file(fp);
return;
}
if (!try_route_request_to_children(request)) {
_handle_request_main(request);
}
}
void FolderServeNode::load() {
file_cache->clear();
if (serve_folder == "") {
return;
}
file_cache->wwwroot = serve_folder;
file_cache->wwwroot_refresh_cache();
}
void FolderServeNode::_notification(const int what) {
switch (what) {
case NOTIFICATION_ENTER_TREE:
load();
break;
default:
break;
}
}
FolderServeNode::FolderServeNode() :
WebNode() {
}
FolderServeNode::~FolderServeNode() {
}

View File

@ -0,0 +1,27 @@
#ifndef FOLDER_SERVE_NODE_H
#define FOLDER_SERVE_NODE_H
#include "core/string.h"
#include "web/http/web_node.h"
class FolderServeNode : public WebNode {
RCPP_OBJECT(FolderServeNode, WebNode);
public:
void handle_request_main(Request *request);
virtual void load();
void _notification(const int what);
String serve_folder;
FolderServeNode();
~FolderServeNode();
protected:
FileCache *file_cache;
};
#endif