diff --git a/appinfo/routes.php b/appinfo/routes.php index 16dc3fb..7e46e20 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -13,6 +13,6 @@ declare(strict_types=1); return [ 'routes' => [ ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], - ['name' => 'top#index', 'url' => '/top/{limit}', 'verb' => 'GET'] + ['name' => 'top#index', 'url' => '/top/{count}', 'verb' => 'GET'] ] ]; diff --git a/lib/Controller/TopController.php b/lib/Controller/TopController.php index a98229e..7dc9594 100644 --- a/lib/Controller/TopController.php +++ b/lib/Controller/TopController.php @@ -29,22 +29,27 @@ class TopController extends Controller * @NoAdminRequired * @NoCSRFRequired */ - public function index(int $limit = 10): JSONResponse { - if (!in_array($limit, [10, 25, 50])) { - return new JSONResponse(['Invalid limit, can be 10, 25 or 50.'], Http::STATUS_BAD_REQUEST); + public function index(int $count = 10): JSONResponse { + $userLang = 'en'; + + try { + $langClient = $this->clientService->newClient(); + $langResponse = $langClient->get("https://api.fyyd.de/0.2/feature/podcast/hot/languages"); + $langJson = (array) json_decode((string) $langResponse->getBody(), true, flags: JSON_THROW_ON_ERROR); + if (array_key_exists('data', $langJson) && is_array($langJson['data'])) { + $userLang = $this->l10n->getUserLanguage($this->userSession->getUser()); + $userLang = explode('_', $userLang); + $userLang = count($userLang) > 1 ? $userLang[1] : $userLang[0]; + $userLang = in_array($userLang, $langJson['data']) ? $userLang : 'en'; + } + } catch (Exception $e) { } try { - $lang = $this->l10n->getUserLanguage($this->userSession->getUser()); - $lang = explode('_', $lang); - $lang = count($lang) > 1 ? $lang[1] : $lang[0]; - $lang = $lang === 'en' ? 'us' : $lang; - - $client = $this->clientService->newClient(); - $response = $client->get("https://rss.applemarketingtools.com/api/v2/{$lang}/podcasts/top/{$limit}/podcasts.json"); - /** @var array $json */ - $json = json_decode((string) $response->getBody(), true, flags: JSON_THROW_ON_ERROR); - return new JSONResponse($json, $response->getStatusCode()); + $podcastClient = $this->clientService->newClient(); + $podcastReponse = $podcastClient->get("https://api.fyyd.de/0.2/feature/podcast/hot?count={$count}&language={$userLang}"); + $podcastJson = (array) json_decode((string) $podcastReponse->getBody(), true, flags: JSON_THROW_ON_ERROR); + return new JSONResponse($podcastJson, $podcastReponse->getStatusCode()); } catch (Exception $e) { return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); } diff --git a/src/components/Top.vue b/src/components/Top.vue index 20a8c2c..b8fd63b 100644 --- a/src/components/Top.vue +++ b/src/components/Top.vue @@ -2,24 +2,26 @@

{{ t('Discover') }} - - {{ t('More') }} - +

- {{ t('Suggests by iTunes') }} + {{ t('Suggests by fyyd') }}