Implemented StaticPageFile and StaticPageFolderFiles aswell.

This commit is contained in:
Relintai 2022-02-06 14:01:04 +01:00
parent f7b17933b5
commit 3a834204d8
4 changed files with 84 additions and 20 deletions

View File

@ -1,17 +1,35 @@
#include "static_page_file.h" #include "static_page_file.h"
#include "web/http/request.h"
#include "web/file_cache.h" #include "web/file_cache.h"
#include "web/html/html_builder.h" #include "web/html/html_builder.h"
#include "web/http/request.h"
void StaticPageFile::handle_request_main(Request *request) {
}
void StaticPageFile::load() { void StaticPageFile::load() {
if (file_path == "") {
return;
}
if (process_if_can) {
load_and_process_file(file_path);
} else {
load_file(file_path);
}
}
void StaticPageFile::_notification(const int what) {
switch (what) {
case NOTIFICATION_ENTER_TREE:
load();
break;
default:
break;
}
} }
StaticPageFile::StaticPageFile() : StaticPageFile::StaticPageFile() :
WebNode() { StaticPage() {
process_if_can = true;
} }
StaticPageFile::~StaticPageFile() { StaticPageFile::~StaticPageFile() {

View File

@ -3,16 +3,19 @@
#include "core/string.h" #include "core/string.h"
#include "web/http/web_node.h" #include "static_page.h"
class StaticPageFile : public WebNode { class StaticPageFile : public StaticPage {
RCPP_OBJECT(StaticPageFile, WebNode); RCPP_OBJECT(StaticPageFile, StaticPage);
public: public:
void handle_request_main(Request *request);
void load(); void load();
void _notification(const int what);
String file_path;
bool process_if_can;
StaticPageFile(); StaticPageFile();
~StaticPageFile(); ~StaticPageFile();
}; };

View File

@ -1,17 +1,56 @@
#include "static_page_folder_files.h" #include "static_page_folder_files.h"
#include "web/http/request.h" #include "core/os/directory.h"
#include "web/file_cache.h" #include "web/file_cache.h"
#include "web/html/html_builder.h" #include "web/html/html_builder.h"
#include "web/html/utils.h"
void StaticPageFolderFiles::handle_request_main(Request *request) { #include "web/http/request.h"
}
void StaticPageFolderFiles::load() { void StaticPageFolderFiles::load() {
if (dir_path == "") {
return;
}
Ref<Directory> d;
d.instance();
ERR_FAIL_COND_MSG(!d->open_dir(dir_path), "Dir Path = " + dir_path);
String str;
while (d->has_next()) {
if (d->current_is_file()) {
String fn = dir_path;
fn.append_path(d->current_get_name_cstr());
d->read_file_into(fn, &str);
if (process_if_can && d->current_get_extension() == "md") {
Utils::markdown_to_html(&str);
}
append_data(str);
}
}
}
void StaticPageFolderFiles::append_data(const String &d) {
data += d;
}
void StaticPageFolderFiles::_notification(const int what) {
switch (what) {
case NOTIFICATION_ENTER_TREE:
load();
break;
default:
break;
}
} }
StaticPageFolderFiles::StaticPageFolderFiles() : StaticPageFolderFiles::StaticPageFolderFiles() :
WebNode() { StaticPage() {
process_if_can = true;
} }
StaticPageFolderFiles::~StaticPageFolderFiles() { StaticPageFolderFiles::~StaticPageFolderFiles() {

View File

@ -3,15 +3,19 @@
#include "core/string.h" #include "core/string.h"
#include "web/http/web_node.h" #include "static_page.h"
class StaticPageFolderFiles : public WebNode { class StaticPageFolderFiles : public StaticPage {
RCPP_OBJECT(StaticPageFolderFiles, WebNode); RCPP_OBJECT(StaticPageFolderFiles, StaticPage);
public: public:
void handle_request_main(Request *request);
void load(); void load();
virtual void append_data(const String &d);
void _notification(const int what);
String dir_path;
bool process_if_can;
StaticPageFolderFiles(); StaticPageFolderFiles();
~StaticPageFolderFiles(); ~StaticPageFolderFiles();