mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-08 12:29:26 +01:00
refactor function
This commit is contained in:
parent
bda39382b4
commit
1271532df8
@ -4,8 +4,7 @@ namespace App\Filament\Admin\Resources\Nodes\Pages;
|
||||
|
||||
use App\Filament\Admin\Resources\Nodes\NodeResource;
|
||||
use App\Models\Node;
|
||||
use App\Repositories\Daemon\DaemonConfigurationRepository;
|
||||
use App\Repositories\Daemon\DaemonRepository;
|
||||
use App\Repositories\Daemon\DaemonSystemRepository;
|
||||
use App\Services\Helpers\SoftwareVersionService;
|
||||
use App\Services\Nodes\NodeAutoDeployService;
|
||||
use App\Services\Nodes\NodeUpdateService;
|
||||
@ -51,17 +50,14 @@ class EditNode extends EditRecord
|
||||
|
||||
protected static string $resource = NodeResource::class;
|
||||
|
||||
private DaemonConfigurationRepository $daemonConfigurationRepository;
|
||||
|
||||
private DaemonRepository $daemonRepository;
|
||||
private DaemonSystemRepository $daemonSystemRepository;
|
||||
|
||||
private NodeUpdateService $nodeUpdateService;
|
||||
|
||||
public function boot(DaemonConfigurationRepository $daemonConfigurationRepository, NodeUpdateService $nodeUpdateService, DaemonRepository $daemonRepository): void
|
||||
public function boot(DaemonSystemRepository $daemonSystemRepository, NodeUpdateService $nodeUpdateService): void
|
||||
{
|
||||
$this->daemonConfigurationRepository = $daemonConfigurationRepository;
|
||||
$this->daemonSystemRepository = $daemonSystemRepository;
|
||||
$this->nodeUpdateService = $nodeUpdateService;
|
||||
$this->daemonRepository = $daemonRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -653,7 +649,7 @@ class EditNode extends EditRecord
|
||||
$logLines = $get('log_lines') ?? 200;
|
||||
|
||||
try {
|
||||
$response = $this->daemonRepository->setNode($node)->getDiagnostics($logLines, $includeEndpoints, $includeLogs);
|
||||
$response = $this->daemonSystemRepository->setNode($node)->getDiagnostics($logLines, $includeEndpoints, $includeLogs);
|
||||
|
||||
$set('pulled', true);
|
||||
$set('log', $response->body());
|
||||
@ -691,7 +687,7 @@ class EditNode extends EditRecord
|
||||
if ($response->failed()) {
|
||||
Notification::make()
|
||||
->title(trans('admin/node.diagnostics.upload_failed'))
|
||||
->body($response->status())
|
||||
->body(fn () => $response->status() . ' - ' . $response->body())
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
@ -752,7 +748,8 @@ class EditNode extends EditRecord
|
||||
->hiddenLabel()
|
||||
->columnSpanFull()
|
||||
->rows(35)
|
||||
->visible(fn (Get $get) => ($get('pulled') ?? false) || ($get('uploaded') ?? false)), ]),
|
||||
->visible(fn (Get $get) => ($get('pulled') ?? false) || ($get('uploaded') ?? false)),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
@ -810,7 +807,7 @@ class EditNode extends EditRecord
|
||||
|
||||
try {
|
||||
if ($changed) {
|
||||
$this->daemonConfigurationRepository->setNode($node)->update($node);
|
||||
$this->daemonSystemRepository->setNode($node)->update($node);
|
||||
}
|
||||
parent::getSavedNotification()?->send();
|
||||
} catch (ConnectionException) {
|
||||
|
||||
@ -4,7 +4,7 @@ namespace App\Models;
|
||||
|
||||
use App\Contracts\Validatable;
|
||||
use App\Exceptions\Service\HasActiveServersException;
|
||||
use App\Repositories\Daemon\DaemonConfigurationRepository;
|
||||
use App\Repositories\Daemon\DaemonSystemRepository;
|
||||
use App\Traits\HasValidation;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
@ -316,7 +316,7 @@ class Node extends Model implements Validatable
|
||||
{
|
||||
return once(function () {
|
||||
try {
|
||||
return (new DaemonConfigurationRepository())
|
||||
return (new DaemonSystemRepository())
|
||||
->setNode($this)
|
||||
->getSystemInformation();
|
||||
} catch (Exception $exception) {
|
||||
|
||||
@ -22,8 +22,6 @@ use App\Models\Server;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use App\Models\UserSSHKey;
|
||||
use App\Repositories\Daemon\DaemonRepository;
|
||||
use App\Repositories\Daemon\HttpDaemonRepository;
|
||||
use App\Services\Helpers\SoftwareVersionService;
|
||||
use Dedoc\Scramble\Scramble;
|
||||
use Dedoc\Scramble\Support\Generator\OpenApi;
|
||||
@ -122,15 +120,4 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
AboutCommand::add('Environment', 'Installation Directory', base_path());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register application service providers.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
Scramble::ignoreDefaultRoutes();
|
||||
|
||||
// Bind the daemon repository abstract to a concrete implementation so it is instantiable.
|
||||
$this->app->bind(DaemonRepository::class, HttpDaemonRepository::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,23 +72,4 @@ abstract class DaemonRepository
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve diagnostics from the daemon for the current node.
|
||||
*
|
||||
*
|
||||
* @throws ConnectionException
|
||||
*/
|
||||
public function getDiagnostics(int $lines, bool $includeEndpoints, bool $includeLogs): Response
|
||||
{
|
||||
Assert::isInstanceOf($this->node, Node::class);
|
||||
|
||||
return $this->getHttpClient()
|
||||
->timeout(5)
|
||||
->get('/api/diagnostics', [
|
||||
'log_lines' => $lines,
|
||||
'include_endpoints' => $includeEndpoints ? 'true' : 'false',
|
||||
'include_logs' => $includeLogs ? 'true' : 'false',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ use App\Models\Node;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\Client\Response;
|
||||
|
||||
class DaemonConfigurationRepository extends DaemonRepository
|
||||
class DaemonSystemRepository extends DaemonRepository
|
||||
{
|
||||
/**
|
||||
* Returns system information from the daemon instance.
|
||||
@ -30,6 +30,23 @@ class DaemonConfigurationRepository extends DaemonRepository
|
||||
})->json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve diagnostics from the daemon for the current node.
|
||||
*
|
||||
*
|
||||
* @throws ConnectionException
|
||||
*/
|
||||
public function getDiagnostics(int $lines, bool $includeEndpoints, bool $includeLogs): Response
|
||||
{
|
||||
return $this->getHttpClient()
|
||||
->timeout(5)
|
||||
->get('/api/diagnostics', [
|
||||
'log_lines' => $lines,
|
||||
'include_endpoints' => $includeEndpoints ? 'true' : 'false',
|
||||
'include_logs' => $includeLogs ? 'true' : 'false',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the configuration information for a daemon. Updates the information for
|
||||
* this instance using a passed-in model. This allows us to change plenty of information
|
||||
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Daemon;
|
||||
|
||||
class HttpDaemonRepository extends DaemonRepository
|
||||
{
|
||||
// Concrete instantiable implementation. Uses DaemonRepository's HTTP helper methods.
|
||||
}
|
||||
@ -4,7 +4,7 @@ namespace App\Services\Nodes;
|
||||
|
||||
use App\Exceptions\Service\Node\ConfigurationNotPersistedException;
|
||||
use App\Models\Node;
|
||||
use App\Repositories\Daemon\DaemonConfigurationRepository;
|
||||
use App\Repositories\Daemon\DaemonSystemRepository;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Support\Str;
|
||||
@ -17,7 +17,7 @@ class NodeUpdateService
|
||||
*/
|
||||
public function __construct(
|
||||
private ConnectionInterface $connection,
|
||||
private DaemonConfigurationRepository $configurationRepository,
|
||||
private DaemonSystemRepository $configurationRepository,
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user