feat: enhance torrent state scheduling and display

Signed-off-by: Qi HU <github@spcsky.com>
This commit is contained in:
Qi HU
2025-12-07 12:57:08 +08:00
parent f098ef72b5
commit 2346afa291
13 changed files with 436 additions and 47 deletions
+6 -13
View File
@@ -3,21 +3,14 @@
function get_global_sp_state()
{
static $global_promotion_state;
$cacheKey = \App\Models\Setting::TORRENT_GLOBAL_STATE_CACHE_KEY;
if (is_null($global_promotion_state)) {
$row = \Nexus\Database\NexusDB::remember($cacheKey, 600, function () use ($cacheKey) {
return \Nexus\Database\NexusDB::getOne('torrents_state', 1);
});
if (is_array($row) && isset($row['deadline']) && $row['deadline'] < date('Y-m-d H:i:s')) {
//expired
$global_promotion_state = \App\Models\Torrent::PROMOTION_NORMAL;
} elseif (is_array($row) && isset($row['begin']) && $row['begin'] > date('Y-m-d H:i:s')) {
//Not begin
$global_promotion_state = \App\Models\Torrent::PROMOTION_NORMAL;
} elseif (is_array($row)) {
$global_promotion_state = $row["global_sp_state"];
$timeline = \App\Models\TorrentState::resolveTimeline();
$current = $timeline['current'] ?? null;
if (is_array($current) && isset($current['global_sp_state'])) {
$global_promotion_state = $current['global_sp_state'];
} else {
$global_promotion_state = $row;
$global_promotion_state = \App\Models\Torrent::PROMOTION_NORMAL;
}
}
return $global_promotion_state;