Detect if IP is SeedBox

This commit is contained in:
xiaomlove
2024-11-22 01:37:57 +08:00
parent c864a34412
commit c537ebc1a2
10 changed files with 77 additions and 6 deletions

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Exceptions;
class SeedBoxYesException extends NexusException
{
private int $id;
public function __construct($id)
{
parent::__construct();
$this->id = $id;
}
public function getId(): int
{
return $this->id;
}
}

View File

@@ -2,10 +2,11 @@
namespace App\Filament\Resources\System\SeedBoxRecordResource\Pages;
use App\Exceptions\SeedBoxYesException;
use App\Filament\PageList;
use App\Filament\Resources\System\SeedBoxRecordResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;
use Filament\Forms;
class ListSeedBoxRecords extends PageList
{
@@ -15,6 +16,24 @@ class ListSeedBoxRecords extends PageList
{
return [
Actions\CreateAction::make(),
Actions\Action::make('check')
->label(__('admin.resources.seed_box_record.check_modal_btn'))
->form([
Forms\Components\TextInput::make('ip')->required()->label('IP'),
Forms\Components\TextInput::make('uid')->required()->label('UID'),
])
->modalHeading(__('admin.resources.seed_box_record.check_modal_header'))
->action(function ($data) {
try {
isIPSeedBox($data['ip'], $data['uid'], true, true);
$this->notify('success', nexus_trans("seed-box.is_seed_box_no"));
} catch (SeedBoxYesException $exception) {
$this->notify('danger', nexus_trans("seed-box.is_seed_box_yes", ['id' => $exception->getId()]));
} catch (\Throwable $throwable) {
do_log($throwable->getMessage() . $throwable->getTraceAsString(), "error");
$this->notify('danger', $throwable->getMessage());
}
})
];
}
}