feat(admin-frontend): 新增节点自动上线托管能力

为节点新增 auto_online 字段与后台同步任务,
仅对开启托管的节点按在线状态自动同步前台显示。

管理端补齐单节点与批量开关、列表标识与统计,
并在自动上线启用时禁用手动显隐切换。

后端新增定时命令、保存校验、批量更新支持、
数据库迁移与单元测试,保证托管逻辑可落地。
This commit is contained in:
yinjianm
2026-04-28 00:08:12 +08:00
parent 9af9dd0df7
commit 73b1696b0a
26 changed files with 361 additions and 33 deletions
@@ -0,0 +1,62 @@
<?php
namespace Tests\Unit;
use App\Models\Server;
use App\Services\ServerAutoOnlineService;
use App\Services\ServerService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ServerAutoOnlineServiceTest extends TestCase
{
use RefreshDatabase;
public function test_sync_updates_only_nodes_with_auto_online_enabled(): void
{
$managedOffline = $this->makeServer([
'name' => 'managed-offline',
'show' => true,
'auto_online' => true,
]);
$managedOnline = $this->makeServer([
'name' => 'managed-online',
'show' => false,
'auto_online' => true,
]);
$manualOffline = $this->makeServer([
'name' => 'manual-offline',
'show' => true,
'auto_online' => false,
]);
ServerService::touchNode($managedOnline);
$result = app(ServerAutoOnlineService::class)->sync();
$this->assertSame(2, $result['total']);
$this->assertSame(2, $result['updated']);
$this->assertSame(1, $result['shown']);
$this->assertSame(1, $result['hidden']);
$this->assertFalse($managedOffline->fresh()->show);
$this->assertTrue($managedOnline->fresh()->show);
$this->assertTrue($manualOffline->fresh()->show);
}
private function makeServer(array $attributes = []): Server
{
return Server::create(array_merge([
'name' => 'test-node',
'type' => Server::TYPE_VMESS,
'host' => '127.0.0.1',
'port' => 443,
'server_port' => 443,
'rate' => '1',
'group_ids' => [1],
'show' => false,
'auto_online' => false,
'enabled' => true,
], $attributes));
}
}