Pārlūkot izejas kodu

Add python scripts to make all resources pack in binary

xcbosa-itx 2 gadi atpakaļ
vecāks
revīzija
cda9c0d9dd

+ 2 - 0
.gitignore

@@ -1,2 +1,4 @@
 cmake-build-debug
 cmake-build-debug
 node_modules
 node_modules
+.idea
+.DS_Store

+ 0 - 8
.idea/.gitignore

@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml

+ 0 - 2
.idea/FRPCWebUI.iml

@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module classpath="CMake" type="CPP_MODULE" version="4" />

+ 0 - 4
.idea/misc.xml

@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
-</project>

+ 0 - 8
.idea/modules.xml

@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="ProjectModuleManager">
-    <modules>
-      <module fileurl="file://$PROJECT_DIR$/.idea/FRPCWebUI.iml" filepath="$PROJECT_DIR$/.idea/FRPCWebUI.iml" />
-    </modules>
-  </component>
-</project>

+ 0 - 6
.idea/vcs.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="VcsDirectoryMappings">
-    <mapping directory="$PROJECT_DIR$" vcs="Git" />
-  </component>
-</project>

+ 20 - 0
CMakeLists.txt

@@ -3,6 +3,26 @@ project(FRPCWebUI)
 
 
 set(CMAKE_CXX_STANDARD 17)
 set(CMAKE_CXX_STANDARD 17)
 
 
+execute_process(
+        COMMAND ${CMAKE_SOURCE_DIR}/data/Generate-Assets.py index.js
+        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/data
+)
+
+execute_process(
+        COMMAND ${CMAKE_SOURCE_DIR}/data/Generate-Assets.py index.css
+        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/data
+)
+
+execute_process(
+        COMMAND ${CMAKE_SOURCE_DIR}/data/Generate-Assets.py framework7/framework7-bundle.min.js
+        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/data
+)
+
+execute_process(
+        COMMAND ${CMAKE_SOURCE_DIR}/data/Generate-Assets.py framework7/framework7-bundle.min.css
+        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/data
+)
+
 aux_source_directory(. DIR_SRCS)
 aux_source_directory(. DIR_SRCS)
 aux_source_directory(controller DIR_CONTROLLERS)
 aux_source_directory(controller DIR_CONTROLLERS)
 aux_source_directory(view DIR_VIEW)
 aux_source_directory(view DIR_VIEW)

+ 1 - 0
controller/StaticWebPageController.cpp

