添加http文件服务可挂载物理目录,新增ENABLE_API_STATIC_LIB

sa
This commit is contained in:
baiyfcu
2021-08-25 14:30:31 +08:00
parent 4a063bee43
commit 626bf3dcf9
5 changed files with 29 additions and 5 deletions

View File

@@ -18,6 +18,7 @@
#include "HttpConst.h"
#include "HttpSession.h"
#include "Record/HlsMediaSource.h"
#include "Common/Parser.h"
namespace mediakit {
@@ -131,6 +132,15 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
}
setFile.emplace(pDirent->d_name);
}
//如果是root目录添加虚拟目录
if (httpPath == "/") {
GET_CONFIG(string, virtualPath, Http::kVirtualPath);
mediakit::Parser pathParser;
StrCaseMap args = pathParser.parseArgs(virtualPath, "|", ",");
for (auto arg : args) {
setFile.emplace(arg.first);
}
}
int i = 0;
for (auto &strFile :setFile) {
string strAbsolutePath = strPathPrefix + "/" + strFile;
@@ -138,7 +148,7 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
ss << "<li><span>" << i++ << "</span>\t";
ss << "<a href=\"";
if (!last_dir_name.empty()) {
ss << last_dir_name << "/" << strFile;
ss << httpPath << "/" << strFile;
} else {
ss << strFile;
}
@@ -461,7 +471,18 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
static string getFilePath(const Parser &parser,const MediaInfo &mediaInfo, TcpSession &sender){
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
GET_CONFIG(string, rootPath, Http::kRootPath);
auto ret = File::absolutePath(enableVhost ? mediaInfo._vhost + parser.Url() : parser.Url(), rootPath);
GET_CONFIG(string, virtualPath, Http::kVirtualPath);
mediakit::Parser pathParser;
StrCaseMap args = pathParser.parseArgs(virtualPath, "|", ",");
auto path = args[mediaInfo._app];
string ret;
if (path == "") {
ret = File::absolutePath(
enableVhost ? mediaInfo._vhost + parser.Url() : parser.Url(), rootPath);
}else {
ret = File::absolutePath(
enableVhost ? mediaInfo._vhost + "/" + mediaInfo._streamid : mediaInfo._streamid, path);
}
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpBeforeAccess, parser, ret, static_cast<SockInfo &>(sender));
return ret;
}