From bd381c164a0b34011167af2095f2a9626f2841d3 Mon Sep 17 00:00:00 2001 From: Victor Hiairrassary Date: Mon, 16 Dec 2024 20:52:18 +0100 Subject: [PATCH] Extract the playground in its own HTML file (#24) --- CMakeLists.txt | 21 +- embed.cmake | 18 + src/assets/index.html | 808 +++++++++++++++++++++++++++++++++++ src/httpserver_extension.cpp | 4 +- src/include/play.h | 11 - 5 files changed, 846 insertions(+), 16 deletions(-) create mode 100644 embed.cmake create mode 100644 src/assets/index.html delete mode 100644 src/include/play.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9eeef49..435c3dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,24 @@ set(EXTENSION_NAME ${TARGET_NAME}_extension) set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension) project(${TARGET_NAME}) -include_directories(src/include duckdb/third_party/httplib duckdb/parquet/include) - -set(EXTENSION_SOURCES src/httpserver_extension.cpp) +include_directories( + src/include + ${CMAKE_CURRENT_BINARY_DIR} + duckdb/third_party/httplib + duckdb/parquet/include +) + +# Embed ./src/assets/index.html as a C++ header +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/playground.hpp + COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/embed.cmake ${PROJECT_SOURCE_DIR}/src/assets/index.html ${CMAKE_CURRENT_BINARY_DIR}/playground.hpp playgroundContent + DEPENDS ${PROJECT_SOURCE_DIR}/src/assets/index.html +) + +set(EXTENSION_SOURCES + src/httpserver_extension.cpp + ${CMAKE_CURRENT_BINARY_DIR}/playground.hpp +) if(MINGW) set(OPENSSL_USE_STATIC_LIBS TRUE) diff --git a/embed.cmake b/embed.cmake new file mode 100644 index 0000000..f60cc4d --- /dev/null +++ b/embed.cmake @@ -0,0 +1,18 @@ +set(resource_file_name ${CMAKE_ARGV3}) +set(output_file_name ${CMAKE_ARGV4}) +set(variable_name ${CMAKE_ARGV5}) + +file(READ "${resource_file_name}" hex_content HEX) + +string(REPEAT "[0-9a-f]" 32 pattern) +string(REGEX REPLACE "(${pattern})" "\\1\n" content "${hex_content}") + +string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " content "${content}") + +string(REGEX REPLACE ", $" "" content "${content}") + +set(array_definition "static const unsigned char ${variable_name}[] =\n{\n${content}\n};") + +set(output "// Auto generated file.\n${array_definition}\n") + +file(WRITE "${output_file_name}" "${output}") diff --git a/src/assets/index.html b/src/assets/index.html new file mode 100644 index 0000000..c74d80c --- /dev/null +++ b/src/assets/index.html @@ -0,0 +1,808 @@ + + + + + + + + + quackpipe + + + + + +
+
+ + + +
+
+ +
+ +
+ +  (Ctrl/Cmd+Enter) + + + 🌑 + 🌞 +
+
+ +
+
+

+        
+ +
+ +

+

+ + + + \ No newline at end of file diff --git a/src/httpserver_extension.cpp b/src/httpserver_extension.cpp index 62ae297..65a9aa0 100644 --- a/src/httpserver_extension.cpp +++ b/src/httpserver_extension.cpp @@ -21,7 +21,7 @@ #include "httplib.hpp" #include "yyjson.hpp" -#include "play.h" +#include "playground.hpp" using namespace duckdb_yyjson; // NOLINT @@ -255,7 +255,7 @@ void HandleHttpRequest(const duckdb_httplib_openssl::Request& req, duckdb_httpli // If no query found, return an error else { res.status = 200; - res.set_content(playContent, "text/html"); + res.set_content(reinterpret_cast(playgroundContent), "text/html"); return; } diff --git a/src/include/play.h b/src/include/play.h deleted file mode 100644 index d670a5f..0000000 --- a/src/include/play.h +++ /dev/null @@ -1,11 +0,0 @@ -// -// Created by hromozeka on 14.10.24. -// - -#ifndef PLAY_H -#define PLAY_H - -const char *playContent = " 🐤\"> quackpipe
 (Ctrl/Cmd+Enter) 🌑🌞
 

"; - -#endif //PLAY_H