apis_v1_check.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * @Author: lishengyin lishengyin@sz-sunwin.com
  3. * @Date: 2022-09-04 20:29:44
  4. * @LastEditors: lishengyin lishengyin@sz-sunwin.com
  5. * @LastEditTime: 2022-09-05 00:31:25
  6. * @FilePath: /gsd_check/controllers/apis_v1_check.cc
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. #include "apis_v1_check.h"
  10. using namespace apis::v1;
  11. // Add definition of your processing function here
  12. /**
  13. * @description: getHelp
  14. * @param {HttpRequestPtr&} req
  15. * @param {function<void (HttpResponsePtr &)>} &
  16. * @return {*}
  17. */
  18. void check::getHelp(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback){
  19. HttpResponsePtr resp;
  20. resp = HttpResponse::newHttpResponse();
  21. resp->setBody("test");
  22. callback(resp);
  23. }
  24. /**
  25. * @description: postInfer
  26. * @param {HttpRequestPtr&} req
  27. * @param {function<void (HttpResponsePtr &)>} &
  28. * @return {*}
  29. */
  30. void check::postInfer(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback){
  31. HttpResponsePtr resp;
  32. resp = HttpResponse::newHttpResponse();
  33. HttpResultMsg<HttpNull, HttpNull> request;
  34. std::string json;
  35. if(req->getContentType() != ContentType::CT_APPLICATION_X_FORM){
  36. request.code = "202";
  37. request.msg = "失败";
  38. request.attr1 = "ContentType error";
  39. request.objectToJson(json);
  40. resp->setBody(json.c_str());
  41. callback(resp);
  42. }
  43. // 获取Parm
  44. if(req->getParameter("image") == "" || req->getParameter("datas") == ""){
  45. request.code = "502";
  46. request.msg = "失败";
  47. request.attr1 = "Parameters are not met.";
  48. request.objectToJson(json);
  49. resp->setBody(json.c_str());
  50. resp->setStatusCode(k502BadGateway);
  51. callback(resp);
  52. return;
  53. }
  54. auto *pluginPtr = app().getPlugin<gsd::InferPlugin>();
  55. auto result_for_future = pluginPtr->CreateTask(req);
  56. auto result = result_for_future.get();
  57. if(result.first){
  58. request.code = "200";
  59. request.msg = "成功";
  60. request.attr1 = result.second;
  61. }else{
  62. request.code = "200";
  63. request.msg = "失败";
  64. request.attr1 = result.second;
  65. }
  66. request.objectToJson(json);
  67. resp->setBody(json.c_str());
  68. resp->setStatusCode(k200OK);
  69. callback(resp);
  70. }