This commit is contained in:
parent
ac6fae0f47
commit
48c2ef7baa
@ -11,6 +11,7 @@
|
|||||||
#include <Wt/Dbo/Json.h>
|
#include <Wt/Dbo/Json.h>
|
||||||
#include <boost/json/object.hpp>
|
#include <boost/json/object.hpp>
|
||||||
#include <boost/json/serialize.hpp>
|
#include <boost/json/serialize.hpp>
|
||||||
|
#include <boost/process/v2/process.hpp>
|
||||||
#include <boost/stacktrace.hpp>
|
#include <boost/stacktrace.hpp>
|
||||||
|
|
||||||
constexpr auto IpcUrl = "ipc:///tmp/nng_ipc_server";
|
constexpr auto IpcUrl = "ipc:///tmp/nng_ipc_server";
|
||||||
@ -264,6 +265,35 @@ Application::Application(const std::string &path)
|
|||||||
s.prepare_payload();
|
s.prepare_payload();
|
||||||
session.reply(std::move(s));
|
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: "<<config;
|
||||||
|
boost::process::process process(session.executor(), "/usr/bin/docker", {"run", "-t", "--rm", "--network=host",
|
||||||
|
"--env=MEILISEARCH_HOST_URL=http://localhost:7700",
|
||||||
|
std::format("--env=MEILISEARCH_API_KEY={}", key),
|
||||||
|
std::format("--volume={}:/docs-scraper/config.json", config),
|
||||||
|
"getmeili/docs-scraper:latest",
|
||||||
|
"pipenv", "run", "./docs_scraper", "config.json"
|
||||||
|
});
|
||||||
|
boost::process::error_code error;
|
||||||
|
int code = process.wait(error);
|
||||||
|
if (error) {
|
||||||
|
LOG(error) << error.message();
|
||||||
|
} else {
|
||||||
|
LOG(info) << "reindex code:" << code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
http::response<boost::beast::http::string_body> 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
|
// clang-format on
|
||||||
m_ioContext = Amass::Singleton<IoContext>::instance<Amass::Construct>(getThreads());
|
m_ioContext = Amass::Singleton<IoContext>::instance<Amass::Construct>(getThreads());
|
||||||
m_timer = std::make_shared<boost::asio::system_timer>(*m_ioContext->ioContext());
|
m_timer = std::make_shared<boost::asio::system_timer>(*m_ioContext->ioContext());
|
||||||
|
@ -32,14 +32,15 @@ public:
|
|||||||
BUILD_SETTING(std::string, ApplicationRoot, "."); // 内部配置文件,不应被外部访问
|
BUILD_SETTING(std::string, ApplicationRoot, "."); // 内部配置文件,不应被外部访问
|
||||||
BUILD_SETTING(std::string, DocumentRoot, "."); // 外部可访问的公共文件
|
BUILD_SETTING(std::string, DocumentRoot, "."); // 外部可访问的公共文件
|
||||||
BUILD_SETTING(std::string, HomeAssistantAccessToken, "");
|
BUILD_SETTING(std::string, HomeAssistantAccessToken, "");
|
||||||
|
BUILD_SETTING(std::string, MeiliSearchApiKey, "");
|
||||||
|
BUILD_SETTING(std::string, MeiliSearchConfig, "");
|
||||||
|
|
||||||
INITIALIZE_FIELDS(Server, Port, Threads, ApplicationRoot, 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();
|
||||||
|
|
||||||
const RequestHandler *find(boost::urls::segments_encoded_view path,
|
const RequestHandler *find(boost::urls::segments_encoded_view path, boost::urls::matches_base &matches) const noexcept;
|
||||||
boost::urls::matches_base &matches) const noexcept;
|
|
||||||
void insertUrl(std::string_view url, RequestHandler &&handler);
|
void insertUrl(std::string_view url, RequestHandler &&handler);
|
||||||
static void requetExit();
|
static void requetExit();
|
||||||
|
|
||||||
|
@ -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(ChatRoom)
|
||||||
add_subdirectory(WebRTC)
|
add_subdirectory(WebRTC)
|
||||||
@ -24,7 +24,8 @@ target_link_libraries(Server
|
|||||||
PRIVATE MediaServer
|
PRIVATE MediaServer
|
||||||
PRIVATE WebApplication
|
PRIVATE WebApplication
|
||||||
PRIVATE Nng
|
PRIVATE Nng
|
||||||
PRIVATE ${Boost_LIBRARIES}
|
PRIVATE Boost::json
|
||||||
|
PRIVATE Boost::process
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(Server PROPERTIES
|
set_target_properties(Server PROPERTIES
|
||||||
|
@ -14,8 +14,11 @@ void HttpSession::run() {
|
|||||||
doRead();
|
doRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpSession::errorReply(const Request &request, boost::beast::http::status status,
|
boost::beast::tcp_stream::executor_type HttpSession::executor() {
|
||||||
boost::beast::string_view message) {
|
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;
|
using namespace boost::beast;
|
||||||
// invalid route
|
// invalid route
|
||||||
http::response<http::string_body> res{status, request.version()};
|
http::response<http::string_body> res{status, request.version()};
|
||||||
|
@ -22,13 +22,12 @@ public:
|
|||||||
void reply(Response &&response) {
|
void reply(Response &&response) {
|
||||||
using ResponseType = typename std::decay_t<decltype(response)>;
|
using ResponseType = typename std::decay_t<decltype(response)>;
|
||||||
auto sp = std::make_shared<ResponseType>(std::forward<decltype(response)>(response));
|
auto sp = std::make_shared<ResponseType>(std::forward<decltype(response)>(response));
|
||||||
boost::beast::http::async_write(
|
boost::beast::http::async_write(m_stream, *sp, [self = shared_from_this(), sp](boost::beast::error_code ec, std::size_t bytes) {
|
||||||
m_stream, *sp, [self = shared_from_this(), sp](boost::beast::error_code ec, std::size_t bytes) {
|
|
||||||
self->onWrite(ec, bytes, sp->need_eof());
|
self->onWrite(ec, bytes, sp->need_eof());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
void errorReply(const Request &request, boost::beast::http::status status, boost::beast::string_view message);
|
void errorReply(const Request &request, boost::beast::http::status status, boost::beast::string_view message);
|
||||||
|
boost::beast::tcp_stream::executor_type executor();
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user