mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 23:12:35 +00:00
Setup Inertia (#593)
This commit is contained in:
@ -1,12 +1,9 @@
|
||||
<?php
|
||||
|
||||
use App\Exceptions\SSHError;
|
||||
use Filament\Notifications\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
function generate_public_key(string $privateKeyPath, string $publicKeyPath): void
|
||||
{
|
||||
@ -57,6 +54,10 @@ function convert_time_format(string $string): string
|
||||
|
||||
function get_public_key_content(): string
|
||||
{
|
||||
if (cache()->has('ssh_public_key_content')) {
|
||||
return cache()->get('ssh_public_key_content');
|
||||
}
|
||||
|
||||
if (! file_exists(storage_path(config('core.ssh_public_key_name')))) {
|
||||
Artisan::call('ssh-key:generate --force');
|
||||
}
|
||||
@ -67,46 +68,13 @@ function get_public_key_content(): string
|
||||
return '';
|
||||
}
|
||||
|
||||
return str($content)
|
||||
$content = str($content)
|
||||
->replace("\n", '')
|
||||
->toString();
|
||||
}
|
||||
|
||||
function run_action(object $static, Closure $callback): void
|
||||
{
|
||||
try {
|
||||
$callback();
|
||||
} catch (SSHError $e) {
|
||||
$actions = [];
|
||||
if ($e->getLog() instanceof \App\Models\ServerLog) {
|
||||
$actions[] = Action::make('View Logs')
|
||||
->url(App\Web\Pages\Servers\Logs\Index::getUrl([
|
||||
'server' => $e->getLog()->server_id,
|
||||
]))
|
||||
->openUrlInNewTab();
|
||||
}
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title($e->getMessage())
|
||||
->body($e->getLog()?->getContent(30))
|
||||
->actions($actions)
|
||||
->send();
|
||||
cache()->put('ssh_public_key_content', $content, 60 * 60 * 24);
|
||||
|
||||
if (method_exists($static, 'halt')) {
|
||||
$reflectionMethod = new ReflectionMethod($static, 'halt');
|
||||
$reflectionMethod->invoke($static);
|
||||
}
|
||||
} catch (ValidationException $e) {
|
||||
Notification::make()
|
||||
->danger()
|
||||
->title($e->getMessage())
|
||||
->send();
|
||||
|
||||
if (method_exists($static, 'halt')) {
|
||||
$reflectionMethod = new ReflectionMethod($static, 'halt');
|
||||
$reflectionMethod->invoke($static);
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,3 +219,11 @@ function format_nginx_config(string $config): string
|
||||
|
||||
return implode("\n", $formattedLines)."\n";
|
||||
}
|
||||
|
||||
function user(): User
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
Reference in New Issue
Block a user