apis_v1_ai.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * @Author: error: git config user.name && git config user.email & please set dead value or install git
  3. * @Date: 2022-07-10 17:09:21
  4. * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
  5. * @LastEditTime: 2022-07-10 22:53:25
  6. * @FilePath: /gsd/controllers/apis_v1_ai.cc
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. #include "apis_v1_ai.h"
  10. using namespace apis::v1;
  11. // Add definition of your processing function here
  12. void ai::postAI(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback){
  13. std::shared_ptr<CNStreamInferData> data = nullptr;
  14. try{
  15. data = std::make_shared<CNStreamInferData>();
  16. if(req->getContentType() == CT_APPLICATION_JSON && data->jsonToObject(std::move(req->body().data()))){
  17. HttpResultMsg<HttpNull, HttpNull> request;
  18. std::string json;
  19. request.code = "201";
  20. request.msg = "成功";
  21. request.ok = true;
  22. request.objectToJson(json);
  23. HttpResponsePtr resp;
  24. resp = HttpResponse::newHttpResponse();
  25. resp->setBody(json);
  26. resp->setStatusCode(HttpStatusCode::k201Created);
  27. callback(resp);
  28. auto *pluginPtr=app().getPlugin<gsd::MonitorPlugin>();
  29. pluginPtr->sendRequest(data);
  30. }else{
  31. auto *pluginPtr=app().getPlugin<httpHelper>();
  32. callback(pluginPtr->makeWrongReply("数据格式不正确"));
  33. }
  34. }catch(const drogon::orm::DrogonDbException &e)
  35. {
  36. ErrorL << "error:" << e.base().what() << std::endl;
  37. auto *pluginPtr=app().getPlugin<httpHelper>();
  38. callback(pluginPtr->makeWrongReply(e.base().what()));
  39. }
  40. }