Update Http Library

This commit is contained in:
2020-06-10 22:17:13 +02:00
parent a161173dec
commit b01fdb8be8
3 changed files with 35 additions and 22 deletions
+32 -20
View File
@@ -27,14 +27,25 @@ WebAPI::~WebAPI()
{
}
std::string WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClient* pHttpClient, const std::string& path, const std::string& ffmpeg, const std::string& uri, const std::vector<Http::HttpPostData>& postData)
Http::HttpServer::HttpReply WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClient* pHttpClient, const std::string& path, const std::string& ffmpeg, const std::string& uri, const std::vector<Http::HttpPostData>& postData)
{
std::string output;
if (!StringAlgorithm::iequals(uri, "/api") && !StringAlgorithm::istarts_with(uri, "/api/"))
{
Http::HttpServer::HttpReply reply;
reply.status = Http::HttpServer::HttpReply::Status::Unauthorized;
return reply;
}
std::vector<std::string> uriTokens = StringAlgorithm::split(uri, '/');
Http::HttpServer::HttpReply reply;
reply.status = Http::HttpServer::HttpReply::Status::InternalServerError;
reply.content = "{\"result\": \"error\"}\r\n";
std::string apiURI = uri.substr(4);
std::vector<std::string> uriTokens = StringAlgorithm::split(apiURI, '/');
if (uriTokens.size() < 7)
return std::string();
return reply;
std::string action = uriTokens[1];
std::string brand = uriTokens[2];
@@ -50,58 +61,59 @@ std::string WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClien
if (uriTokens.size() > 7)
numberOfImages = stoi(uriTokens[7]);
reply.status = Http::HttpServer::HttpReply::Status::Ok;
if (StringAlgorithm::iequals("Digoo", brand))
{
auto recorder = Recorder::DigooRecorder(pHttpClient, settings);
if (StringAlgorithm::iequals("Snapshot", action))
output = recorder.Snapshot(pThreadPool);
reply.content = recorder.Snapshot(pThreadPool);
else if (StringAlgorithm::iequals("MultiSnapshot", action))
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
else if (StringAlgorithm::iequals("Video", action))
output = recorder.Video(pThreadPool, ffmpeg);
reply.content = recorder.Video(pThreadPool, ffmpeg);
}
else if (StringAlgorithm::iequals("Foscam", brand))
{
auto recorder = Recorder::FoscamRecorder(pHttpClient, settings);
if (StringAlgorithm::iequals("Snapshot", action))
output = recorder.Snapshot(pThreadPool);
reply.content = recorder.Snapshot(pThreadPool);
else if (StringAlgorithm::iequals("MultiSnapshot", action))
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
else if (StringAlgorithm::iequals("Video", action))
output = recorder.Video(pThreadPool, ffmpeg);
reply.content = recorder.Video(pThreadPool, ffmpeg);
}
else if (StringAlgorithm::iequals("VStarCam", brand))
{
auto recorder = Recorder::VStarCamRecorder(pHttpClient, settings);
if (StringAlgorithm::iequals("Snapshot", action))
output = recorder.Snapshot(pThreadPool);
reply.content = recorder.Snapshot(pThreadPool);
else if (StringAlgorithm::iequals("MultiSnapshot", action))
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
else if (StringAlgorithm::iequals("Video", action))
output = recorder.Video(pThreadPool, ffmpeg);
reply.content = recorder.Video(pThreadPool, ffmpeg);
}
else if (StringAlgorithm::iequals("WatchBot", brand))
{
auto recorder = Recorder::WatchBotRecorder(pHttpClient, settings);
if (StringAlgorithm::iequals("Snapshot", action))
output = recorder.Snapshot(pThreadPool);
reply.content = recorder.Snapshot(pThreadPool);
else if (StringAlgorithm::iequals("MultiSnapshot", action))
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
else if (StringAlgorithm::iequals("Video", action))
output = recorder.Video(pThreadPool, ffmpeg);
reply.content = recorder.Video(pThreadPool, ffmpeg);
}
else if (StringAlgorithm::iequals("ZModo", brand))
{
auto recorder = Recorder::ZModoRecorder(pHttpClient, settings);
if (StringAlgorithm::iequals("Snapshot", action))
output = recorder.Snapshot(pThreadPool);
reply.content = recorder.Snapshot(pThreadPool);
else if (StringAlgorithm::iequals("MultiSnapshot", action))
output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
else if (StringAlgorithm::iequals("Video", action))
output = recorder.Video(pThreadPool, ffmpeg);
reply.content = recorder.Video(pThreadPool, ffmpeg);
}
return output;
return reply;
}
} // namespace API
+2 -1
View File
@@ -2,6 +2,7 @@
#define API_WEBAPI_H
#include <HttpPostData.h>
#include <HttpServer.h>
#include <ctpl_stl.h>
#include <string>
#include <vector>
@@ -22,7 +23,7 @@ public:
WebAPI();
~WebAPI();
static std::string ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClient* pHttpClient, const std::string& path, const std::string& ffmpeg, const std::string& uri, const std::vector<Http::HttpPostData>& postData);
static Http::HttpServer::HttpReply ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClient* pHttpClient, const std::string& path, const std::string& ffmpeg, const std::string& uri, const std::vector<Http::HttpPostData>& postData);
};
} // namespace API