diff --git a/Server/Application.cpp b/Server/Application.cpp index 5235865..7da26e2 100644 --- a/Server/Application.cpp +++ b/Server/Application.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include constexpr auto IpcUrl = "ipc:///tmp/nng_ipc_server"; @@ -263,6 +264,35 @@ Application::Application(const std::string &path) s.body() = boost::json::serialize(reply); s.prepare_payload(); session.reply(std::move(s)); + }); + m_router->insert("/api/v1/search/reindex", [this](HttpSession &session, const Request &request, const boost::urls::matches &matches) { + using namespace boost::beast; + auto key = getMeiliSearchApiKey(); + auto config = getMeiliSearchConfig(); + if (!key.empty() && !config.empty()) { + config = std::filesystem::absolute(config); + LOG(info)<<"config path: "< s{boost::beast::http::status::ok, request.version()}; + s.set(http::field::server, BOOST_BEAST_VERSION_STRING); + s.set(http::field::content_type, "application/json;charset=UTF-8"); + s.keep_alive(request.keep_alive()); + s.prepare_payload(); + session.reply(std::move(s)); }); // clang-format on m_ioContext = Amass::Singleton::instance(getThreads()); diff --git a/Server/Application.h b/Server/Application.h index 4180e7b..98fa2c8 100644 --- a/Server/Application.h +++ b/Server/Application.h @@ -29,17 +29,18 @@ 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, ApplicationRoot, "."); // 内部配置文件,不应被外部访问 - BUILD_SETTING(std::string, DocumentRoot, "."); // 外部可访问的公共文件 + BUILD_SETTING(std::string, ApplicationRoot, "."); // 内部配置文件,不应被外部访问 + BUILD_SETTING(std::string, DocumentRoot, "."); // 外部可访问的公共文件 BUILD_SETTING(std::string, HomeAssistantAccessToken, ""); + BUILD_SETTING(std::string, MeiliSearchApiKey, ""); + BUILD_SETTING(std::string, MeiliSearchConfig, ""); INITIALIZE_FIELDS(Server, Port, Threads, ApplicationRoot, DocumentRoot); Application(const std::string &path); boost::asio::io_context &ioContext(); int exec(); - const RequestHandler *find(boost::urls::segments_encoded_view path, - boost::urls::matches_base &matches) const noexcept; + const RequestHandler *find(boost::urls::segments_encoded_view path, boost::urls::matches_base &matches) const noexcept; void insertUrl(std::string_view url, RequestHandler &&handler); static void requetExit(); diff --git a/Server/CMakeLists.txt b/Server/CMakeLists.txt index 8864366..3de61fc 100644 --- a/Server/CMakeLists.txt +++ b/Server/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package(Boost COMPONENTS program_options json REQUIRED) +find_package(Boost COMPONENTS program_options json process REQUIRED) add_subdirectory(ChatRoom) add_subdirectory(WebRTC) @@ -24,7 +24,8 @@ target_link_libraries(Server PRIVATE MediaServer PRIVATE WebApplication PRIVATE Nng - PRIVATE ${Boost_LIBRARIES} + PRIVATE Boost::json + PRIVATE Boost::process ) set_target_properties(Server PROPERTIES diff --git a/Server/HttpSession.cpp b/Server/HttpSession.cpp index c6c4c53..c64235f 100644 --- a/Server/HttpSession.cpp +++ b/Server/HttpSession.cpp @@ -14,8 +14,11 @@ void HttpSession::run() { doRead(); } -void HttpSession::errorReply(const Request &request, boost::beast::http::status status, - boost::beast::string_view message) { +boost::beast::tcp_stream::executor_type HttpSession::executor() { + return m_stream.get_executor(); +} + +void HttpSession::errorReply(const Request &request, boost::beast::http::status status, boost::beast::string_view message) { using namespace boost::beast; // invalid route http::response res{status, request.version()}; diff --git a/Server/HttpSession.h b/Server/HttpSession.h index 1f58398..0a54c54 100644 --- a/Server/HttpSession.h +++ b/Server/HttpSession.h @@ -22,13 +22,12 @@ public: void reply(Response &&response) { using ResponseType = typename std::decay_t; auto sp = std::make_shared(std::forward(response)); - boost::beast::http::async_write( - m_stream, *sp, [self = shared_from_this(), sp](boost::beast::error_code ec, std::size_t bytes) { - self->onWrite(ec, bytes, sp->need_eof()); - }); + boost::beast::http::async_write(m_stream, *sp, [self = shared_from_this(), sp](boost::beast::error_code ec, std::size_t bytes) { + self->onWrite(ec, bytes, sp->need_eof()); + }); } void errorReply(const Request &request, boost::beast::http::status status, boost::beast::string_view message); - + boost::beast::tcp_stream::executor_type executor(); void run(); private: