cache rss + redis require 2.0

This commit is contained in:
xiaomlove
2022-07-18 15:13:03 +08:00
parent ffd25a1dae
commit 1759f4abfc
10 changed files with 67 additions and 24 deletions

View File

@@ -28,7 +28,7 @@ Complete PT website building solution. Based on NexusPHP + Laravel + Filament.
## System Requirements
- PHP: 8.0, must have extensions: bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix
- Mysql: 5.7 latest version or above
- Redis1.0.0 or above
- Redis2.0.0 or above
## Quick Start
Install docker.

View File

@@ -27,7 +27,7 @@
## 系统要求
- PHP: 8.0必须扩展bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix
- Mysql: 5.7最新版或以上版本
- Redis1.0.0或以上版本
- Redis2.0.0或以上版本
## 快速开始
安装 docker。

View File

@@ -5,7 +5,7 @@ namespace App\Console\Commands;
use App\Repositories\ToolRepository;
use Illuminate\Console\Command;
class BackuAll extends Command
class BackupAll extends Command
{
/**
* The name and signature of the console command.

View File

@@ -91,6 +91,7 @@ class NexusUpdate extends Command
$symbolicLinks = $settingTableRows['symbolic_links'];
$fails = $settingTableRows['fails'];
$mysqlInfo = $this->update->getMysqlVersionInfo();
$redisInfo = $this->update->getRedisVersionInfo();
if (!empty($fails)) {
foreach ($fails as $value) {
@@ -102,6 +103,10 @@ class NexusUpdate extends Command
$this->doLog("Error: MySQL version: {$mysqlInfo['version']} is too low, please use the newest version of 5.7 or above.", 'error');
return 0;
}
if (!$redisInfo['match']) {
$this->doLog("Error: Redis version: {$mysqlInfo['version']} is too low, please use 2.0.0 or above.", 'error');
return 0;
}
$this->doLog("going to createSymbolicLinks...");
$this->update->createSymbolicLinks($symbolicLinks);
$this->doLog("createSymbolicLinks done!");

View File

@@ -293,7 +293,7 @@ class ExamRepository extends BaseRepository
$logPrefix = "uid: $uid, examId: $examId, begin: $begin, end: $end";
$exam = Exam::query()->find($examId);
$user = User::query()->findOrFail($uid);
if (Auth::user()->Class <= $user->class) {
if (Auth::user()->class <= $user->class) {
throw new NexusException("No permission !");
}
if (!$this->isExamMatchUser($exam, $user)) {

View File

@@ -233,7 +233,7 @@ class UserRepository extends BaseRepository
}
$sourceField = $fieldMap[$field];
$targetUser = User::query()->findOrFail($uid, User::$commonFields);
if (Auth::user()->Class <= $targetUser->class) {
if (Auth::user()->class <= $targetUser->class) {
throw new NexusException("No permission !");
}
$old = $targetUser->{$sourceField};

View File

@@ -663,6 +663,16 @@ class Install
return compact('version', 'match');
}
public function getRedisVersionInfo(): array
{
global $Cache;
$redis = $Cache->getRedis();
$result = $redis->info();
$version = $result['redis_version'];
$match = version_compare($version, '2.0.0', '>=');
return compact('version', 'match');
}
public function checkLock()
{
$fullFilename = ROOT_PATH . $this->lockFile;

View File

@@ -104,6 +104,7 @@ if ($currentStep == 4) {
$tableRows = $settingTableRows['table_rows'];
$pass = $settingTableRows['pass'];
$mysqlInfo = $install->getMysqlVersionInfo();
$redisInfo = $install->getREdisVersionInfo();
while ($isPost) {
set_time_limit(300);
try {
@@ -136,7 +137,11 @@ if ($currentStep == 5) {
];
}
if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) {
if (
!empty($error)
|| (isset($mysqlInfo) && !$mysqlInfo['match'])
|| (isset($redisInfo) && !$redisInfo['match'])
) {
$pass = false;
}
?>
@@ -184,6 +189,9 @@ if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) {
if (!$mysqlInfo['match']) {
echo sprintf('<div class="text-red-700 pt-10">MySQL version: %s is too low, please use the newest version of 5.7 or above.</div>', $mysqlInfo['version']);
}
if (!$redisInfo['match']) {
echo sprintf('<div class="text-red-700 pt-10">Redis version: %s is too low, please use 2.0.0 or above.</div>', $redisInfo['version']);
}
} elseif ($currentStep == 5) {
echo $install->renderForm($userFormControls, '1/2', '1/4', '3/4');
} elseif ($currentStep > $maxStep) {

View File

@@ -157,6 +157,7 @@ if ($currentStep == 4) {
$tableRows = $settingTableRows['table_rows'];
$pass = $settingTableRows['pass'];
$mysqlInfo = $update->getMysqlVersionInfo();
$redisInfo = $update->getREdisVersionInfo();
while ($isPost) {
set_time_limit(300);
try {
@@ -175,7 +176,11 @@ if ($currentStep == 4) {
}
}
if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) {
if (
!empty($error)
|| (isset($mysqlInfo) && !$mysqlInfo['match'])
|| (isset($redisInfo) && !$redisInfo['match'])
) {
$pass = false;
}
?>
@@ -224,6 +229,9 @@ if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) {
if (!$mysqlInfo['match']) {
echo sprintf('<div class="text-red-700 pt-10">MySQL version: %s is too low, please use the newest version of 5.7 or above.</div>', $mysqlInfo['version']);
}
if (!$redisInfo['match']) {
echo sprintf('<div class="text-red-700 pt-10">Redis version: %s is too low, please use 2.0.0 or above.</div>', $redisInfo['version']);
}
} elseif ($currentStep > $maxStep) {
echo '<div class="text-green-900 text-6xl p-10">Congratulations, everything is ready!</div>';
echo '<div class="mb-6">For questions, consult the upgrade log at: <code>' . $update->getLogFile() . '</code></div>';

View File

@@ -1,5 +1,17 @@
<?php
require "../include/bittorrent.php";
$cacheKey = 'nexus_rss';
$hashKey = md5(http_build_query($_GET));
$redis = $Cache->getRedis();
$cacheData = $redis->hGet($cacheKey, $hashKey);
if ($cacheData) {
$cacheData = unserialize($cacheData);
if (isset($cacheData['deadline']) && $cacheData['deadline'] > time()) {
do_log("rss get from cache");
header ("Content-type: text/xml");
die($cacheData['data']);
}
}
dbconn();
function hex_esc($matches) {
return sprintf("%02x", ord($matches[0]));
@@ -117,15 +129,12 @@ $url = get_protocol_prefix().$BASEURL;
$year = substr($datefounded, 0, 4);
$yearfounded = ($year ? $year : 2007);
$copyright = "Copyright (c) ".$SITENAME." ".(date("Y") != $yearfounded ? $yearfounded."-" : "").date("Y").", all rights reserved";
header ("Content-type: text/xml");
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
//The commented version passed feed validator at http://www.feedvalidator.org
/*print('
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">');*/
print('
<rss version="2.0">');
print('
<channel>
$xml .= '<rss version="2.0">';
$xml .= '<channel>
<title>' . addslashes($SITENAME.' Torrents'). '</title>
<link><![CDATA[' . $url . ']]></link>
<description><![CDATA[' . addslashes('Latest torrents from '.$SITENAME.' - '.htmlspecialchars($SLOGAN)) . ']]></description>
@@ -144,11 +153,11 @@ print('
<width>100</width>
<height>100</height>
<description>' . addslashes($SITENAME.' Torrents') . '</description>
</image>');
</image>';
/*print('
<atom:link href="'.$url.$_SERVER['REQUEST_URI'].'" rel="self" type="application/rss+xml" />');*/
print('
');
//print('
//');
foreach ($list as $row)
{
$title = "";
@@ -165,22 +174,25 @@ foreach ($list as $row)
if (!empty($_GET['isize'])) $title .= "[".mksize($row['size'])."]";
if (!empty($_GET['iuplder'])) $title .= "[".$author."]";
$content = format_comment($row['descr'], true, false, false, false);
print(' <item>
$xml .= '<item>
<title><![CDATA['.$title.']]></title>
<link>'.$itemurl.'</link>
<description><![CDATA['.$content.']]></description>
');
';
//print(' <dc:creator>'.$author.'</dc:creator>');
print(' <author>'.$author.'@'.$_SERVER['HTTP_HOST'].' ('.$author.')</author>');
print('
<category domain="'.$url.'/torrents.php?cat='.$row['cat_id'].'">'.$row['cat_name'].'</category>
$xml .= '<author>'.$author.'@'.$_SERVER['HTTP_HOST'].' ('.$author.')</author>';
$xml .= '<category domain="'.$url.'/torrents.php?cat='.$row['cat_id'].'">'.$row['cat_name'].'</category>
<comments><![CDATA['.$url.'/details.php?id='.$row['id'].'&cmtpage=0#startcomments]]></comments>
<enclosure url="'.$itemdlurl.'" length="'.$row['size'].'" type="application/x-bittorrent" />
<guid isPermaLink="false">'.preg_replace_callback('/./s', 'hex_esc', hash_pad($row['info_hash'])).'</guid>
<pubDate>'.date('r',strtotime($row['added'])).'</pubDate>
</item>
');
';
}
print(' </channel>
</rss>');
$xml .= '</channel>
</rss>';
do_log("rss cache generated");
$redis->hSet($cacheKey, $hashKey, serialize(['data' => $xml, 'deadline' => time() + 300]));
header ("Content-type: text/xml");
echo $xml;
?>