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