Add cloud so far

This commit is contained in:
Lance Pioch 2025-06-01 17:14:30 -04:00
parent 8ae3c88c91
commit 3212ad21ab
9 changed files with 136 additions and 14 deletions

View File

@ -3,19 +3,26 @@
namespace App\Filament\Admin\Resources\NodeResource\Pages;
use App\Filament\Admin\Resources\NodeResource;
use App\Models\ApiKey;
use App\Models\Node;
use App\Services\Acl\Api\AdminAcl;
use App\Services\Api\KeyCreationService;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\TagsInput;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\ToggleButtons;
use Filament\Forms\Components\View;
use Filament\Forms\Components\Wizard;
use Filament\Forms\Components\Wizard\Step;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\HtmlString;
class CreateNode extends CreateRecord
@ -24,11 +31,83 @@ class CreateNode extends CreateRecord
protected static bool $canCreateAnother = false;
private KeyCreationService $keyCreationService;
public function boot(KeyCreationService $keyCreationService): void
{
$this->keyCreationService = $keyCreationService;
}
public function local(): void
{
$wizard = null;
foreach ($this->form->getComponents() as $component) {
if ($component instanceof Wizard) {
$wizard = $component;
}
}
$wizard->dispatchEvent('wizard::nextStep', $wizard->getStatePath(), 0);
}
public function cloud(): void
{
$key = ApiKey::query()
->where('key_type', ApiKey::TYPE_APPLICATION)
->whereJsonContains('permissions->' . Node::RESOURCE_NAME, AdminAcl::READ|AdminAcl::WRITE)
->first();
if (!$key) {
$key = $this->keyCreationService->setKeyType(ApiKey::TYPE_APPLICATION)->handle([
'memo' => 'Automatically generated node cloud key.',
'user_id' => auth()->user()->id,
'permissions' => [Node::RESOURCE_NAME => AdminAcl::READ|AdminAcl::WRITE],
]);
}
$vars = [
'url' => Request::root(),
'token' => $key->identifier . $key->token,
];
$domain = config('PELICAN_CLOUD_DOMAIN', 'https://hub.pelican.dev');
$response = Http::post("$domain/api/cloud/start", $vars);
if ($response->json('error')) {
$code = $response->json('code');
Notification::make()
->danger()
->persistent()
->title('Pelican Cloud Error')->body(new HtmlString("
It looks like there was a problem communicating with Pelican Cloud!
Please make a ticket by <a class='underline text-blue-400' href='https://hub.pelican.dev/tickets?code=$code'>clicking here</a>.
"))
->send()
;
return;
}
$uuid = $response->json('uuid');
$this->redirect("$domain/cloud/$uuid");
}
public function form(Forms\Form $form): Forms\Form
{
return $form
->schema([
Wizard::make([
Step::make('select')
->label(trans('admin/node.tabs.select_type'))
->icon('tabler-cloud')
->columns(2)
->schema([
View::make('filament.admin.nodes.config.left'),
View::make('filament.admin.nodes.config.right'),
])
,
Step::make('basic')
->label(trans('admin/node.tabs.basic_settings'))
->icon('tabler-server')
@ -374,16 +453,25 @@ class CreateNode extends CreateRecord
->required(),
]),
]),
])->columnSpanFull()
->nextAction(fn (Action $action) => $action->label(trans('admin/node.next_step')))
->submitAction(new HtmlString(Blade::render(<<<'BLADE'
<x-filament::button
type="submit"
size="sm"
>
Create Node
</x-filament::button>
BLADE))),
])
->columnSpanFull()
->nextAction(function (Action $action, Wizard $wizard) {
if ($wizard->getCurrentStepIndex() === 0) {
return $action->label(trans('admin/node.next_step'))->view('filament.admin.nodes.config.empty');
}
return $action->label(trans('admin/node.next_step'));
})
->submitAction(new HtmlString(Blade::render(
<<<'BLADE'
<x-filament::button
type="submit"
size="sm"
>
Create Node
</x-filament::button>
BLADE
))),
]);
}

View File

@ -55,19 +55,19 @@ class ListServers extends ListRecords
$viewThree = [
TextColumn::make('cpuUsage')
->label('')
->label('CPU')
->icon('tabler-cpu')
->tooltip(fn (Server $server) => 'Usage Limit: ' . $server->formatResource('cpu', limit: true, type: ServerResourceType::Percentage, precision: 0))
->state(fn (Server $server) => $server->formatResource('cpu_absolute', type: ServerResourceType::Percentage))
->color(fn (Server $server) => $this->getResourceColor($server, 'cpu')),
TextColumn::make('memoryUsage')
->label('')
->label('Memory')
->icon('tabler-memory')
->tooltip(fn (Server $server) => 'Usage Limit: ' . $server->formatResource('memory', limit: true))
->state(fn (Server $server) => $server->formatResource('memory_bytes'))
->color(fn (Server $server) => $this->getResourceColor($server, 'memory')),
TextColumn::make('diskUsage')
->label('')
->label('Disk')
->icon('tabler-device-floppy')
->tooltip(fn (Server $server) => 'Usage Limit: ' . $server->formatResource('disk', limit: true))
->state(fn (Server $server) => $server->formatResource('disk_bytes'))

View File

@ -18,7 +18,8 @@ class DaemonConfigurationRepository extends DaemonRepository
public function getSystemInformation(): array
{
return $this->getHttpClient()
->connectTimeout(3)
->connectTimeout(1)
->timeout(1)
->get('/api/system')
->throwIf(function ($result) {
$header = $result->header('User-Agent');

View File

@ -9,6 +9,7 @@ return [
'basic_settings' => 'Basic Settings',
'advanced_settings' => 'Advanced Settings',
'config_file' => 'Configuration File',
'select_type' => 'Node Type',
],
'table' => [
'health' => 'Health',

BIN
public/images/cloud.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
public/images/local.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

@ -0,0 +1,16 @@
<div class="text-center mb-2">
<x-filament::button
icon="tabler-cloud"
wire:click="cloud"
class="text-center"
size="xl"
color="info"
>
Pelican Cloud
</x-filament::button>
</div>
<div class="text-center block">
<p class="mb-2">Very easily and quickly set up a powerful game server on our cloud!</p>
<img src="/images/cloud.png" class="w-1/2 mx-auto" alt="pelican cloud" />
</div>

View File

@ -0,0 +1,16 @@
<div class="text-center mb-2">
<x-filament::button
icon="tabler-server"
wire:click="local"
class="text-center"
size="xl"
color="primary"
>
Self Host
</x-filament::button>
</div>
<div class="text-center block">
<p class="mb-2">Use your own hardware either in your home or somewhere else.</p>
<img src="/images/local.png" class="w-1/2 mx-auto" alt="pelican cloud" />
</div>