repod/lib/Controller/SearchController.php
Michel Roux 431cbf0c42
All checks were successful
repod / nextcloud (push) Successful in 59s
repod / nodejs (push) Successful in 1m13s
debounce search OK
2023-07-26 01:26:46 +02:00

56 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\RePod\Controller;
use Exception;
use OCA\RePod\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Http\Client\IClientService;
use OCP\IRequest;
class SearchController extends Controller
{
public function __construct(
IRequest $request,
private IClientService $clientService
) {
parent::__construct(Application::APP_ID, $request);
}
public function index(string $value): JSONResponse {
$podcasts = [];
try {
$fyydClient = $this->clientService->newClient();
$fyydReponse = $fyydClient->get("https://api.fyyd.de/0.2/search/podcast", [
'query' => [
'title' => $value,
'term' => $value
]
]);
$fyydJson = (array) json_decode((string) $fyydReponse->getBody(), true, flags: JSON_THROW_ON_ERROR);
if (array_key_exists('data', $fyydJson) && is_array($fyydJson['data'])) {
/** @var string[] $fyydFeed */
foreach ($fyydJson['data'] as $fyydFeed) {
$podcasts[] = [
'id' => $fyydFeed['id'],
'title' => $fyydFeed['title'],
'description' => $fyydFeed['description'],
'image' => $fyydFeed['imgURL'],
'url' => $fyydFeed['xmlURL'],
'lang' => $fyydFeed['language'],
'lastpub' => $fyydFeed['lastpub']
];
}
}
} catch (Exception $e) {
}
return new JSONResponse($podcasts);
}
}