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 "web/http/request.h"
#include "web/file_cache.h"
#include "web/html/html_builder.h"
void StaticPageFile::handle_request_main(Request *request) {
}
#include "web/http/request.h"
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() :
WebNode() {
StaticPage() {
process_if_can = true;
}
StaticPageFile::~StaticPageFile() {

View File

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

View File

@ -1,17 +1,56 @@
#include "static_page_folder_files.h"
#include "web/http/request.h"
#include "core/os/directory.h"
#include "web/file_cache.h"
#include "web/html/html_builder.h"
void StaticPageFolderFiles::handle_request_main(Request *request) {
}
#include "web/html/utils.h"
#include "web/http/request.h"
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() :
WebNode() {
StaticPage() {
process_if_can = true;
}
StaticPageFolderFiles::~StaticPageFolderFiles() {

View File

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