Fixed:app protocol bug.

This commit is contained in:
Fancy code 2024-07-17 17:40:06 +08:00
parent a476c4fc82
commit 59f6b7ec8b
9 changed files with 41 additions and 2 deletions

View File

@ -125,6 +125,7 @@ StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::v
}
IFilesManager::GetInstance()->GetFiles(types, info);
}
const std::string webServerDocumentRoot = IAppManager::GetInstance()->GetFilesSavingRootPath();
LogInfo("GetStorageFileList: file size = %d, event = %s.\n",
info.size(),
IAppManager::GetInstance()->StorageFileEventToString(fileInfo.mEvent));
@ -132,7 +133,7 @@ StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::v
AppGetFileList file;
file.mCreateTime_s = oneFileInfo.mCreateTime_s;
file.mDuration = oneFileInfo.mFileDuration;
file.mName = oneFileInfo.mFileName;
file.mName = RemovePrefix(oneFileInfo.mFileName, webServerDocumentRoot);
file.mSize = oneFileInfo.mFileSize;
file.mType = StorageFileType::VIDEO;
param.push_back(file);
@ -184,4 +185,12 @@ SdCardStatus AppMonitor::SdCardStatusConvert(const StorageEvent &event)
default:
return SdCardStatus::END;
}
}
std::string AppMonitor::RemovePrefix(const std::string &originalStr, const std::string &prefix)
{
if (originalStr.compare(0, prefix.length(), prefix) == 0) {
return originalStr.substr(prefix.length());
}
LogWarning("Something wrong happened, prefix is %s.\n", prefix.c_str());
return originalStr;
}

View File

@ -41,6 +41,7 @@ public:
private:
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
std::string RemovePrefix(const std::string &originalStr, const std::string &prefix);
private:
SwitchStatus mMicStatus; // TODO: improve delete.

View File

@ -48,7 +48,7 @@ set(LOG_SUPPORT "true")
# ------------ build log end ------------ #
# ------------ build GoAhead ------------ #
set(GOAHEAD_DOCUMENTS_PATH "web")
set(GOAHEAD_DOCUMENTS_PATH "./sdcard") # web访mp4jpghtml
set(GOAHEAD_UPLOAD_TMP_PATH "./goahead")
set(GOAHEAD_UPLOAD_PATH "${GOAHEAD_UPLOAD_TMP_PATH}")
set(GOAHEAD_LIMIT_POST "335544320") # If not defined means using default setting. See goahead-linux-static-fancy.mk

View File

@ -344,5 +344,11 @@ public:
virtual const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor);
virtual StatusCode SetSdCardStatus(const SdCardStatus &status);
virtual const char *StorageFileEventToString(const StorageFileEvent &event);
/**
* @brief Get the document root directory configured by the web server of the APP management module. The mobile APP
* can access the files in the directory through the network.
* @return std::string Path of the document root directory.
*/
virtual std::string GetFilesSavingRootPath(void);
};
#endif

View File

@ -23,6 +23,7 @@
#include "TcpModule.h"
#include "WebServer.h"
#include <memory>
#include <string>
#include <sys/types.h>
AppManager::AppManager() : mTcpServer(nullptr), mInitRuning(false)
{
@ -97,6 +98,11 @@ const char *AppManager::StorageFileEventToString(const StorageFileEvent &event)
break;
}
}
std::string AppManager::GetFilesSavingRootPath(void)
{
std::string rootPath = GetWebServerDocumentRoot();
return rootPath;
}
void AppManager::AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
void *context)
{

View File

@ -28,6 +28,7 @@ public:
const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
StatusCode SetSdCardStatus(const SdCardStatus &status) override;
const char *StorageFileEventToString(const StorageFileEvent &event) override;
std::string GetFilesSavingRootPath(void) override;
void AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, void *context);
void AppRequestHandleTcp(const char *data, const unsigned int dataLength, ResponseHandle responseHandle,
void *context);

View File

@ -249,4 +249,10 @@ StatusCode IAppManager::SetSdCardStatus(const SdCardStatus &status)
const char *IAppManager::StorageFileEventToString(const StorageFileEvent &event)
{
return "STATUS_CODE_VIRTUAL_FUNCTION";
}
std::string IAppManager::GetFilesSavingRootPath(void)
{
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION\n");
const std::string path = "unknwon";
return path;
}

View File

@ -29,6 +29,12 @@ typedef struct web_server_param
StatusCode WebServerInit(const WebServerParam webParam);
StatusCode WebServerExit(void);
StatusCode WebServerUnInit(void);
/**
* @brief The document root directory configured by the web server. Files under the directory can be accessed over the
* network.
* @return const char*
*/
const char *GetWebServerDocumentRoot(void);
#ifdef __cplusplus
}
#endif

View File

@ -237,4 +237,8 @@ StatusCode WebServerUnInit(void)
{
LogInfo("WebServerUnInit.\n");
return CreateStatusCode(STATUS_CODE_OK);
}
const char *GetWebServerDocumentRoot(void)
{
return GOAHEAD_DOCUMENTS_PATH;
}