torrent global state add begin

This commit is contained in:
xiaomlove
2022-08-26 17:35:49 +08:00
parent cedd9ec437
commit e6888c043c
12 changed files with 94 additions and 29 deletions
@@ -4,6 +4,7 @@ namespace App\Filament\Resources\System;
use App\Filament\Resources\System\TorrentStateResource\Pages;
use App\Filament\Resources\System\TorrentStateResource\RelationManagers;
use App\Models\Setting;
use App\Models\Torrent;
use App\Models\TorrentState;
use Filament\Forms;
@@ -43,8 +44,9 @@ class TorrentStateResource extends Resource
->options(Torrent::listPromotionTypes(true))
->label(__('label.torrent_state.global_sp_state'))
->required(),
Forms\Components\DateTimePicker::make('begin')
->label(__('label.begin')),
Forms\Components\DateTimePicker::make('deadline')
->required()
->label(__('label.deadline')),
])->columns(1);
}
@@ -54,6 +56,7 @@ class TorrentStateResource extends Resource
return $table
->columns([
Tables\Columns\TextColumn::make('global_sp_state_text')->label(__('label.torrent_state.global_sp_state')),
Tables\Columns\TextColumn::make('begin')->label(__('label.begin')),
Tables\Columns\TextColumn::make('deadline')->label(__('label.deadline')),
])
->filters([
@@ -62,8 +65,7 @@ class TorrentStateResource extends Resource
->actions([
Tables\Actions\EditAction::make()->after(function () {
do_log("cache_del: global_promotion_state");
NexusDB::cache_del('global_promotion_state');
NexusDB::cache_del('global_promotion_state_deadline');
NexusDB::cache_del(Setting::TORRENT_GLOBAL_STATE_CACHE_KEY);
}),
// Tables\Actions\DeleteAction::make(),
])
@@ -37,6 +37,8 @@ class TorrentResource extends Resource
protected static ?int $navigationSort = 1;
private static ?TorrentRepository $rep;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.torrent_list');
@@ -55,6 +57,14 @@ class TorrentResource extends Resource
]);
}
public static function getRep(): ?TorrentRepository
{
if (self::$rep === null) {
self::$rep = new TorrentRepository();
}
return self::$rep;
}
public static function table(Table $table): Table
{
$showApproval = self::shouldShowApproval();
@@ -64,8 +74,8 @@ class TorrentResource extends Resource
Tables\Columns\TextColumn::make('basic_category.name')->label(__('label.torrent.category')),
Tables\Columns\TextColumn::make('name')->formatStateUsing(function (Torrent $record) {
$name = sprintf(
'<div class="text-primary-600 transition hover:underline hover:text-primary-500 focus:underline focus:text-primary-500"><a href="/details.php?id=%s" target="_blank">%s</a></div>',
$record->id, Str::limit($record->name, 40)
'<div class="text-primary-600 transition hover:underline hover:text-primary-500 focus:underline focus:text-primary-500"><a href="/details.php?id=%s" target="_blank" title="%s">%s</a></div>',
$record->id, $record->name, Str::limit($record->name, 40)
);
$tags = sprintf('&nbsp;<div>%s</div>', $record->tagsFormatted);
@@ -206,8 +216,7 @@ class TorrentResource extends Resource
private static function getActions(): array
{
$actions = [];
$userClass = Auth::user()->class;
if (self::shouldShowApproval() && $userClass >= Setting::get('authority.torrentmanage')) {
if (self::shouldShowApproval() && user_can('torrent-approval')) {
$actions[] = Tables\Actions\Action::make('approval')
->label(__('admin.resources.torrent.action_approval'))
->form([
@@ -228,6 +237,12 @@ class TorrentResource extends Resource
do_log($exception->getMessage(), 'error');
}
});
}
if (user_can('torrentmanage')) {
$actions[] = Tables\Actions\DeleteAction::make('delete')->using(function ($record) {
deletetorrent($record->id);
});
}
return $actions;
}
+2
View File
@@ -18,6 +18,8 @@ class Setting extends NexusModel
const DIRECT_PERMISSION_CACHE_KEY_PREFIX = 'nexus_direct_permissions_';
const ROLE_PERMISSION_CACHE_KEY_PREFIX = 'nexus_role_permissions_';
const TORRENT_GLOBAL_STATE_CACHE_KEY = 'global_promotion_state';
/**
* get setting autoload = yes with cache
*
+1 -1
View File
@@ -5,7 +5,7 @@ namespace App\Models;
class TorrentState extends NexusModel
{
protected $fillable = ['global_sp_state', 'deadline'];
protected $fillable = ['global_sp_state', 'deadline', 'begin'];
protected $table = 'torrents_state';
-1
View File
@@ -605,5 +605,4 @@ class TorrentRepository extends BaseRepository
return Torrent::query()->whereIn('id', $idArr)->update(['pos_state' => $posState]);
}
}
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('torrents_state', function (Blueprint $table) {
$table->dateTime('begin')->nullable(true);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('torrents_state', function (Blueprint $table) {
$table->dropColumn('begin');
});
}
};
+13 -11
View File
@@ -2689,11 +2689,12 @@ if ($msgalert)
{
$spStateGlobal = get_global_sp_state();
if ($spStateGlobal != \App\Models\Torrent::PROMOTION_NORMAL) {
$deadline = \Nexus\Database\NexusDB::cache_get('global_promotion_state_deadline');
if (!$deadline) {
$deadline = \App\Models\TorrentState::query()->first(['deadline'])->deadline ?? '';
}
msgalert("torrents.php", sprintf($lang_functions['full_site_promotion_in_effect'], \App\Models\Torrent::$promotionTypes[$spStateGlobal]['text'], $deadline), "green");
$torrentGlobalStateRow = \Nexus\Database\NexusDB::cache_get(\App\Models\Setting::TORRENT_GLOBAL_STATE_CACHE_KEY);
$timeRange = sprintf('%s ~ %s', $torrentGlobalStateRow['begin'] ?? '', $torrentGlobalStateRow['deadline'] ?? '');
msgalert("torrents.php", sprintf(
$lang_functions['full_site_promotion_in_effect'],
\App\Models\Torrent::$promotionTypes[$spStateGlobal]['text'], $timeRange
), "green");
}
if($CURUSER['leechwarn'] == 'yes')
{
@@ -3030,14 +3031,15 @@ function loggedinorreturn($mainpage = false) {
}
function deletetorrent($id) {
global $torrent_dir;
sql_query("DELETE FROM torrents WHERE id = ".mysql_real_escape_string($id));
sql_query("DELETE FROM snatched WHERE torrentid = ".mysql_real_escape_string($id));
$id = intval($id);
$torrent_dir = get_setting('main.torrent_dir');
\Nexus\Database\NexusDB::statement("DELETE FROM torrents WHERE id = $id");
\Nexus\Database\NexusDB::statement("DELETE FROM snatched WHERE torrentid = $id");
foreach(array("peers", "files", "comments") as $x) {
sql_query("DELETE FROM $x WHERE torrent = ".mysql_real_escape_string($id));
\Nexus\Database\NexusDB::statement("DELETE FROM $x WHERE torrent = $id");
}
sql_query("DELETE FROM hit_and_runs WHERE torrent_id = ".mysql_real_escape_string($id));
sql_query("DELETE FROM claims WHERE torrent_id = ".mysql_real_escape_string($id));
\Nexus\Database\NexusDB::statement("DELETE FROM hit_and_runs WHERE torrent_id = $id");
\Nexus\Database\NexusDB::statement("DELETE FROM claims WHERE torrent_id = $id");
do_action("torrent_delete", $id);
do_log("delete torrent: $id", "error");
unlink(getFullDirectory("$torrent_dir/$id.torrent"));
+5 -4
View File
@@ -3,16 +3,17 @@
function get_global_sp_state()
{
static $global_promotion_state;
$cacheKey = 'global_promotion_state';
$cacheKey = \App\Models\Setting::TORRENT_GLOBAL_STATE_CACHE_KEY;
if (!$global_promotion_state) {
$row = \Nexus\Database\NexusDB::remember($cacheKey, 600, function () use ($cacheKey) {
$row = \Nexus\Database\NexusDB::getOne('torrents_state', 1);
\Nexus\Database\NexusDB::cache_put($cacheKey . '_deadline', $row['deadline'], 600);
return $row;
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"];
} else {
+1 -1
View File
@@ -321,7 +321,7 @@ $lang_functions = array
'menu_claim' => '认领: ',
'text_complains' => '有%s%u个待处理的申诉%s',
'text_contactstaff' => '联系管理组',
'full_site_promotion_in_effect' => '全站 [%s] 生效中!截止时间:%s',
'full_site_promotion_in_effect' => '全站 [%s] 生效中!时间:%s',
'text_torrent_to_approval' => '有 %s%u 个待审核的种子%s',
'std_confirm_remove' => '确定要删除吗?',
'select_an_user_class' => '选择一个用户等级',
+1 -1
View File
@@ -328,7 +328,7 @@ $lang_functions = array
'menu_claim' => '認領: ',
'text_complains' => '有%s%u個待處理的申诉%s',
'text_contactstaff' => '聯系管理組',
'full_site_promotion_in_effect' => '全站 [%s] 生效中!截止時間:%s',
'full_site_promotion_in_effect' => '全站 [%s] 生效中!時間:%s',
'text_torrent_to_approval' => '有 %s%u 個待審核的種子%s',
'std_confirm_remove' => '確定要刪除嗎?',
'select_an_user_class' => '選擇一個用戶等級',
+1 -1
View File
@@ -329,7 +329,7 @@ $lang_functions = array
'menu_claim' => 'Claim: ',
'text_complains' => 'There %s %u pending complaint%s.',
'text_contactstaff' => 'Contact staff',
'full_site_promotion_in_effect' => 'Full site [%s] in effect! Deadline: %s',
'full_site_promotion_in_effect' => 'Full site [%s] in effect! Time range: %s',
'text_torrent_to_approval' => 'There %s%u not approval torrent%s.',
'std_confirm_remove' => 'Are you sure you want to delete it?',
'select_an_user_class' => 'Select an user class',
+14 -2
View File
@@ -80,7 +80,7 @@ class TechnicalInformation
public function getRefFrame()
{
foreach ($this->mediaInfoArr['Video'] ?? [] as $key => $value) {
if (strpos($key, 'Reference frames') !== false) {
if (str_contains($key, 'Reference frames')) {
return $value;
}
}
@@ -135,6 +135,16 @@ class TechnicalInformation
return $result;
}
public function getHDRFormat()
{
return $this->mediaInfoArr['Video']['HDR format'] ?? '';
}
public function getBitDepth()
{
return $this->mediaInfoArr['Video']['Bit depth'] ?? '';
}
public function renderOnDetailsPage()
{
global $lang_functions;
@@ -142,7 +152,9 @@ class TechnicalInformation
'Runtime' => $this->getRuntime(),
'Resolution' => $this->getResolution(),
'Bitrate' => $this->getBitrate(),
'Framerate' => $this->getFramerate(),
'HDR' => $this->getHDRFormat(),
'Bit depth' => $this->getBitDepth(),
'Frame rate' => $this->getFramerate(),
'Profile' => $this->getProfile(),
'Ref.Frames' => $this->getRefFrame(),
];