diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 69854a7..93c3bc3 100755 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -37,15 +37,24 @@ jobs: cat notify.tpl | envsubst | jq -sR . | xargs -0 -I {} curl -H "Content-Type: application/json" -X POST -d '{"type":"text","msg":{} }' https://amass.fun/notify - run: resources/build.sh build - run: resources/build.sh lvgl - - name: Copy app wt resources to server + - name: copy wt resources to server uses: appleboy/scp-action@v0.1.7 with: host: ${{ vars.YUYUN_SERVER }} username: ${{ vars.YUYUN_USER }} password: ${{ secrets.SERVER_ROOT_PASSWORD }} overwrite: true - source: "resources/*.css,resources/*.xml" + source: "resources/*.css" target: /root/Server/amass_blog + - name: copy wt app to server + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ vars.YUYUN_SERVER }} + username: ${{ vars.YUYUN_USER }} + password: ${{ secrets.SERVER_ROOT_PASSWORD }} + overwrite: true + source: "resources/*.xml" + target: /root/Server - name: Copy lvgl to server uses: appleboy/scp-action@v0.1.7 with: diff --git a/Server/Application.h b/Server/Application.h index 7567674..4180e7b 100644 --- a/Server/Application.h +++ b/Server/Application.h @@ -29,11 +29,11 @@ public: BUILD_SETTING(uint16_t, Port, 8081); BUILD_SETTING(uint16_t, WtPort, 8082); BUILD_SETTING(uint32_t, Threads, std::thread::hardware_concurrency()); - BUILD_SETTING(std::string, DocumentRoot, "."); + BUILD_SETTING(std::string, ApplicationRoot, "."); // 内部配置文件,不应被外部访问 + BUILD_SETTING(std::string, DocumentRoot, "."); // 外部可访问的公共文件 BUILD_SETTING(std::string, HomeAssistantAccessToken, ""); - BUILD_SETTING(std::string, Live2dModelsRoot, "./live2d"); - INITIALIZE_FIELDS(Server, Port, Threads, DocumentRoot); + INITIALIZE_FIELDS(Server, Port, Threads, ApplicationRoot, DocumentRoot); Application(const std::string &path); boost::asio::io_context &ioContext(); int exec(); diff --git a/Server/Live2dBackend.cpp b/Server/Live2dBackend.cpp index 3304a2d..9ea243f 100644 --- a/Server/Live2dBackend.cpp +++ b/Server/Live2dBackend.cpp @@ -3,13 +3,14 @@ #include "HttpSession.h" #include "ServiceLogic.h" #include +#include Live2dBackend::Live2dBackend() { using namespace Amass; auto application = Singleton::instance(); - application->insertUrl("/api/v1/live2d/{path*}", [this, live2dModelsRoot{application->getLive2dModelsRoot()}]( - HttpSession &session, const Application::Request &request, - const boost::urls::matches &matches) { + m_live2dModelsRoot = std::format("{}/resources/live2d", application->getDocumentRoot()); + application->insertUrl("/api/v1/live2d/{path*}", [this](HttpSession &session, const Application::Request &request, + const boost::urls::matches &matches) { using namespace boost::beast; boost::urls::url_view view(request.target()); auto target = view.path(); @@ -18,7 +19,7 @@ Live2dBackend::Live2dBackend() { session.reply(ServiceLogic::badRequest(request, "Illegal request-target")); return; } - std::string path = ResponseUtility::pathCat(live2dModelsRoot, matches["path"]); + std::string path = ResponseUtility::pathCat(m_live2dModelsRoot, matches["path"]); if (target.back() == '/') path.append("index.html"); if (std::filesystem::is_directory(path)) path.append("/index.html"); boost::beast::error_code ec; diff --git a/Server/Live2dBackend.h b/Server/Live2dBackend.h index 7d8d099..c070dcf 100644 --- a/Server/Live2dBackend.h +++ b/Server/Live2dBackend.h @@ -1,9 +1,13 @@ #ifndef __LIVE2DBACKEND_H__ #define __LIVE2DBACKEND_H__ +#include class Live2dBackend { public: Live2dBackend(); + +private: + std::string m_live2dModelsRoot; }; #endif // __LIVE2DBACKEND_H__ \ No newline at end of file diff --git a/Server/main.cpp b/Server/main.cpp index d183350..7dbabdc 100644 --- a/Server/main.cpp +++ b/Server/main.cpp @@ -55,7 +55,7 @@ int main(int argc, char const *argv[]) { return -1; } std::filesystem::current_path(prefix, error); - LOG_IF(fatal, error) << "cannot set current path,reason: " << error.message(); + LOG_IF(fatal, error) << "cannot set current path, reason: " << error.message(); } auto application = Singleton::instance("settings.ini"); @@ -64,7 +64,7 @@ int main(int argc, char const *argv[]) { std::exit(102); } BOOST_ASSERT_MSG(!application->getServer().empty(), "server.empty() == true"); - Database::initialize(std::format("{}/database.sqlite", application->getDocumentRoot())); + Database::initialize(std::format("{}/database.sqlite", application->getApplicationRoot())); auto address = boost::asio::ip::make_address(application->getServer()); auto listener = std::make_shared(application->ioContext(), boost::asio::ip::tcp::endpoint{address, application->getPort()}); @@ -96,7 +96,7 @@ int main(int argc, char const *argv[]) { auto udpServer = std::make_shared(application->ioContext()); auto mediaServer = std::make_shared(554, false); - auto webApp = Singleton::instance(application->getWtPort(), application->getDocumentRoot()); + auto webApp = Singleton::instance(application->getWtPort(), application->getApplicationRoot(), application->getDocumentRoot()); using namespace boost::asio::ip; auto proxyAddress = make_address(application->getServer()); diff --git a/WebApplication/Application.cpp b/WebApplication/Application.cpp index 81d961f..105c073 100644 --- a/WebApplication/Application.cpp +++ b/WebApplication/Application.cpp @@ -117,15 +117,15 @@ void Application::handlePathChange(const std::string &path) { } } -Server::Server(uint16_t port, const std::string &documentRoot) { +Server::Server(uint16_t port, const std::string &applicationRoot, const std::string &documentRoot) { try { std::vector args; args.push_back(std::format("--docroot={};/resources", documentRoot)); - args.push_back(std::format("--approot={}/resources", documentRoot)); + args.push_back(std::format("--approot={}/resources", applicationRoot)); args.push_back(std::format("--http-listen=127.0.0.1:{}", port)); initializeAuthenticationService(); - m_server = std::make_unique(std::format("{}/resources", documentRoot), args); + m_server = std::make_unique(std::format("{}/resources", applicationRoot), args); m_server->addEntryPoint(Wt::EntryPointType::Application, std::bind(&Server::createApplication, this, std::placeholders::_1, false)); @@ -133,7 +133,6 @@ Server::Server(uint16_t port, const std::string &documentRoot) { std::bind(&Server::createApplication, this, std::placeholders::_1, true), "/wt/app.js"); m_server->addResource(std::make_shared(), "/auth"); m_server->addResource(std::make_shared(), "/plaintext"); - m_server->addResource(std::make_shared(std::format("{}/database.sqlite", documentRoot)), "/db"); m_server->start(); } catch (const std::exception &e) { diff --git a/WebApplication/Application.h b/WebApplication/Application.h index fb312b3..a9a8c6f 100644 --- a/WebApplication/Application.h +++ b/WebApplication/Application.h @@ -51,7 +51,7 @@ public: const Wt::Auth::PasswordService &passwordService(); protected: - Server(uint16_t port, const std::string &documentRoot); + Server(uint16_t port, const std::string &applicationRoot, const std::string &documentRoot); std::unique_ptr createApplication(const Wt::WEnvironment &env, bool embedded); private: diff --git a/WebApplication/Restful.cpp b/WebApplication/Restful.cpp index 2495e5d..86c79f0 100644 --- a/WebApplication/Restful.cpp +++ b/WebApplication/Restful.cpp @@ -27,23 +27,6 @@ void PlaintextResource::handleRequest(const Wt::Http::Request &request, Wt::Http response.out() << "Hello, World!"; } -DbResource::DbResource(const std::string &db) { - if (!m_dbStruct) { - m_dbStruct = new DbStruct(db); - } -} - -void DbResource::handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) { - response.setMimeType("application/json"); - response.addHeader("Server", "Wt"); - - Wt::Dbo::Transaction transaction(m_dbStruct->session); - Wt::Dbo::ptr entry = m_dbStruct->session.load(m_dbStruct->rand()); - - Wt::Dbo::JsonSerializer writer(response.out()); - writer.serialize(entry); -} - int DbStruct::rand() { return distribution(rng); } diff --git a/WebApplication/Restful.h b/WebApplication/Restful.h index f76a788..00a7a14 100644 --- a/WebApplication/Restful.h +++ b/WebApplication/Restful.h @@ -55,10 +55,4 @@ public: void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) final; }; -class DbResource : public Wt::WResource { -public: - DbResource(const std::string &db); - void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) final; -}; - #endif // __RESTFUL_H__ \ No newline at end of file diff --git a/resources/build.sh b/resources/build.sh index d090b4d..7fee28f 100755 --- a/resources/build.sh +++ b/resources/build.sh @@ -25,7 +25,7 @@ function build() { # reset # pkill -9 HttpServer # cp -r /opt/Libraries/wt-4.11.1/share/Wt/* ./build - # cp -r resources/* build/resources/ + # cp -r resources/themes resources/*.css build/resources/ if [ ! -f "${build_path}/CMakeCache.txt" ]; then cmake_scan