This commit is contained in:
make
2025-06-02 16:42:16 +08:00
parent 83c3bd512c
commit fe1e2c04d8

View File

@@ -112,7 +112,7 @@ class SiteContext
public function initCfg() public function initCfg()
{ {
$this->limitRequestRate(); $this->limitRequestRate();
if(config('app.default_app_type') == 'novel'){ if (config('app.default_app_type') == 'novel') {
// 全局使用的URL模板 // 全局使用的URL模板
$strPcUrlTemp = $this->DomainModel->getFomartSubject('PC_PATH_URL', '', false); $strPcUrlTemp = $this->DomainModel->getFomartSubject('PC_PATH_URL', '', false);
$strNanUrlTemp = $this->DomainModel->getFomartSubject('NAN_SHENG_URL', '', false); $strNanUrlTemp = $this->DomainModel->getFomartSubject('NAN_SHENG_URL', '', false);
@@ -138,7 +138,7 @@ class SiteContext
View::assign("strHistoryUrlTemp", $strHistoryUrlTemp); View::assign("strHistoryUrlTemp", $strHistoryUrlTemp);
View::assign("strBookShelfUrlTemp", $strBookShelfUrlTemp); View::assign("strBookShelfUrlTemp", $strBookShelfUrlTemp);
View::assign("strUserUrlTemp", $strUserUrlTemp); View::assign("strUserUrlTemp", $strUserUrlTemp);
}else{ } else {
// $strPcUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_PC_PATH_URL', '', false); // $strPcUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_PC_PATH_URL', '', false);
$strRankUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_RANK_INDEX_URL', '', false); $strRankUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_RANK_INDEX_URL', '', false);
$strSearchListUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_SEARCH_LIST_URL', '', false); $strSearchListUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_SEARCH_LIST_URL', '', false);
@@ -148,7 +148,7 @@ class SiteContext
View::assign("strSearchListUrlTemp", $strSearchListUrlTemp); View::assign("strSearchListUrlTemp", $strSearchListUrlTemp);
View::assign("strHistoryUrlTemp", $strHistoryUrlTemp); View::assign("strHistoryUrlTemp", $strHistoryUrlTemp);
} }
// 视频站点需要信息 // 视频站点需要信息
// $strVideoCategoryIndexUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_CATEGORY_INDEX_URL', '', false); // $strVideoCategoryIndexUrlTemp = $this->DomainModel->getFomartSubject('VIDEO_CATEGORY_INDEX_URL', '', false);
@@ -158,7 +158,7 @@ class SiteContext
// View::assign("strVideoSearchListUrlTemp", $strVideoSearchListUrlTemp); // View::assign("strVideoSearchListUrlTemp", $strVideoSearchListUrlTemp);
// View::assign("strVideoHistoryUrlTemp", $strVideoHistoryUrlTemp); // View::assign("strVideoHistoryUrlTemp", $strVideoHistoryUrlTemp);
View::assign('Request', $this->Request); View::assign('Request', $this->Request);
View::assign('DomainModel', $this->DomainModel); View::assign('DomainModel', $this->DomainModel);
@@ -188,7 +188,7 @@ class SiteContext
public function converterTemplate(string $strCode, string | Null $strDiff = "0"): string public function converterTemplate(string $strCode, string | Null $strDiff = "0"): string
{ {
$strTitleTemplate = $this->DomainModel->getFomartSubject($strCode, $strDiff); $strTitleTemplate = $this->DomainModel->getFomartSubject($strCode, $strDiff);
return ConverterMovel::convert($strTitleTemplate); return ConverterMovel::convert($strTitleTemplate);
} }
@@ -231,20 +231,19 @@ class SiteContext
{ {
if ($strPlatform == 'h5') { if ($strPlatform == 'h5') {
if ($this->DomainModel->info_id > 0) { if ($this->DomainModel->info_id > 0) {
if(config('app.default_app_type') == 'video'){ if (config('app.default_app_type') == 'video') {
$strView = 'video/getVideoInfo.html'; $strView = 'video/getVideoInfo.html';
}else{ } else {
$strView = 'novel/getNovelInfo.html'; $strView = 'novel/getNovelInfo.html';
} }
} else { } else {
$strView = 'index/index.html'; $strView = 'index/index.html';
} }
} else { } else {
if ($this->DomainModel->info_id > 0) { if ($this->DomainModel->info_id > 0) {
if(config('app.default_app_type') == 'video'){ if (config('app.default_app_type') == 'video') {
$strView = 'pc/getVideoInfo.html'; $strView = 'pc/getVideoInfo.html';
}else{ } else {
$strView = 'pc/getNovelInfo.html'; $strView = 'pc/getNovelInfo.html';
} }
} else { } else {
@@ -341,7 +340,7 @@ class SiteContext
// 检查分类是否有效 // 检查分类是否有效
if (!empty($strParentCategory) && $strParentCategory !== 'all' && array_key_exists($strParentCategory, StaticConfig::$arrVideoClass)) { if (!empty($strParentCategory) && $strParentCategory !== 'all' && array_key_exists($strParentCategory, StaticConfig::$arrVideoClass)) {
$strVideoParentCategoryName = StaticConfig::$arrVideoClass[$strParentCategory]; $strVideoParentCategoryName = StaticConfig::$arrVideoClass[$strParentCategory];
} }
// 设置分类名称 // 设置分类名称
ConverterMovel::setVal([ ConverterMovel::setVal([
'strVideoParentCategoryName' => $strVideoParentCategoryName, 'strVideoParentCategoryName' => $strVideoParentCategoryName,
@@ -350,7 +349,7 @@ class SiteContext
// $strParentCategory = $this->Request->param('strParentCategory'); // $strParentCategory = $this->Request->param('strParentCategory');
// if (array_key_exists($strParentCategory, StaticConfig::$arrVideoClass)) { // if (array_key_exists($strParentCategory, StaticConfig::$arrVideoClass)) {
// } // }
// ConverterMovel::setVal([ // ConverterMovel::setVal([
// 'strVideoParentCategoryName' => empty($strParentCategory) || $strParentCategory == 'all' ? '' : StaticConfig::$arrVideoClass[$strParentCategory], // 'strVideoParentCategoryName' => empty($strParentCategory) || $strParentCategory == 'all' ? '' : StaticConfig::$arrVideoClass[$strParentCategory],
@@ -408,7 +407,7 @@ class SiteContext
'intPage' => $intPage ?? 1, 'intPage' => $intPage ?? 1,
]); ]);
} }
/** /**
* 视图反向控制器(注释函数),在视图开头调用,用来初始化一些操作。这里尽量不要复杂逻辑。这是个样例 * 视图反向控制器(注释函数),在视图开头调用,用来初始化一些操作。这里尽量不要复杂逻辑。这是个样例
@@ -515,8 +514,8 @@ class SiteContext
// 判断是否为爬虫 // 判断是否为爬虫
$arrVisitInfo['vil_is_spider'] = $this->isSpider($arrVisitInfo['vil_user_agent']); $arrVisitInfo['vil_is_spider'] = $this->isSpider($arrVisitInfo['vil_user_agent']);
$strIp = $this->Request->ip(); $strIp = $this->getRealClientIp();
$strKeyLimit10 = 'access:' . $strIp; $strKeyLimit10 = 'access:' . $strIp;
$strKeyLimit100 = 'access100:' . $strIp; $strKeyLimit100 = 'access100:' . $strIp;
$strKeyBlacklist = 'blacklist:ips'; // 黑名单缓存键 $strKeyBlacklist = 'blacklist:ips'; // 黑名单缓存键
@@ -554,7 +553,7 @@ class SiteContext
} }
$strAGEN = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Amazonbot/0.1; +https://developer.amazon.com/support/amazonbot) Chrome/119.0.6045.214 Safari/537.36'; $strAGEN = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Amazonbot/0.1; +https://developer.amazon.com/support/amazonbot) Chrome/119.0.6045.214 Safari/537.36';
if($arrVisitInfo['vil_user_agent'] == $strAGEN){ if ($arrVisitInfo['vil_user_agent'] == $strAGEN) {
throw new HttpException(404, 'Too Many Requests100'); throw new HttpException(404, 'Too Many Requests100');
//abort(403, 'Too Many Requests100'); //abort(403, 'Too Many Requests100');
} }
@@ -562,7 +561,6 @@ class SiteContext
throw new HttpException(404, 'Too Many Requests100'); throw new HttpException(404, 'Too Many Requests100');
//abort(403, 'Too Many Requests100'); //abort(403, 'Too Many Requests100');
} }
} }
/** /**
@@ -599,4 +597,24 @@ class SiteContext
return false; return false;
} }
/**
* 获取真实ip
*
* @return void
*/
protected function getRealClientIp()
{
$headers = $this->Request->header();
if (isset($headers['x-forwarded-for'])) {
$ips = explode(',', $headers['x-forwarded-for']);
return trim($ips[0]); // 取第一个(用户 IP
}
if (isset($headers['x-real-ip'])) {
return $headers['x-real-ip'];
}
return $this->Request->ip(); // 备用
}
} }