WebAPI.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. int numberOfImages = 5;
  38. if (uriTokens.size() > 7)
  39. numberOfImages = stoi(uriTokens[7]);
  40. if (StringAlgorithm::iequals("Digoo", brand))
  41. {
  42. auto recorder = Recorder::DigooRecorder(pHttpClient, settings);
  43. if (StringAlgorithm::iequals("Snapshot", action))
  44. output = recorder.Snapshot(pThreadPool);
  45. else if (StringAlgorithm::iequals("MultiSnapshot", action))
  46. output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
  47. else if (StringAlgorithm::iequals("Video", action))
  48. output = recorder.Video(pThreadPool, ffmpeg);
  49. }
  50. else if (StringAlgorithm::iequals("Foscam", brand))
  51. {
  52. auto recorder = Recorder::FoscamRecorder(pHttpClient, settings);
  53. if (StringAlgorithm::iequals("Snapshot", action))
  54. output = recorder.Snapshot(pThreadPool);
  55. else if (StringAlgorithm::iequals("MultiSnapshot", action))
  56. output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
  57. else if (StringAlgorithm::iequals("Video", action))
  58. output = recorder.Video(pThreadPool, ffmpeg);
  59. }
  60. else if (StringAlgorithm::iequals("VStarCam", brand))
  61. {
  62. auto recorder = Recorder::VStarCamRecorder(pHttpClient, settings);
  63. if (StringAlgorithm::iequals("Snapshot", action))
  64. output = recorder.Snapshot(pThreadPool);
  65. else if (StringAlgorithm::iequals("MultiSnapshot", action))
  66. output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
  67. else if (StringAlgorithm::iequals("Video", action))
  68. output = recorder.Video(pThreadPool, ffmpeg);
  69. }
  70. else if (StringAlgorithm::iequals("WatchBot", brand))
  71. {
  72. auto recorder = Recorder::WatchBotRecorder(pHttpClient, settings);
  73. if (StringAlgorithm::iequals("Snapshot", action))
  74. output = recorder.Snapshot(pThreadPool);
  75. else if (StringAlgorithm::iequals("MultiSnapshot", action))
  76. output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
  77. else if (StringAlgorithm::iequals("Video", action))
  78. output = recorder.Video(pThreadPool, ffmpeg);
  79. }
  80. else if (StringAlgorithm::iequals("ZModo", brand))
  81. {
  82. auto recorder = Recorder::ZModoRecorder(pHttpClient, settings);
  83. if (StringAlgorithm::iequals("Snapshot", action))
  84. output = recorder.Snapshot(pThreadPool);
  85. else if (StringAlgorithm::iequals("MultiSnapshot", action))
  86. output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
  87. else if (StringAlgorithm::iequals("Video", action))
  88. output = recorder.Video(pThreadPool, ffmpeg);
  89. }
  90. return output;
  91. }
  92. } // namespace API
  93. } // namespace CameraRecorder