diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index dc3a292e..51d2a950 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -202,23 +202,9 @@ readonly class DockerController { error_log('WARNING: Not pulling container images. Instead, using local ones.'); } - $nonbufResp = $response - ->withBody(new NonBufferedBody()) - ->withHeader('Content-Type', 'text/html; charset=utf-8') - ->withHeader('X-Accel-Buffering', 'no') - ->withHeader('Cache-Control', 'no-cache'); - - // Text written into this body is immediately sent to the client, without waiting for later content. - $streamingResponseBody = $nonbufResp->getBody(); - - $streamingResponseBody->write($this->getStreamingResponseHtmlStart()); - - // Create a closure to pass around to the code, which should to the logging (because it e.g. decides - // if it'll actually pull an image), but which should not need to know anything about the - // wanted markup or formatting. - $addToStreamingResponseBody = function (Container $container, string $message) use ($streamingResponseBody) : void { - $streamingResponseBody->write("
{$container->displayName}: {$message}
"); - }; + // Get streaming response start and closure + $nonbufResp = $this->startStreamingResponse($response); + $addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp); // Start container $this->startTopContainer($pullImage, $addToStreamingResponseBody); @@ -227,7 +213,8 @@ readonly class DockerController { // Temporarily disabled as it leads much faster to docker rate limits // apcu_clear_cache(); - $streamingResponseBody->write($this->getStreamingResponseHtmlEnd()); + // End streaming response + $this->finalizeStreamingResponse($nonbufResp); return $nonbufResp; } @@ -243,14 +230,21 @@ readonly class DockerController { } public function StartWatchtowerContainer(Request $request, Response $response, array $args) : Response { - $this->startWatchtower(); - return $response->withStatus(201)->withHeader('Location', '.'); + // Get streaming response start and closure + $nonbufResp = $this->startStreamingResponse($response); + $addToStreamingResponseBody = $this->getAddToStreamingResponseBody($nonbufResp); + + $this->startWatchtower($addToStreamingResponseBody); + + // End streaming response + $this->finalizeStreamingResponse($nonbufResp); + return $nonbufResp; } - public function startWatchtower() : void { + public function startWatchtower(?\Closure $addToStreamingResponseBody = null) : void { $id = 'nextcloud-aio-watchtower'; - $this->PerformRecursiveContainerStart($id); + $this->PerformRecursiveContainerStart($id, true, $addToStreamingResponseBody); } private function PerformRecursiveContainerStop(string $id, bool $forceStopNextcloud = false) : void @@ -354,7 +348,37 @@ readonly class DockerController { END; } - + + private function startStreamingResponse(Response $response) : Response { + $nonbufResp = $response + ->withBody(new NonBufferedBody()) + ->withHeader('Content-Type', 'text/html; charset=utf-8') + ->withHeader('X-Accel-Buffering', 'no') + ->withHeader('Cache-Control', 'no-cache'); + + // Text written into this body is immediately sent to the client, without waiting for later content. + $streamingResponseBody = $nonbufResp->getBody(); + + $streamingResponseBody->write($this->getStreamingResponseHtmlStart()); + + return $nonbufResp; + } + + private function getAddToStreamingResponseBody(Response $nonbufResp) : ?\Closure { + // Create a closure to pass around to the code, which should to the logging (because it e.g. decides + // if it'll actually pull an image), but which should not need to know anything about the + // wanted markup or formatting. + $addToStreamingResponseBody = function (Container $container, string $message) use ($nonbufResp) : void { + $nonbufResp->getBody()->write("
{$container->displayName}: {$message}
"); + }; + + return $addToStreamingResponseBody; + } + + private function finalizeStreamingResponse(Response $nonbufResp) : void { + $nonbufResp->getBody()->write($this->getStreamingResponseHtmlEnd()); + } + private function getStreamingResponseHtmlEnd() : string { return "\n \n"; } diff --git a/php/templates/containers.twig b/php/templates/containers.twig index ebe2552f..b92e9f10 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -90,7 +90,7 @@ {% elseif is_mastercontainer_update_available == true %}

Mastercontainer update

⚠️ A mastercontainer update is available. Please click on the button below to update it. Afterwards, you will be able to proceed with the setup.

-
+ @@ -332,7 +332,7 @@ {% endif %} {% if is_mastercontainer_update_available == true %}

⚠️ A mastercontainer update is available. Please click on the button below to update it.

- +