@@ -18,6 +18,7 @@ using namespace configor;
 namespace xc::controller {
 namespace xc::controller {
 
 
     ContentGeneratorDefine({
     ContentGeneratorDefine({
+                               if (!conf::enableStaticAssetsController) { return false; }
                                if (request.getMethod() != "GET") { return false; }
                                if (request.getMethod() != "GET") { return false; }
                                if (request.getURL().length() == 0) { return false; }
                                if (request.getURL().length() == 0) { return false; }
                                struct stat buffer;
                                struct stat buffer;

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 31 - 0
controller/framework7-framework7-bundle.min.css.cpp


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 31 - 0
controller/framework7-framework7-bundle.min.js.cpp


+ 26 - 0
controller/index.css.cpp

@@ -0,0 +1,26 @@
+//
+// Created by xcbosa on 2023-01-30
+//
+
+#include "../processor/processor.h"
+#include "../utils/utils.h"
+#include "../webuiconf.h"
+
+using namespace std;
+using namespace xc::processor;
+using namespace xc::utils;
+using namespace xc::processor::templates;
+
+namespace xc::controller {
+
+    static string ControllerPath = "/index.css";
+
+    static ResponseData *controllerResponse(RequestData request) {
+        return new TextResponseData(200,
+""
+        , mimeTypeOfFile(ControllerPath));
+    }
+
+    ContentGeneratorDefineS(request.getURL() == ControllerPath, controllerResponse(request))
+
+}

+ 45 - 0
controller/index.js.cpp

@@ -0,0 +1,45 @@
+//
+// Created by xcbosa on 2023-01-30
+//
+
+#include "../processor/processor.h"
+#include "../utils/utils.h"
+#include "../webuiconf.h"
+
+using namespace std;
+using namespace xc::processor;
+using namespace xc::utils;
+using namespace xc::processor::templates;
+
+namespace xc::controller {
+
+    static string ControllerPath = "/index.js";
+
+    static ResponseData *controllerResponse(RequestData request) {
+        return new TextResponseData(200,
+            string("let app = new Framework7({\n") + 
+            string("    // App root element\n") + 
+            string("    el: \'#app\',\n") + 
+            string("    // App Name\n") + 
+            string("    name: \'FRPCWebUI\',\n") + 
+            string("    // App id\n") + 
+            string("    id: \'org.forgetive.frpcwebui\',\n") + 
+            string("    // Enable swipe panel\n") + 
+            string("    panel: {\n") + 
+            string("        swipe: true,\n") + 
+            string("    },\n") + 
+            string("    // Add default routes\n") + 
+            string("    routes: [\n") + 
+            string("        {\n") + 
+            string("            path: \'/about/\',\n") + 
+            string("            url: \'about.html\',\n") + 
+            string("        },\n") + 
+            string("    ],\n") + 
+            string("    // ... other parameters\n") + 
+            string("});\n")
+        , mimeTypeOfFile(ControllerPath));
+    }
+
+    ContentGeneratorDefineS(request.getURL() == ControllerPath, controllerResponse(request))
+
+}

+ 51 - 0
data/Generate-Assets.py

@@ -0,0 +1,51 @@
+#!/usr/bin/python3
+
+# 使用此脚本将data/html下的代码转换成写死的Controller
+
+import os
+import sys
+import datetime
+
+if __name__ == "__main__":
+    if len(sys.argv) != 2:
+        print("usage: Generate-Assets <AssetFilePath>")
+        exit(-1)
+        pass
+    assetPath = sys.argv[1]
+    with open("html/" + assetPath, "r", encoding="utf-8") as f:
+        fileTexts = []
+        for it in f.readlines():
+            lineText = it.replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "").replace("\'", "\\'").replace("\"", "\\\"")
+            lineText = "            string(\"" + lineText + "\")"
+            fileTexts.append(lineText)
+        fileText = " + \n".join(fileTexts)
+        if len(fileTexts) == 0:
+            fileText = "\"\""
+        writeToFilePath = "../controller/" + assetPath.replace("/", "-") + ".cpp"
+        print("Writing to " + writeToFilePath)
+        with open(writeToFilePath, "w+", encoding="utf-8") as w:
+            w.write("//\n")
+            w.write("// Created by xcbosa on " + str(datetime.date.today()) + "\n")
+            w.write("//\n")
+            w.write("\n")
+            w.write("#include \"../processor/processor.h\"\n")
+            w.write("#include \"../utils/utils.h\"\n")
+            w.write("#include \"../webuiconf.h\"\n")
+            w.write("\n")
+            w.write("using namespace std;\n")
+            w.write("using namespace xc::processor;\n")
+            w.write("using namespace xc::utils;\n")
+            w.write("using namespace xc::processor::templates;\n")
+            w.write("\n")
+            w.write("namespace xc::controller {\n")
+            w.write("\n")
+            w.write("    static string ControllerPath = \"/" + assetPath + "\";\n\n")
+            w.write("    static ResponseData *controllerResponse(RequestData request) {\n")
+            w.write("        return new TextResponseData(200,\n")
+            w.write(fileText + "\n")
+            w.write("        , mimeTypeOfFile(ControllerPath));\n")
+            w.write("    }\n\n")
+            w.write("    ContentGeneratorDefineS(request.getURL() == ControllerPath, controllerResponse(request))\n")
+            w.write("\n")
+            w.write("}\n")
+

BIN
data/html/.DS_Store


+ 1 - 1
processor/templates/framework7/Framework7Document.hpp

@@ -40,7 +40,7 @@ namespace xc::processor::templates::framework7 {
                                 p("Page content goes here"),
                                 p("Page content goes here"),
                                 a("About app").href("/about/")
                                 a("About app").href("/about/")
                             }).classAdd("page-content")
                             }).classAdd("page-content")
-
+                            
                         }).prop("data-name", "home").classAdd("page")
                         }).prop("data-name", "home").classAdd("page")
                     }).classAdd("view view-main")
                     }).classAdd("view view-main")
                 }).id("app"),
                 }).id("app"),

+ 2 - 0
webuiconf.h

@@ -16,6 +16,8 @@ namespace xc::conf {
     const int taskProcessTimeoutSeconds = 1;
     const int taskProcessTimeoutSeconds = 1;
     const int mtu = 1536;
     const int mtu = 1536;
 
 
+    const bool enableStaticAssetsController = false;
+
     const map<string, string> fileExtensionToMimeTypes = {
     const map<string, string> fileExtensionToMimeTypes = {
             { ".html", "text/html" },
             { ".html", "text/html" },
             { ".htm", "text/html" },
             { ".htm", "text/html" },

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels