The s3DownloadedFile was being set immediately when download started, causing the "Restore" button to appear while still downloading and the download message to not hide properly. - Remove immediate setting of s3DownloadedFile in downloadFromS3() - Set s3DownloadedFile only in handleS3DownloadFinished() event handler - Add broadcastWith() to S3DownloadFinished to send downloadPath - Store downloadPath as public property for broadcasting - Now download message hides and restore button shows only when complete 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Events;
|
|
|
|
use App\Models\Server;
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class S3DownloadFinished implements ShouldBroadcast
|
|
{
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
public int|string|null $userId = null;
|
|
|
|
public ?string $downloadPath = null;
|
|
|
|
public function __construct($teamId, $data = null)
|
|
{
|
|
if (is_null($data)) {
|
|
return;
|
|
}
|
|
|
|
// Get userId from event data (the user who triggered the download)
|
|
$this->userId = data_get($data, 'userId');
|
|
$this->downloadPath = data_get($data, 'downloadPath');
|
|
|
|
$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);
|
|
}
|
|
}
|
|
|
|
public function broadcastOn(): ?array
|
|
{
|
|
if (is_null($this->userId)) {
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
new PrivateChannel("user.{$this->userId}"),
|
|
];
|
|
}
|
|
|
|
public function broadcastWith(): array
|
|
{
|
|
return [
|
|
'downloadPath' => $this->downloadPath,
|
|
];
|
|
}
|
|
}
|