Signed-off-by: Simon L. <szaimen@e.mail.de>
This commit is contained in:
Simon L.
2026-02-27 14:55:16 +01:00
parent 4f7ccdedb5
commit 04c08b586f
2 changed files with 20 additions and 5 deletions

View File

@@ -286,8 +286,12 @@ readonly class DockerController {
}
public function SystemPrune(Request $request, Response $response, array $args) : Response {
$this->dockerActionManager->SystemPrune();
return $response->withStatus(201)->withHeader('Location', '.');
$results = $this->dockerActionManager->SystemPrune();
$body = $response->getBody();
$body->write(json_encode($results));
return $response
->withStatus(200)
->withHeader('Content-Type', 'application/json; charset=utf-8');
}
public function stopTopContainer() : void {

View File

@@ -984,7 +984,7 @@ readonly class DockerActionManager {
}
}
public function SystemPrune(): void {
public function SystemPrune(): array {
$endpoints = [
// Remove stopped containers
'containers/prune',
@@ -998,6 +998,7 @@ readonly class DockerActionManager {
'build/prune',
];
$results = [];
foreach ($endpoints as $endpoint) {
// Special-case images prune to include the dangling filter as requested
if ($endpoint === 'images/prune') {
@@ -1008,11 +1009,21 @@ readonly class DockerActionManager {
}
try {
$this->guzzleClient->post($url);
$resp = $this->guzzleClient->post($url);
$body = (string)$resp->getBody();
$json = null;
try {
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
} catch (\Throwable $e) {
// Non-JSON body, keep raw
$json = $body;
}
$results[$endpoint] = $json;
} catch (RequestException $e) {
error_log(sprintf('Docker prune (%s) failed: %s', $endpoint, $e->getMessage()));
$results[$endpoint] = ['error' => $e->getMessage()];
// continue with next prune step
}
}
return $results;
}
}