Switch top to fyyd
All checks were successful
repod / nextcloud (push) Successful in 1m5s
repod / nodejs (push) Successful in 1m18s

This commit is contained in:
Michel Roux 2023-07-25 21:44:25 +02:00
parent f91c693115
commit 95bd71e0a4
4 changed files with 39 additions and 32 deletions

View File

@ -13,6 +13,6 @@ declare(strict_types=1);
return [ return [
'routes' => [ 'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'top#index', 'url' => '/top/{limit}', 'verb' => 'GET'] ['name' => 'top#index', 'url' => '/top/{count}', 'verb' => 'GET']
] ]
]; ];

View File

@ -29,22 +29,27 @@ class TopController extends Controller
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
*/ */
public function index(int $limit = 10): JSONResponse { public function index(int $count = 10): JSONResponse {
if (!in_array($limit, [10, 25, 50])) { $userLang = 'en';
return new JSONResponse(['Invalid limit, can be 10, 25 or 50.'], Http::STATUS_BAD_REQUEST);
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 { try {
$lang = $this->l10n->getUserLanguage($this->userSession->getUser()); $podcastClient = $this->clientService->newClient();
$lang = explode('_', $lang); $podcastReponse = $podcastClient->get("https://api.fyyd.de/0.2/feature/podcast/hot?count={$count}&language={$userLang}");
$lang = count($lang) > 1 ? $lang[1] : $lang[0]; $podcastJson = (array) json_decode((string) $podcastReponse->getBody(), true, flags: JSON_THROW_ON_ERROR);
$lang = $lang === 'en' ? 'us' : $lang; return new JSONResponse($podcastJson, $podcastReponse->getStatusCode());
$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());
} catch (Exception $e) { } catch (Exception $e) {
return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR); return new JSONResponse([$e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
} }

View File

@ -2,24 +2,26 @@
<fragment> <fragment>
<p class="more"> <p class="more">
<span>{{ t('Discover') }}</span> <span>{{ t('Discover') }}</span>
<NcButton v-if="showMore" @click="more"> <NcSelect v-model="count"
{{ t('More') }} class="select"
</NcButton> :components="{Deselect: {}}"
:options="[...Array(10).keys()].map(x=>(x+1)*10)"
@input="fetch" />
</p> </p>
<p> <p>
<NcLoadingIcon v-if="loading" /> <NcLoadingIcon v-if="loading" />
<ul v-if="!loading" class="tops"> <ul v-if="!loading" class="tops">
<li v-for="top in tops.feed.results" :key="top.id"> <li v-for="top in tops" :key="top.id">
<img :src="top.artworkUrl100" :alt="top.artistName" :title="top.artistName"> <img :src="top.imgURL" :alt="top.author" :title="top.author">
</li> </li>
</ul> </ul>
<span class="caption">{{ t('Suggests by iTunes') }}</span> <span class="caption">{{ t('Suggests by fyyd') }}</span>
</p> </p>
</fragment> </fragment>
</template> </template>
<script> <script>
import { NcButton, NcLoadingIcon } from '@nextcloud/vue' import { NcLoadingIcon, NcSelect } from '@nextcloud/vue'
import axios from '@nextcloud/axios' import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs' import { showError } from '@nextcloud/dialogs'
@ -27,30 +29,26 @@ import { showError } from '@nextcloud/dialogs'
export default { export default {
name: 'Top', name: 'Top',
components: { components: {
NcButton,
NcLoadingIcon, NcLoadingIcon,
NcSelect,
}, },
data() { data() {
return { return {
tops: [], tops: [],
loading: true, loading: true,
showMore: true, count: 10,
} }
}, },
async mounted() { async mounted() {
await this.fetch(10) await this.fetch()
}, },
methods: { methods: {
async more() { async fetch() {
this.showMore = false
await this.fetch(50)
},
async fetch(limit) {
this.loading = true this.loading = true
try { try {
const top = await axios.get(generateUrl('/apps/repod/top/{limit}', { limit })) const top = await axios.get(generateUrl('/apps/repod/top/{count}', { count: this.count }))
this.tops = top.data this.tops = top.data.data
} catch (e) { } catch (e) {
console.error(e) console.error(e)
showError(t('Could not fetch tops')) showError(t('Could not fetch tops'))
@ -79,6 +77,10 @@ export default {
width: 100%; width: 100%;
} }
.select {
min-width: 160px;
}
.more { .more {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;

View File

@ -34,7 +34,7 @@ export default {
<style scoped> <style scoped>
.main { .main {
margin: 11px 55px; margin: 22px 55px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 1rem; gap: 1rem;