mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
修改无法删除hls目录的bug:#1485
This commit is contained in:
parent
2d88115b3f
commit
ed661b1cf1
@ -1 +1 @@
|
|||||||
Subproject commit 9d3124047d1ec64bf1674ae71bd4fddd728d2243
|
Subproject commit 3c4a8ce36a18162b3cdc8094cdeba9d752cb3408
|
@ -353,35 +353,23 @@ static string pathCat(const string &a, const string &b){
|
|||||||
*/
|
*/
|
||||||
static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
|
static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
|
||||||
bool is_hls = end_with(file_path, kHlsSuffix);
|
bool is_hls = end_with(file_path, kHlsSuffix);
|
||||||
bool file_exist = File::is_file(file_path.data());
|
if (!is_hls && !File::fileExist(file_path.data())) {
|
||||||
bool is_forbid_cache = false;
|
|
||||||
if (!is_hls && !file_exist) {
|
|
||||||
//文件不存在且不是hls,那么直接返回404
|
//文件不存在且不是hls,那么直接返回404
|
||||||
sendNotFound(cb);
|
sendNotFound(cb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_hls) {
|
if (is_hls) {
|
||||||
//hls,那么移除掉后缀获取真实的stream_id并且修改协议为HLS
|
// hls,那么移除掉后缀获取真实的stream_id并且修改协议为HLS
|
||||||
const_cast<string &>(media_info._schema) = HLS_SCHEMA;
|
const_cast<string &>(media_info._schema) = HLS_SCHEMA;
|
||||||
replace(const_cast<string &>(media_info._streamid), kHlsSuffix, "");
|
replace(const_cast<string &>(media_info._streamid), kHlsSuffix, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_CONFIG_FUNC(vector<string>, forbidCacheSuffix, Http::kForbidCacheSuffix, [](const string &str) {
|
|
||||||
return split(str,",");
|
|
||||||
});
|
|
||||||
for (auto &suffix : forbidCacheSuffix) {
|
|
||||||
if(suffix != "" && end_with(file_path, suffix)){
|
|
||||||
is_forbid_cache = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
weak_ptr<TcpSession> weakSession = sender.shared_from_this();
|
weak_ptr<TcpSession> weakSession = sender.shared_from_this();
|
||||||
//判断是否有权限访问该文件
|
//判断是否有权限访问该文件
|
||||||
canAccessPath(sender, parser, media_info, false, [cb, file_path, parser, is_hls,is_forbid_cache, media_info, weakSession , file_exist](const string &err_msg, const HttpServerCookie::Ptr &cookie) {
|
canAccessPath(sender, parser, media_info, false, [cb, file_path, parser, is_hls, media_info, weakSession](const string &err_msg, const HttpServerCookie::Ptr &cookie) {
|
||||||
auto strongSession = weakSession.lock();
|
auto strongSession = weakSession.lock();
|
||||||
if (!strongSession) {
|
if (!strongSession) {
|
||||||
//http客户端已经断开,不需要回复
|
// http客户端已经断开,不需要回复
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!err_msg.empty()) {
|
if (!err_msg.empty()) {
|
||||||
@ -394,14 +382,13 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto response_file = [file_exist, is_hls, is_forbid_cache](const HttpServerCookie::Ptr &cookie, const HttpFileManager::invoker &cb,
|
auto response_file = [is_hls](const HttpServerCookie::Ptr &cookie, const HttpFileManager::invoker &cb, const string &file_path, const Parser &parser, const string &file_content = "") {
|
||||||
const string &file_path, const Parser &parser, const string &file_content = "") {
|
|
||||||
StrCaseMap httpHeader;
|
StrCaseMap httpHeader;
|
||||||
if (cookie) {
|
if (cookie) {
|
||||||
httpHeader["Set-Cookie"] = cookie->getCookie(cookie->getAttach<HttpCookieAttachment>()._path);
|
httpHeader["Set-Cookie"] = cookie->getCookie(cookie->getAttach<HttpCookieAttachment>()._path);
|
||||||
}
|
}
|
||||||
HttpSession::HttpResponseInvoker invoker = [&](int code, const StrCaseMap &headerOut, const HttpBody::Ptr &body) {
|
HttpSession::HttpResponseInvoker invoker = [&](int code, const StrCaseMap &headerOut, const HttpBody::Ptr &body) {
|
||||||
if (cookie && file_exist) {
|
if (cookie && body) {
|
||||||
auto& attach = cookie->getAttach<HttpCookieAttachment>();
|
auto& attach = cookie->getAttach<HttpCookieAttachment>();
|
||||||
if (attach._hls_data) {
|
if (attach._hls_data) {
|
||||||
attach._hls_data->addByteUsage(body->remainSize());
|
attach._hls_data->addByteUsage(body->remainSize());
|
||||||
@ -409,6 +396,16 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
|||||||
}
|
}
|
||||||
cb(code, HttpFileManager::getContentType(file_path.data()), headerOut, body);
|
cb(code, HttpFileManager::getContentType(file_path.data()), headerOut, body);
|
||||||
};
|
};
|
||||||
|
GET_CONFIG_FUNC(vector<string>, forbidCacheSuffix, Http::kForbidCacheSuffix, [](const string &str) {
|
||||||
|
return split(str, ",");
|
||||||
|
});
|
||||||
|
bool is_forbid_cache;
|
||||||
|
for (auto &suffix : forbidCacheSuffix) {
|
||||||
|
if (suffix != "" && end_with(file_path, suffix)) {
|
||||||
|
is_forbid_cache = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
invoker.responseFile(parser.getHeader(), httpHeader, file_content.empty() ? file_path : file_content, !is_hls && !is_forbid_cache, file_content.empty());
|
invoker.responseFile(parser.getHeader(), httpHeader, file_content.empty() ? file_path : file_content, !is_hls && !is_forbid_cache, file_content.empty());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user