diff --git a/app/Filament/Resources/System/TorrentStateResource.php b/app/Filament/Resources/System/TorrentStateResource.php
index 60015652..51bd13ec 100644
--- a/app/Filament/Resources/System/TorrentStateResource.php
+++ b/app/Filament/Resources/System/TorrentStateResource.php
@@ -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(),
])
diff --git a/app/Filament/Resources/Torrent/TorrentResource.php b/app/Filament/Resources/Torrent/TorrentResource.php
index 7af59e93..6163de01 100644
--- a/app/Filament/Resources/Torrent/TorrentResource.php
+++ b/app/Filament/Resources/Torrent/TorrentResource.php
@@ -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(
- '
',
- $record->id, Str::limit($record->name, 40)
+ '',
+ $record->id, $record->name, Str::limit($record->name, 40)
);
$tags = sprintf(' %s
', $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;
}
diff --git a/app/Models/Setting.php b/app/Models/Setting.php
index 9fc7fc2e..9d5b5660 100644
--- a/app/Models/Setting.php
+++ b/app/Models/Setting.php
@@ -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
*
diff --git a/app/Models/TorrentState.php b/app/Models/TorrentState.php
index f0d32f1b..498a4515 100644
--- a/app/Models/TorrentState.php
+++ b/app/Models/TorrentState.php
@@ -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';
diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php
index 62f5feba..8b619243 100644
--- a/app/Repositories/TorrentRepository.php
+++ b/app/Repositories/TorrentRepository.php
@@ -605,5 +605,4 @@ class TorrentRepository extends BaseRepository
return Torrent::query()->whereIn('id', $idArr)->update(['pos_state' => $posState]);
}
-
}
diff --git a/database/migrations/2022_08_26_061516_add_begin_to_torrents_state_table.php b/database/migrations/2022_08_26_061516_add_begin_to_torrents_state_table.php
new file mode 100644
index 00000000..06793c16
--- /dev/null
+++ b/database/migrations/2022_08_26_061516_add_begin_to_torrents_state_table.php
@@ -0,0 +1,32 @@
+dateTime('begin')->nullable(true);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('torrents_state', function (Blueprint $table) {
+ $table->dropColumn('begin');
+ });
+ }
+};
diff --git a/include/functions.php b/include/functions.php
index 2b5a4260..ab4750e0 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -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"));
diff --git a/include/globalfunctions.php b/include/globalfunctions.php
index 997ca8e2..3cb0af01 100644
--- a/include/globalfunctions.php
+++ b/include/globalfunctions.php
@@ -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 {
diff --git a/lang/chs/lang_functions.php b/lang/chs/lang_functions.php
index d42e3cb4..adb07155 100644
--- a/lang/chs/lang_functions.php
+++ b/lang/chs/lang_functions.php
@@ -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' => '选择一个用户等级',
diff --git a/lang/cht/lang_functions.php b/lang/cht/lang_functions.php
index 4e49e9e2..719b2569 100644
--- a/lang/cht/lang_functions.php
+++ b/lang/cht/lang_functions.php
@@ -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' => '選擇一個用戶等級',
diff --git a/lang/en/lang_functions.php b/lang/en/lang_functions.php
index 51b2a4a4..166233b1 100644
--- a/lang/en/lang_functions.php
+++ b/lang/en/lang_functions.php
@@ -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',
diff --git a/nexus/Torrent/TechnicalInformation.php b/nexus/Torrent/TechnicalInformation.php
index 34cab405..b7080573 100644
--- a/nexus/Torrent/TechnicalInformation.php
+++ b/nexus/Torrent/TechnicalInformation.php
@@ -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(),
];