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); IFilesManager::GetInstance()->GetFiles(types, info);
} }
const std::string webServerDocumentRoot = IAppManager::GetInstance()->GetFilesSavingRootPath();
LogInfo("GetStorageFileList: file size = %d, event = %s.\n", LogInfo("GetStorageFileList: file size = %d, event = %s.\n",
info.size(), info.size(),
IAppManager::GetInstance()->StorageFileEventToString(fileInfo.mEvent)); IAppManager::GetInstance()->StorageFileEventToString(fileInfo.mEvent));
@ -132,7 +133,7 @@ StatusCode AppMonitor::GetStorageFileList(const AppGetFileInfo &fileInfo, std::v
AppGetFileList file; AppGetFileList file;
file.mCreateTime_s = oneFileInfo.mCreateTime_s; file.mCreateTime_s = oneFileInfo.mCreateTime_s;
file.mDuration = oneFileInfo.mFileDuration; file.mDuration = oneFileInfo.mFileDuration;
file.mName = oneFileInfo.mFileName; file.mName = RemovePrefix(oneFileInfo.mFileName, webServerDocumentRoot);
file.mSize = oneFileInfo.mFileSize; file.mSize = oneFileInfo.mFileSize;
file.mType = StorageFileType::VIDEO; file.mType = StorageFileType::VIDEO;
param.push_back(file); param.push_back(file);
@ -185,3 +186,11 @@ SdCardStatus AppMonitor::SdCardStatusConvert(const StorageEvent &event)
return SdCardStatus::END; 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: private:
SdCardStatus SdCardStatusConvert(const StorageEvent &event); SdCardStatus SdCardStatusConvert(const StorageEvent &event);
std::string RemovePrefix(const std::string &originalStr, const std::string &prefix);
private: private:
SwitchStatus mMicStatus; // TODO: improve delete. SwitchStatus mMicStatus; // TODO: improve delete.

View File

@ -48,7 +48,7 @@ set(LOG_SUPPORT "true")
# ------------ build log end ------------ # # ------------ build log end ------------ #
# ------------ build GoAhead ------------ # # ------------ build GoAhead ------------ #
set(GOAHEAD_DOCUMENTS_PATH "web") set(GOAHEAD_DOCUMENTS_PATH "./sdcard") # web访mp4jpghtml
set(GOAHEAD_UPLOAD_TMP_PATH "./goahead") set(GOAHEAD_UPLOAD_TMP_PATH "./goahead")
set(GOAHEAD_UPLOAD_PATH "${GOAHEAD_UPLOAD_TMP_PATH}") 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 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 const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor);
virtual StatusCode SetSdCardStatus(const SdCardStatus &status); virtual StatusCode SetSdCardStatus(const SdCardStatus &status);
virtual const char *StorageFileEventToString(const StorageFileEvent &event); 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 #endif

View File

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

View File

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

View File

@ -250,3 +250,9 @@ const char *IAppManager::StorageFileEventToString(const StorageFileEvent &event)
{ {
return "STATUS_CODE_VIRTUAL_FUNCTION"; 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 WebServerInit(const WebServerParam webParam);
StatusCode WebServerExit(void); StatusCode WebServerExit(void);
StatusCode WebServerUnInit(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 #ifdef __cplusplus
} }
#endif #endif

View File

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