This commit is contained in:
parent
34253a4bf6
commit
03c7a564a1
@ -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
|
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 build
|
||||||
- run: resources/build.sh lvgl
|
- 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
|
uses: appleboy/scp-action@v0.1.7
|
||||||
with:
|
with:
|
||||||
host: ${{ vars.YUYUN_SERVER }}
|
host: ${{ vars.YUYUN_SERVER }}
|
||||||
username: ${{ vars.YUYUN_USER }}
|
username: ${{ vars.YUYUN_USER }}
|
||||||
password: ${{ secrets.SERVER_ROOT_PASSWORD }}
|
password: ${{ secrets.SERVER_ROOT_PASSWORD }}
|
||||||
overwrite: true
|
overwrite: true
|
||||||
source: "resources/*.css,resources/*.xml"
|
source: "resources/*.css"
|
||||||
target: /root/Server/amass_blog
|
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
|
- name: Copy lvgl to server
|
||||||
uses: appleboy/scp-action@v0.1.7
|
uses: appleboy/scp-action@v0.1.7
|
||||||
with:
|
with:
|
||||||
|
@ -29,11 +29,11 @@ public:
|
|||||||
BUILD_SETTING(uint16_t, Port, 8081);
|
BUILD_SETTING(uint16_t, Port, 8081);
|
||||||
BUILD_SETTING(uint16_t, WtPort, 8082);
|
BUILD_SETTING(uint16_t, WtPort, 8082);
|
||||||
BUILD_SETTING(uint32_t, Threads, std::thread::hardware_concurrency());
|
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, 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);
|
Application(const std::string &path);
|
||||||
boost::asio::io_context &ioContext();
|
boost::asio::io_context &ioContext();
|
||||||
int exec();
|
int exec();
|
||||||
|
@ -3,13 +3,14 @@
|
|||||||
#include "HttpSession.h"
|
#include "HttpSession.h"
|
||||||
#include "ServiceLogic.h"
|
#include "ServiceLogic.h"
|
||||||
#include <boost/url/url_view.hpp>
|
#include <boost/url/url_view.hpp>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
Live2dBackend::Live2dBackend() {
|
Live2dBackend::Live2dBackend() {
|
||||||
using namespace Amass;
|
using namespace Amass;
|
||||||
auto application = Singleton<Application>::instance();
|
auto application = Singleton<Application>::instance();
|
||||||
application->insertUrl("/api/v1/live2d/{path*}", [this, live2dModelsRoot{application->getLive2dModelsRoot()}](
|
m_live2dModelsRoot = std::format("{}/resources/live2d", application->getDocumentRoot());
|
||||||
HttpSession &session, const Application::Request &request,
|
application->insertUrl("/api/v1/live2d/{path*}", [this](HttpSession &session, const Application::Request &request,
|
||||||
const boost::urls::matches &matches) {
|
const boost::urls::matches &matches) {
|
||||||
using namespace boost::beast;
|
using namespace boost::beast;
|
||||||
boost::urls::url_view view(request.target());
|
boost::urls::url_view view(request.target());
|
||||||
auto target = view.path();
|
auto target = view.path();
|
||||||
@ -18,7 +19,7 @@ Live2dBackend::Live2dBackend() {
|
|||||||
session.reply(ServiceLogic::badRequest(request, "Illegal request-target"));
|
session.reply(ServiceLogic::badRequest(request, "Illegal request-target"));
|
||||||
return;
|
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 (target.back() == '/') path.append("index.html");
|
||||||
if (std::filesystem::is_directory(path)) path.append("/index.html");
|
if (std::filesystem::is_directory(path)) path.append("/index.html");
|
||||||
boost::beast::error_code ec;
|
boost::beast::error_code ec;
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
#ifndef __LIVE2DBACKEND_H__
|
#ifndef __LIVE2DBACKEND_H__
|
||||||
#define __LIVE2DBACKEND_H__
|
#define __LIVE2DBACKEND_H__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
class Live2dBackend {
|
class Live2dBackend {
|
||||||
public:
|
public:
|
||||||
Live2dBackend();
|
Live2dBackend();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_live2dModelsRoot;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __LIVE2DBACKEND_H__
|
#endif // __LIVE2DBACKEND_H__
|
@ -55,7 +55,7 @@ int main(int argc, char const *argv[]) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::filesystem::current_path(prefix, error);
|
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<Application>::instance<Construct>("settings.ini");
|
auto application = Singleton<Application>::instance<Construct>("settings.ini");
|
||||||
@ -64,7 +64,7 @@ int main(int argc, char const *argv[]) {
|
|||||||
std::exit(102);
|
std::exit(102);
|
||||||
}
|
}
|
||||||
BOOST_ASSERT_MSG(!application->getServer().empty(), "server.empty() == true");
|
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 address = boost::asio::ip::make_address(application->getServer());
|
||||||
auto listener =
|
auto listener =
|
||||||
std::make_shared<Listener>(application->ioContext(), boost::asio::ip::tcp::endpoint{address, application->getPort()});
|
std::make_shared<Listener>(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<UdpServer>(application->ioContext());
|
auto udpServer = std::make_shared<UdpServer>(application->ioContext());
|
||||||
auto mediaServer = std::make_shared<MediaServer>(554, false);
|
auto mediaServer = std::make_shared<MediaServer>(554, false);
|
||||||
auto webApp = Singleton<WebToolkit::Server>::instance<Construct>(application->getWtPort(), application->getDocumentRoot());
|
auto webApp = Singleton<WebToolkit::Server>::instance<Construct>(application->getWtPort(), application->getApplicationRoot(), application->getDocumentRoot());
|
||||||
|
|
||||||
using namespace boost::asio::ip;
|
using namespace boost::asio::ip;
|
||||||
auto proxyAddress = make_address(application->getServer());
|
auto proxyAddress = make_address(application->getServer());
|
||||||
|
@ -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 {
|
try {
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
args.push_back(std::format("--docroot={};/resources", documentRoot));
|
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));
|
args.push_back(std::format("--http-listen=127.0.0.1:{}", port));
|
||||||
initializeAuthenticationService();
|
initializeAuthenticationService();
|
||||||
|
|
||||||
m_server = std::make_unique<Wt::WServer>(std::format("{}/resources", documentRoot), args);
|
m_server = std::make_unique<Wt::WServer>(std::format("{}/resources", applicationRoot), args);
|
||||||
|
|
||||||
m_server->addEntryPoint(Wt::EntryPointType::Application,
|
m_server->addEntryPoint(Wt::EntryPointType::Application,
|
||||||
std::bind(&Server::createApplication, this, std::placeholders::_1, false));
|
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");
|
std::bind(&Server::createApplication, this, std::placeholders::_1, true), "/wt/app.js");
|
||||||
m_server->addResource(std::make_shared<AuthenticationResource>(), "/auth");
|
m_server->addResource(std::make_shared<AuthenticationResource>(), "/auth");
|
||||||
m_server->addResource(std::make_shared<PlaintextResource>(), "/plaintext");
|
m_server->addResource(std::make_shared<PlaintextResource>(), "/plaintext");
|
||||||
m_server->addResource(std::make_shared<DbResource>(std::format("{}/database.sqlite", documentRoot)), "/db");
|
|
||||||
|
|
||||||
m_server->start();
|
m_server->start();
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
const Wt::Auth::PasswordService &passwordService();
|
const Wt::Auth::PasswordService &passwordService();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Server(uint16_t port, const std::string &documentRoot);
|
Server(uint16_t port, const std::string &applicationRoot, const std::string &documentRoot);
|
||||||
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env, bool embedded);
|
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env, bool embedded);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -27,23 +27,6 @@ void PlaintextResource::handleRequest(const Wt::Http::Request &request, Wt::Http
|
|||||||
response.out() << "Hello, World!";
|
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<World> entry = m_dbStruct->session.load<World>(m_dbStruct->rand());
|
|
||||||
|
|
||||||
Wt::Dbo::JsonSerializer writer(response.out());
|
|
||||||
writer.serialize(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
int DbStruct::rand() {
|
int DbStruct::rand() {
|
||||||
return distribution(rng);
|
return distribution(rng);
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,4 @@ public:
|
|||||||
void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) final;
|
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__
|
#endif // __RESTFUL_H__
|
@ -25,7 +25,7 @@ function build() {
|
|||||||
# reset
|
# reset
|
||||||
# pkill -9 HttpServer
|
# pkill -9 HttpServer
|
||||||
# cp -r /opt/Libraries/wt-4.11.1/share/Wt/* ./build
|
# 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
|
if [ ! -f "${build_path}/CMakeCache.txt" ]; then
|
||||||
cmake_scan
|
cmake_scan
|
||||||
|
Loading…
Reference in New Issue
Block a user