60 lines
2.3 KiB
C++
60 lines
2.3 KiB
C++
#ifndef SERVICELOGIC_H
|
|
#define SERVICELOGIC_H
|
|
|
|
#include "ResponseUtility.h"
|
|
#include "SharedState.h"
|
|
#include "StringUtility.h"
|
|
#include <boost/beast/http/message.hpp>
|
|
#include <boost/beast/http/string_body.hpp>
|
|
#include <boost/beast/http/vector_body.hpp>
|
|
#include <boost/beast/version.hpp>
|
|
#include <boost/uuid/uuid_generators.hpp>
|
|
#include <boost/uuid/uuid_io.hpp>
|
|
#include <fstream>
|
|
|
|
using StringRequest = boost::beast::http::request<boost::beast::http::string_body>;
|
|
|
|
namespace ServiceLogic {
|
|
|
|
template <class Send>
|
|
static void onDownload(SharedStatePtr /*state*/, StringRequest &&request, Send &&send);
|
|
|
|
template <class Send>
|
|
static void onGetBlogList(SharedStatePtr state, StringRequest &&request, Send &&send);
|
|
|
|
template <class Send>
|
|
static void onGetBlogContent(SharedStatePtr state, StringRequest &&request, Send &&send, const std::string &prefix);
|
|
|
|
template <class Send>
|
|
static void onGetBlogImage(SharedStatePtr state, StringRequest &&request, Send &&send);
|
|
|
|
template <class Send>
|
|
static void onWechat(SharedStatePtr state, StringRequest &&request, Send &&send);
|
|
|
|
// Returns a not found response
|
|
boost::beast::http::response<boost::beast::http::string_body>
|
|
notFound(const boost::beast::http::request<boost::beast::http::string_body> &request);
|
|
|
|
// Returns a server error response
|
|
boost::beast::http::response<boost::beast::http::string_body>
|
|
serverError(const boost::beast::http::request<boost::beast::http::string_body> &request, std::string_view errorMessage);
|
|
|
|
template <class ResponseBody, class RequestBody>
|
|
boost::beast::http::response<ResponseBody> make_200(const boost::beast::http::request<RequestBody> &request,
|
|
typename ResponseBody::value_type body,
|
|
boost::beast::string_view content) {
|
|
boost::beast::http::response<ResponseBody> response{boost::beast::http::status::ok, request.version()};
|
|
response.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
|
|
response.set(boost::beast::http::field::content_type, content);
|
|
response.body() = body;
|
|
response.prepare_payload();
|
|
response.keep_alive(request.keep_alive());
|
|
|
|
return response;
|
|
}
|
|
}; // namespace ServiceLogic
|
|
|
|
#include "ServiceLogic.inl"
|
|
|
|
#endif // SERVICELOGIC_H
|