WebAPI.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "WebAPI.h"
  2. #include "Recorder/Recorder.h"
  3. #include "Recorder/DigooRecorder.h"
  4. #include "Recorder/FoscamRecorder.h"
  5. #include "Recorder/VStarCamRecorder.h"
  6. #include "Recorder/WatchBotRecorder.h"
  7. #include "Recorder/ZModoRecorder.h"
  8. #include <StringAlgorithm.h>
  9. #include <memory>
  10. namespace CameraRecorder {
  11. namespace API {
  12. // API Description
  13. // Status Query
  14. // Goal: Provide status information based on POST data
  15. // Use: DomoticaSite status update
  16. // URL: http://<ip>/API/<action>/<brand>/<ipaddress>/<port>/<username>/<password>
  17. WebAPI::WebAPI()
  18. {
  19. }
  20. WebAPI::~WebAPI()
  21. {
  22. }
  23. 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)
  24. {
  25. std::string output;
  26. std::vector<std::string> uriTokens = StringAlgorithm::split(uri, '/');
  27. if (uriTokens.size() < 7)
  28. return std::string();
  29. std::string action = uriTokens[1];
  30. std::string brand = uriTokens[2];
  31. Recorder::Settings settings;
  32. settings.Path = path;
  33. settings.IpAddress = uriTokens[3];
  34. settings.Port = uriTokens[4];
  35. settings.Username = uriTokens[5];
  36. settings.Password = uriTokens[6];
  37. if (StringAlgorithm::iequals("Digoo", brand))
  38. {
  39. auto recorder = Recorder::DigooRecorder(pHttpClient, settings);
  40. if (StringAlgorithm::iequals("Snapshot", action))
  41. output = recorder.Snapshot(pThreadPool);
  42. else if (StringAlgorithm::iequals("Video", action))
  43. output = recorder.Video(pThreadPool, ffmpeg);
  44. }
  45. else if (StringAlgorithm::iequals("Foscam", brand))
  46. {
  47. auto recorder = Recorder::FoscamRecorder(pHttpClient, settings);
  48. if (StringAlgorithm::iequals("Snapshot", action))
  49. output = recorder.Snapshot(pThreadPool);
  50. else if (StringAlgorithm::iequals("Video", action))
  51. output = recorder.Video(pThreadPool, ffmpeg);
  52. }
  53. else if (StringAlgorithm::iequals("VStarCam", brand))
  54. {
  55. auto recorder = Recorder::VStarCamRecorder(pHttpClient, settings);
  56. if (StringAlgorithm::iequals("Snapshot", action))
  57. output = recorder.Snapshot(pThreadPool);
  58. else if (StringAlgorithm::iequals("Video", action))
  59. output = recorder.Video(pThreadPool, ffmpeg);
  60. }
  61. else if (StringAlgorithm::iequals("WatchBot", brand))
  62. {
  63. auto recorder = Recorder::WatchBotRecorder(pHttpClient, settings);
  64. if (StringAlgorithm::iequals("Snapshot", action))
  65. output = recorder.Snapshot(pThreadPool);
  66. else if (StringAlgorithm::iequals("Video", action))
  67. output = recorder.Video(pThreadPool, ffmpeg);
  68. }
  69. else if (StringAlgorithm::iequals("ZModo", brand))
  70. {
  71. auto recorder = Recorder::ZModoRecorder(pHttpClient, settings);
  72. if (StringAlgorithm::iequals("Snapshot", action))
  73. output = recorder.Snapshot(pThreadPool);
  74. else if (StringAlgorithm::iequals("Video", action))
  75. output = recorder.Video(pThreadPool, ffmpeg);
  76. }
  77. return output;
  78. }
  79. } // namespace API
  80. } // namespace CameraRecorder