diff --git a/app/Filament/Resources/Torrent/TorrentResource.php b/app/Filament/Resources/Torrent/TorrentResource.php index bc046f67..49f14881 100644 --- a/app/Filament/Resources/Torrent/TorrentResource.php +++ b/app/Filament/Resources/Torrent/TorrentResource.php @@ -155,13 +155,17 @@ class TorrentResource extends Resource ->label(__('label.torrent.pos_state')) ->options(Torrent::listPosStates(true)) ->required() + , + Forms\Components\DateTimePicker::make('pos_state_until') + ->label(__('label.deadline')) + , ]) ->icon('heroicon-o-arrow-circle-up') ->action(function (Collection $records, array $data) { $idArr = $records->pluck('id')->toArray(); try { $torrentRep = new TorrentRepository(); - $torrentRep->setPosState($idArr, $data['pos_state']); + $torrentRep->setPosState($idArr, $data['pos_state'], $data['pos_state_until']); } catch (\Exception $exception) { do_log($exception->getMessage() . $exception->getTraceAsString(), 'error'); Filament::notify('danger', class_basename($exception)); diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index cce44462..49726ed1 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Repositories\TagRepository; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Casts\Attribute; use JeroenG\Explorer\Application\Explored; use Laravel\Scout\Searchable; @@ -15,7 +16,7 @@ class Torrent extends NexusModel 'size', 'added', 'type', 'numfiles', 'owner', 'nfo', 'sp_state', 'promotion_time_type', 'promotion_until', 'anonymous', 'url', 'pos_state', 'cache_stamp', 'picktype', 'picktime', 'last_reseed', 'pt_gen', 'technical_info', 'leechers', 'seeders', 'cover', 'last_action', - 'times_completed', 'approval_status', 'banned', 'visible', + 'times_completed', 'approval_status', 'banned', 'visible', 'pos_state_until', ]; private static $globalPromotionState; @@ -30,11 +31,13 @@ class Torrent extends NexusModel 'added' => 'datetime', 'pt_gen' => 'array', 'promotion_until' => 'datetime', + 'pos_state_until' => 'datetime', ]; public static $commentFields = [ 'id', 'name', 'added', 'visible', 'banned', 'owner', 'sp_state', 'pos_state', 'hr', 'picktype', 'picktime', - 'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size', 'cover', 'anonymous', 'approval_status' + 'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size', 'cover', 'anonymous', 'approval_status', + 'pos_state_until' ]; public static $basicRelations = [ @@ -193,11 +196,18 @@ class Torrent extends NexusModel return $spState; } - protected function posStateText(): Attribute + protected function getPosStateTextAttribute() { - return new Attribute( - get: fn($value, $attributes) => nexus_trans('torrent.pos_state_' . $attributes['pos_state']) - ); + $text = nexus_trans('torrent.pos_state_' . $this->pos_state); + if ($this->pos_state != Torrent::POS_STATE_STICKY_NONE) { + if ($this->pos_state_until) { + $append = format_datetime($this->pos_state_until); + } else { + $append = nexus_trans('label.permanent'); + } + $text .= "($append)"; + } + return $text; } protected function approvalStatusText(): Attribute diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index 0f10aa2b..fe91ad6d 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -598,11 +598,22 @@ class TorrentRepository extends BaseRepository } - public function setPosState($id, $posState): int + public function setPosState($id, $posState, $posStateUntil = null): int { user_can('torrentsticky', true); + if ($posState == Torrent::POS_STATE_STICKY_NONE) { + $posStateUntil = null; + } + if ($posStateUntil && Carbon::parse($posStateUntil)->lte(now())) { + $posState = Torrent::POS_STATE_STICKY_NONE; + $posStateUntil = null; + } + $update = [ + 'pos_state' => $posState, + 'pos_state_until' => $posStateUntil, + ]; $idArr = Arr::wrap($id); - return Torrent::query()->whereIn('id', $idArr)->update(['pos_state' => $posState]); + return Torrent::query()->whereIn('id', $idArr)->update($update); } public function buildUploadFieldInput($name, $value, $noteText, $btnText): string