mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-10 00:52:11 +01:00
Added a new FolderServeNode.
This commit is contained in:
parent
7dbc34137a
commit
c592484350
12
web_modules/folder_serve_nodes/SCsub
Normal file
12
web_modules/folder_serve_nodes/SCsub
Normal 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])
|
27
web_modules/folder_serve_nodes/detect.py
Normal file
27
web_modules/folder_serve_nodes/detect.py
Normal 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
|
56
web_modules/folder_serve_nodes/folder_serve_node.cpp
Normal file
56
web_modules/folder_serve_nodes/folder_serve_node.cpp
Normal 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() {
|
||||
}
|
27
web_modules/folder_serve_nodes/folder_serve_node.h
Normal file
27
web_modules/folder_serve_nodes/folder_serve_node.h
Normal 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
|
Loading…
Reference in New Issue
Block a user