Merge branch 'next' into feat/disable-default-redirect

This commit is contained in:
🏔️ Peak
2024-12-05 14:46:33 +01:00
committed by GitHub
190 changed files with 2581 additions and 952 deletions

View File

@@ -11,6 +11,7 @@ use App\Notifications\Server\Reachable;
use App\Notifications\Server\Unreachable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
@@ -42,14 +43,13 @@ use Symfony\Component\Yaml\Yaml;
'validation_logs' => ['type' => 'string', 'description' => 'The validation logs.'],
'log_drain_notification_sent' => ['type' => 'boolean', 'description' => 'The flag to indicate if the log drain notification has been sent.'],
'swarm_cluster' => ['type' => 'string', 'description' => 'The swarm cluster configuration.'],
'delete_unused_volumes' => ['type' => 'boolean', 'description' => 'The flag to indicate if the unused volumes should be deleted.'],
'delete_unused_networks' => ['type' => 'boolean', 'description' => 'The flag to indicate if the unused networks should be deleted.'],
'settings' => ['$ref' => '#/components/schemas/ServerSetting'],
]
)]
class Server extends BaseModel
{
use SchemalessAttributesTrait, SoftDeletes;
use HasFactory, SchemalessAttributesTrait, SoftDeletes;
public static $batch_counter = 0;
@@ -606,7 +606,8 @@ $schema://$host {
}
$memory = json_decode($memory, true);
$parsedCollection = collect($memory)->map(function ($metric) {
return [(int) $metric['time'], (float) $metric['usedPercent']];
$usedPercent = $metric['usedPercent'] ?? 0.0;
return [(int) $metric['time'], (float) $usedPercent];
});
return $parsedCollection->toArray();
@@ -809,7 +810,7 @@ $schema://$host {
{
return Attribute::make(
get: function ($value) {
return preg_replace('/[^0-9]/', '', $value);
return (int) preg_replace('/[^0-9]/', '', $value);
}
);
}
@@ -983,7 +984,7 @@ $schema://$host {
public function status(): bool
{
['uptime' => $uptime] = $this->validateConnection(false);
['uptime' => $uptime] = $this->validateConnection();
if ($uptime === false) {
foreach ($this->applications() as $application) {
$application->status = 'exited';
@@ -1035,7 +1036,7 @@ $schema://$host {
$this->unreachable_notification_sent = false;
$this->save();
$this->refresh();
$this->team->notify(new Reachable($this));
// $this->team->notify(new Reachable($this));
}
public function sendUnreachableNotification()
@@ -1043,21 +1044,17 @@ $schema://$host {
$this->unreachable_notification_sent = true;
$this->save();
$this->refresh();
$this->team->notify(new Unreachable($this));
// $this->team->notify(new Unreachable($this));
}
public function validateConnection(bool $isManualCheck = true, bool $justCheckingNewKey = false)
public function validateConnection(bool $justCheckingNewKey = false)
{
config()->set('constants.ssh.mux_enabled', ! $isManualCheck);
config()->set('constants.ssh.mux_enabled', false);
if ($this->skipServer()) {
return ['uptime' => false, 'error' => 'Server skipped.'];
}
try {
// Make sure the private key is stored
if ($this->privateKey) {
$this->privateKey->storeInFileSystem();
}
instant_remote_process(['ls /'], $this);
if ($this->settings->is_reachable === false) {
$this->settings->is_reachable = true;