1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /*
- * @Author: lishengyin lishengyin@sz-sunwin.com
- * @Date: 2022-09-04 20:29:44
- * @LastEditors: lishengyin lishengyin@sz-sunwin.com
- * @LastEditTime: 2022-09-05 00:31:25
- * @FilePath: /gsd_check/controllers/apis_v1_check.cc
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- #include "apis_v1_check.h"
- using namespace apis::v1;
- // Add definition of your processing function here
- /**
- * @description: getHelp
- * @param {HttpRequestPtr&} req
- * @param {function<void (HttpResponsePtr &)>} &
- * @return {*}
- */
- void check::getHelp(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback){
- HttpResponsePtr resp;
- resp = HttpResponse::newHttpResponse();
- resp->setBody("test");
- callback(resp);
- }
- /**
- * @description: postInfer
- * @param {HttpRequestPtr&} req
- * @param {function<void (HttpResponsePtr &)>} &
- * @return {*}
- */
- void check::postInfer(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback){
- HttpResponsePtr resp;
- resp = HttpResponse::newHttpResponse();
- HttpResultMsg<HttpNull, HttpNull> request;
- std::string json;
- if(req->getContentType() != ContentType::CT_APPLICATION_X_FORM){
- request.code = "202";
- request.msg = "失败";
- request.attr1 = "ContentType error";
- request.objectToJson(json);
- resp->setBody(json.c_str());
- callback(resp);
- }
- // 获取Parm
- if(req->getParameter("image") == "" || req->getParameter("datas") == ""){
- request.code = "502";
- request.msg = "失败";
- request.attr1 = "Parameters are not met.";
- request.objectToJson(json);
- resp->setBody(json.c_str());
- resp->setStatusCode(k502BadGateway);
- callback(resp);
- return;
- }
- auto *pluginPtr = app().getPlugin<gsd::InferPlugin>();
- auto result_for_future = pluginPtr->CreateTask(req);
- auto result = result_for_future.get();
- if(result.first){
- request.code = "200";
- request.msg = "成功";
- request.attr1 = result.second;
- }else{
- request.code = "200";
- request.msg = "失败";
- request.attr1 = result.second;
- }
- request.objectToJson(json);
- resp->setBody(json.c_str());
- resp->setStatusCode(k200OK);
- callback(resp);
- }
|