mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
[admin] set torrent pos_state_until
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user