49 lines
1.8 KiB
PHP
49 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\OgBoot\OgLive;
|
|
|
|
use App\Controller\OgBoot\AbstractOgBootController;
|
|
use App\Entity\OgLive;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
|
|
#[AsController]
|
|
class GetIsosAction extends AbstractOgBootController
|
|
{
|
|
/**
|
|
* @throws TransportExceptionInterface
|
|
* @throws ServerExceptionInterface
|
|
* @throws RedirectionExceptionInterface
|
|
* @throws ClientExceptionInterface
|
|
*/
|
|
public function __invoke(): JsonResponse
|
|
{
|
|
$content = $this->createRequest('GET', 'http://'.$this->ogBootApiUrl.'/ogboot/v1/oglives/isos');
|
|
|
|
if (!isset($content['message']) || !is_array($content['message'])) {
|
|
return new JsonResponse(data: ['error' => 'Invalid response'], status: Response::HTTP_BAD_REQUEST);
|
|
}
|
|
|
|
$isos = array_map(function ($iso) {
|
|
$filename = $this->simplifyOgLiveFilenameService->__invoke($iso['filename']);
|
|
|
|
return [
|
|
'id' => $iso['id'],
|
|
'filename' => $filename,
|
|
'url' => $iso['url'],
|
|
'installed' => $iso['installed'],
|
|
'compatible' => $iso['compatible'],
|
|
];
|
|
}, $content['message']);
|
|
|
|
usort($isos, fn($a, $b) => $b['id'] <=> $a['id']);
|
|
|
|
return new JsonResponse(data: ['success' => 'ISOs retrieved successfully', 'message' => $isos], status: Response::HTTP_OK);
|
|
}
|
|
}
|