id(), 404); Gate::authorize('canAccessTerminal'); $resource = $download['resource_type']::findOrFail($download['resource_id']); Gate::authorize('view', $resource); abort_unless((int) $resource->environment->project->team_id === (int) auth()->user()->currentTeam()->id, 403); $filesystem = new ContainerFilesystemService(Server::findOrFail($download['server_id']), $download['container'], $download['use_helper'] ?? false); return response()->streamDownload(function () use ($filesystem, $download) { set_time_limit(0); $filesystem->streamDownload($download['path'], $download['is_dir'], function (string $chunk) { echo $chunk; if (ob_get_level() > 0) { ob_flush(); } flush(); }); }, $download['name'], [ 'Content-Type' => 'application/octet-stream', // Stop nginx from buffering the response to a temp file on the Coolify host. 'X-Accel-Buffering' => 'no', ]); } }