mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-17 17:21:04 +00:00
fix: create S3 event classes and add formatBytes helper
- Create S3DownloadFinished event to cleanup MinIO containers - Create S3RestoreJobFinished event to cleanup temp files and S3 downloads - Add formatBytes() helper function for human-readable file sizes - Update Import component to use full Event class names in callEventOnFinish - Fix activity monitor visibility issues with proper event dispatching 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
27
app/Events/S3DownloadFinished.php
Normal file
27
app/Events/S3DownloadFinished.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Server;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class S3DownloadFinished
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$containerName = data_get($data, 'containerName');
|
||||
$serverId = data_get($data, 'serverId');
|
||||
|
||||
if (filled($containerName) && filled($serverId)) {
|
||||
// Clean up the MinIO client container
|
||||
$commands = [];
|
||||
$commands[] = "docker stop {$containerName} 2>/dev/null || true";
|
||||
$commands[] = "docker rm {$containerName} 2>/dev/null || true";
|
||||
instant_remote_process($commands, Server::find($serverId), throwError: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
49
app/Events/S3RestoreJobFinished.php
Normal file
49
app/Events/S3RestoreJobFinished.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Server;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class S3RestoreJobFinished
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$scriptPath = data_get($data, 'scriptPath');
|
||||
$tmpPath = data_get($data, 'tmpPath');
|
||||
$container = data_get($data, 'container');
|
||||
$serverId = data_get($data, 'serverId');
|
||||
$s3DownloadedFile = data_get($data, 's3DownloadedFile');
|
||||
|
||||
// Clean up temporary files from container
|
||||
if (filled($scriptPath) && filled($tmpPath) && filled($container) && filled($serverId)) {
|
||||
if (str($tmpPath)->startsWith('/tmp/')
|
||||
&& str($scriptPath)->startsWith('/tmp/')
|
||||
&& ! str($tmpPath)->contains('..')
|
||||
&& ! str($scriptPath)->contains('..')
|
||||
&& strlen($tmpPath) > 5 // longer than just "/tmp/"
|
||||
&& strlen($scriptPath) > 5
|
||||
) {
|
||||
$commands[] = "docker exec {$container} sh -c 'rm {$scriptPath}'";
|
||||
$commands[] = "docker exec {$container} sh -c 'rm {$tmpPath}'";
|
||||
instant_remote_process($commands, Server::find($serverId), throwError: true);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up S3 downloaded file from server
|
||||
if (filled($s3DownloadedFile) && filled($serverId)) {
|
||||
if (str($s3DownloadedFile)->startsWith('/tmp/s3-restore-')
|
||||
&& ! str($s3DownloadedFile)->contains('..')
|
||||
&& strlen($s3DownloadedFile) > 16 // longer than just "/tmp/s3-restore-"
|
||||
) {
|
||||
$commands = [];
|
||||
$commands[] = "rm -f {$s3DownloadedFile}";
|
||||
instant_remote_process($commands, Server::find($serverId), throwError: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user