Added crow log, rename curl class / functions
parent
af47396334
commit
862766de71
|
@ -8,23 +8,33 @@
|
|||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
|
||||
namespace cs {
|
||||
|
||||
void init();
|
||||
void cleanup();
|
||||
namespace cs
|
||||
{
|
||||
|
||||
class request {
|
||||
namespace requests
|
||||
{
|
||||
void init();
|
||||
|
||||
void cleanup();
|
||||
}
|
||||
|
||||
class request
|
||||
{
|
||||
private:
|
||||
CURL* handler = nullptr;
|
||||
struct curl_slist* headers = nullptr;
|
||||
public:
|
||||
request();
|
||||
|
||||
void setAuthHeader(const std::string& header);
|
||||
|
||||
void get(const std::string& domain);
|
||||
|
||||
void post(const std::string& domain);
|
||||
~easyrequest_get();
|
||||
|
||||
~request();
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif //CROWSITE_CURL_H
|
||||
|
|
2
libs/BLT
2
libs/BLT
|
@ -1 +1 @@
|
|||
Subproject commit eba9ecb9e525c954e956ae7e25504654af9d8eaf
|
||||
Subproject commit a3f67571460d23fe819a3a3a572344e7030fba4a
|
|
@ -21,7 +21,7 @@ namespace cs {
|
|||
responses[site] = response;
|
||||
}
|
||||
|
||||
void init()
|
||||
void requests::init()
|
||||
{
|
||||
auto code = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if (code)
|
||||
|
@ -31,23 +31,23 @@ namespace cs {
|
|||
}
|
||||
}
|
||||
|
||||
void cleanup()
|
||||
void requests::cleanup()
|
||||
{
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
easy_get::easy_get()
|
||||
request::request()
|
||||
{
|
||||
handler = curl_easy_init();
|
||||
}
|
||||
|
||||
easy_get::~easy_get()
|
||||
request::~request()
|
||||
{
|
||||
curl_slist_free_all(headers);
|
||||
curl_easy_cleanup(handler);
|
||||
}
|
||||
|
||||
void easy_get::setAuthHeader(const std::string& header)
|
||||
void request::setAuthHeader(const std::string& header)
|
||||
{
|
||||
curl_slist_free_all(headers);
|
||||
headers = curl_slist_append(headers, "Content-Type: application/json");
|
||||
|
@ -56,7 +56,7 @@ namespace cs {
|
|||
curl_easy_setopt(handler, CURLOPT_HTTPHEADER, headers);
|
||||
}
|
||||
|
||||
void easy_get::request(const std::string& domain)
|
||||
void request::get(const std::string& domain)
|
||||
{
|
||||
curl_easy_setopt(handler, CURLOPT_URL, domain.c_str());
|
||||
curl_easy_setopt(handler, CURLOPT_WRITEDATA, domain.c_str());
|
||||
|
@ -68,4 +68,9 @@ namespace cs {
|
|||
BLT_ERROR("CURL failed to send request '%s'. Error '%s'", domain.c_str(), curl_easy_strerror(err));
|
||||
}
|
||||
}
|
||||
|
||||
void request::post(const std::string& domain)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
65
src/main.cpp
65
src/main.cpp
|
@ -10,8 +10,39 @@
|
|||
#include <crowsite/requests/curl.h>
|
||||
#include <blt/parse/argparse.h>
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
blt::logging::setLogOutputFormat("\033[94m[${{FULL_TIME}}]${{RC}} ${{LF}}[${{LOG_LEVEL}}]${{RC}} \033[35m(${{FILE}}:${{LINE}})${{RC}} ${{CNR}}${{STR}}${{RC}}\n");
|
||||
class BLT_CrowLogger : public crow::ILogHandler
|
||||
{
|
||||
public:
|
||||
void log(std::string message, crow::LogLevel crow_level) final
|
||||
{
|
||||
blt::logging::log_level blt_level;
|
||||
switch (crow_level){
|
||||
case crow::LogLevel::DEBUG:
|
||||
blt_level = blt::logging::log_level::DEBUG;
|
||||
break;
|
||||
case crow::LogLevel::INFO:
|
||||
blt_level = blt::logging::log_level::INFO;
|
||||
break;
|
||||
case crow::LogLevel::WARNING:
|
||||
blt_level = blt::logging::log_level::WARN;
|
||||
break;
|
||||
case crow::LogLevel::ERROR:
|
||||
blt_level = blt::logging::log_level::ERROR;
|
||||
break;
|
||||
case crow::LogLevel::CRITICAL:
|
||||
blt_level = blt::logging::log_level::FATAL;
|
||||
break;
|
||||
}
|
||||
BLT_LOG("Crow: %s", blt_level, message.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
blt::logging::setLogOutputFormat(
|
||||
"\033[94m[${{FULL_TIME}}]${{RC}} ${{LF}}[${{LOG_LEVEL}}]${{RC}} \033[35m(${{FILE}}:${{LINE}})${{RC}} ${{CNR}}${{STR}}${{RC}}\n"
|
||||
);
|
||||
cs::requests::init();
|
||||
|
||||
blt::arg_parse parser;
|
||||
|
@ -70,12 +101,14 @@ int main(int argc, const char** argv) {
|
|||
//
|
||||
// return 0;
|
||||
|
||||
cs::requests::easy_get get;
|
||||
cs::request get;
|
||||
get.setAuthHeader("MediaBrowser Client=Crowsite, Device=YourMom, Token=" + blt::arg_parse::get<std::string>(args["token"]));
|
||||
get.request("https://media.tpgc.me/Auth/Keys");
|
||||
|
||||
get.get("https://media.tpgc.me/Auth/Keys");
|
||||
|
||||
BLT_INFO("Starting site %s.", SITE_NAME);
|
||||
crow::mustache::set_global_base(SITE_FILES_PATH);
|
||||
static BLT_CrowLogger bltCrowLogger{};
|
||||
crow::logger::setHandler(&bltCrowLogger);
|
||||
|
||||
BLT_INFO("Init Crow with compression and logging enabled!");
|
||||
crow::SimpleApp app;
|
||||
|
@ -97,12 +130,14 @@ int main(int argc, const char** argv) {
|
|||
|
||||
BLT_INFO("Creating routes");
|
||||
|
||||
CROW_ROUTE(app, "/favicon.ico")([](crow::response& local_fav_res) {
|
||||
local_fav_res.compressed = false;
|
||||
local_fav_res.set_static_file_info_unsafe(cs::fs::createStaticFilePath("images/favicon.ico"));
|
||||
local_fav_res.set_header("content-type", "image/x-icon");
|
||||
local_fav_res.end();
|
||||
});
|
||||
CROW_ROUTE(app, "/favicon.ico")(
|
||||
[](crow::response& local_fav_res) {
|
||||
local_fav_res.compressed = false;
|
||||
local_fav_res.set_static_file_info_unsafe(cs::fs::createStaticFilePath("images/favicon.ico"));
|
||||
local_fav_res.set_header("content-type", "image/x-icon");
|
||||
local_fav_res.end();
|
||||
}
|
||||
);
|
||||
|
||||
CROW_ROUTE(app, "/<string>")(
|
||||
[&](const std::string& name) -> crow::response {
|
||||
|
@ -128,9 +163,11 @@ int main(int argc, const char** argv) {
|
|||
}
|
||||
);
|
||||
|
||||
CROW_ROUTE(app, "/")([&engine]() {
|
||||
return engine.fetch("home.html");
|
||||
});
|
||||
CROW_ROUTE(app, "/")(
|
||||
[&engine]() {
|
||||
return engine.fetch("home.html");
|
||||
}
|
||||
);
|
||||
|
||||
CROW_CATCHALL_ROUTE(app)(
|
||||
[&engine]() {
|
||||
|
|
Loading…
Reference in New Issue