mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 04:20:49 +08:00
improve torrent approval
This commit is contained in:
73
app/Filament/Resources/Torrent/TorrentDenyReasonResource.php
Normal file
73
app/Filament/Resources/Torrent/TorrentDenyReasonResource.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Torrent;
|
||||
|
||||
use App\Filament\Resources\Torrent\TorrentDenyReasonResource\Pages;
|
||||
use App\Filament\Resources\Torrent\TorrentDenyReasonResource\RelationManagers;
|
||||
use App\Models\TorrentDenyReason;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class TorrentDenyReasonResource extends Resource
|
||||
{
|
||||
protected static ?string $model = TorrentDenyReason::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-ban';
|
||||
|
||||
protected static ?string $navigationGroup = 'Torrent';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.torrent_deny_reason');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->required()->label(__('label.name')),
|
||||
Forms\Components\TextInput::make('priority')->integer()->label(__('label.priority'))->default(0),
|
||||
])->columns(1);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id'),
|
||||
Tables\Columns\TextColumn::make('name')->label(__('label.name')),
|
||||
Tables\Columns\TextColumn::make('priority')->label(__('label.priority'))->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')->label(__('label.created_at')),
|
||||
])
|
||||
->defaultSort('priority', 'desc')
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ManageTorrentDenyReasons::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Torrent\TorrentDenyReasonResource\Pages;
|
||||
|
||||
use App\Filament\Resources\Torrent\TorrentDenyReasonResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageTorrentDenyReasons extends ManageRecords
|
||||
{
|
||||
protected ?string $maxContentWidth = 'full';
|
||||
|
||||
protected static string $resource = TorrentDenyReasonResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\RewardResource;
|
||||
use App\Http\Resources\TorrentOperationLogResource;
|
||||
use App\Http\Resources\TorrentResource;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\TorrentDenyReason;
|
||||
use App\Models\TorrentOperationLog;
|
||||
use App\Models\User;
|
||||
use App\Repositories\TorrentRepository;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -100,4 +103,45 @@ class TorrentController extends Controller
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
public function approvalPage(Request $request)
|
||||
{
|
||||
$request->validate(['torrent_id' => 'required']);
|
||||
$torrentId = $request->torrent_id;
|
||||
$torrent = Torrent::query()->findOrFail($torrentId, Torrent::$commentFields);
|
||||
$denyReasons = TorrentDenyReason::query()->orderBy('priority', 'desc')->get();
|
||||
return view('torrent/approval', compact('torrent', 'denyReasons'));
|
||||
}
|
||||
|
||||
public function approvalLogs(Request $request)
|
||||
{
|
||||
$request->validate(['torrent_id' => 'required']);
|
||||
$torrentId = $request->torrent_id;
|
||||
$actionTypes = [
|
||||
TorrentOperationLog::ACTION_TYPE_APPROVAL_NONE,
|
||||
TorrentOperationLog::ACTION_TYPE_APPROVAL_ALLOW,
|
||||
TorrentOperationLog::ACTION_TYPE_APPROVAL_DENY,
|
||||
];
|
||||
$records = TorrentOperationLog::query()
|
||||
->with(['user'])
|
||||
->where('torrent_id', $torrentId)
|
||||
->whereIn('action_type', $actionTypes)
|
||||
->orderBy('id', 'desc')
|
||||
->paginate($request->limit);
|
||||
|
||||
$resource = TorrentOperationLogResource::collection($records);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
public function approval(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'torrent_id' => 'required',
|
||||
'approval_status' => 'required',
|
||||
]);
|
||||
$params = $request->all();
|
||||
$this->repository->approval(Auth::user(), $params);
|
||||
return $this->success($params);
|
||||
}
|
||||
}
|
||||
|
||||
27
app/Http/Resources/TorrentOperationLogResource.php
Normal file
27
app/Http/Resources/TorrentOperationLogResource.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TorrentOperationLogResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'action_type' => $this->action_type,
|
||||
'action_type_text' => $this->actionTypeText,
|
||||
'uid' => $this->uid,
|
||||
'username' => $this->user->username,
|
||||
'comment' => $this->comment,
|
||||
'created_at' => format_datetime($this->created_at)
|
||||
];
|
||||
}
|
||||
}
|
||||
15
app/Models/TorrentDenyReason.php
Normal file
15
app/Models/TorrentDenyReason.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class TorrentDenyReason extends NexusModel
|
||||
{
|
||||
protected $table = 'torrent_deny_reasons';
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = ['name', 'hits', 'priority',];
|
||||
|
||||
}
|
||||
@@ -22,6 +22,11 @@ class TorrentOperationLog extends NexusModel
|
||||
self::ACTION_TYPE_APPROVAL_DENY => ['text' => 'Approval deny'],
|
||||
];
|
||||
|
||||
public function getActionTypeTextAttribute()
|
||||
{
|
||||
return nexus_trans("torrent.operation_log.{$this->action_type}.type_text");
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'uid')->select(User::$commonFields);
|
||||
|
||||
Reference in New Issue
Block a user