add interface

This commit is contained in:
lnk
2026-04-01 15:30:52 +08:00
parent 15cbbd1c24
commit b11105f91c
5 changed files with 485 additions and 169 deletions

View File

@@ -136,7 +136,7 @@ void SendJsonAPI_web(const std::string& strUrl, //接口路径
////////////////////////////////////////////////////////////////////////////////////////////////////////上传文件接口
//处理文件上传响应
void handleUploadResponse(const std::string& response, std::string& wavepath) {
void handleUploadResponse(const std::string& response, std::string& wavepath, int type) {
using nlohmann::json; //把 nlohmann::json 这个名字带到当前作用域
@@ -183,13 +183,22 @@ void handleUploadResponse(const std::string& response, std::string& wavepath) {
// 找到最后一个 '.'
size_t pos = name.find_last_of('.');
std::string nameWithoutExt;
if (pos != std::string::npos) {
// 截取去掉后缀的部分
nameWithoutExt = name.substr(0, pos);
} else {
// 如果没有后缀,直接使用原文件名
nameWithoutExt = name;
if(1 == type) {
if (pos != std::string::npos) {
// 截取去掉后缀的部分
nameWithoutExt = name.substr(0, pos); //去掉路径后缀的名
} else {
// 如果没有后缀,直接使用原文件名
nameWithoutExt = name;
}
}
else if(2 == type) {
nameWithoutExt = name;//带路径全名
}
else{
nameWithoutExt = fileName;//没有路径的全名
}
// 拷贝到 wavepath
wavepath = nameWithoutExt;
@@ -199,7 +208,7 @@ void handleUploadResponse(const std::string& response, std::string& wavepath) {
}
//上传文件
void SendFileWeb(const std::string& strUrl, const std::string& localpath, const std::string& cloudpath, std::string& wavepath) {
void SendFileWeb(const std::string& strUrl, const std::string& localpath, const std::string& cloudpath, std::string& wavepath, int type) {
// 基本存在性检查
if (access(localpath.c_str(), F_OK) != 0) {
@@ -274,7 +283,7 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG, "通过文件接口上传文件 %s 失败",localpath.c_str());
} else {
std::cout << "http web success, response: " << resPost0 << std::endl;
handleUploadResponse(resPost0, wavepath); // 处理响应
handleUploadResponse(resPost0, wavepath, type); // 处理响应
}
// 清理
@@ -289,7 +298,7 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const
//上传暂态文件
void SOEFileWeb(std::string& localpath,std::string& cloudpath, std::string& wavepath)
{
SendFileWeb(WEB_FILEUPLOAD,localpath,cloudpath,wavepath);
SendFileWeb(WEB_FILEUPLOAD,localpath,cloudpath,wavepath,1);
}
//上传文件测试函数